Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Meta: Get building on NixOS #5005

Merged
merged 1 commit into from
Jan 22, 2021
Merged

Conversation

sophiajt
Copy link
Contributor

Managed to get this building on NixOS and figured I'd turn it into a PR so it didn't get lost. The gist is largely to not use /bin/bash or /bin/mkdir, since those aren't available on NixOS and instead use env to find where they are.

The rest of this is setting up the build dependencies so that both the bootstrap and Serenity can build successfully.

@@ -1,4 +1,4 @@
#!/bin/bash ../.port_include.sh
#!/usr/bin/env bash ../.port_include.sh
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it actually work to specify multiple arguments in shebangs?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember running into this when changing Serenity's env. Some env implementations allow that by default and others require a -S flag or something like that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, so the kernel passes everything following the initial binary name as a single argument (in this case, /usr/bin/env "bash ../.port_include.sh"), and the env implementation can then optionally support splitting this as a shell would otherwise do it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I'm not quite following - is there a change you'd like me to do here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might need to add -S as @asynts says

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think using -S breaks support for OpenBSD: https://man.openbsd.org/env.1

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Portability in a nutshell...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So no -S? 😅

Copy link
Member

@emanuele6 emanuele6 Jan 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jonathandturner: I don't think it would work without it.

EDIT:
file

@bugaevc
Copy link
Member

bugaevc commented Jan 21, 2021

Not to sound negative — being able to build Serenity on Guix would be great 😀 —

but the idea that /bin/env is a well-known path but /bin/sh is not one (and so all the sh invocations have to be proxied through env) sounds backwards to me. I'd expect any system that places its shell in an unusual location to provide the necessary symlinks or some other mechanism to make existing software work, rather than requiring everything to proxy binary invocations through env.

But I realize that ship has sailed, and the design of Nix/Guix is not gonna change because of my preferences.

@@ -1,5 +1,8 @@
#!/usr/bin/env bash
<<<<<<< HEAD
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, looks like an unresolved merge conflict snuck in. I also noticed there's a merge commit in your commit list -- we like to follow a rebase + squash workflow so that commits can be directly placed in master from each PR. https://github.com/SerenityOS/serenity/blob/master/CONTRIBUTING.md#code-submission-policy

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

@sophiajt sophiajt force-pushed the nixos_build branch 2 times, most recently from 435cfaa to 56d9795 Compare January 21, 2021 18:46
@@ -390,7 +390,7 @@ add_custom_target(generate_PropertyID.h DEPENDS CSS/PropertyID.h)

add_custom_command(
OUTPUT CSS/PropertyID.cpp
COMMAND /bin/mkdir -p CSS
COMMAND /usr/bin/env -S mkdir -p CSS
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we somehow use cmake to make directories instead of using /usr/bin/env -S mkdir -p ...?

Copy link
Member

@emanuele6 emanuele6 Jan 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
COMMAND /usr/bin/env -S mkdir -p CSS
COMMAND ${CMAKE_COMMAND} -E make_directory CSS

https://stackoverflow.com/a/3702233

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, this didn't need -S since it is not a shebang.

@awesomekling
Copy link
Collaborator

All right, let's get this merged since it seems fine, although I have a strong feeling that NixOS build support will bitrot unless somebody uses it regularly.

@awesomekling awesomekling changed the title Platforms: Get building on NixOS Meta: Get building on NixOS Jan 22, 2021
@awesomekling awesomekling merged commit 0bf5669 into SerenityOS:master Jan 22, 2021
@linusg
Copy link
Member

linusg commented Jan 22, 2021

Why do some shebangs say #!/usr/bin/env bash and some say #!/usr/bin/env -S bash now?

@emanuele6
Copy link
Member

@linusg: because of how arguments are passed to programs with shebangs:
file

With #!/usr/bin/env bash, env will get bash and the filename as arguments which is fine.
With #!/usr/bin/env bash ../.port_include.sh, env will get bash ../.port_include.sh and the filename as arguments which is not fine because we don't want to run the file with a program called bash ../.port_include.sh which probably doesn't exist, we want to run it with bash.
To solve this issue, some implementations of env have added an -S (--split-string) "option" which tells env that if it gets an argument that looks like -S something somethingelse it should treat it as two (or more, splitting spaces) seperate arguments: something and somethingelse.
Sadly, since env wasn't meant to be used in shebangs originally, this option is not defined in POSIX.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants