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

Add usrBinEnv setup hook for running scripts with #!/usr/bin/env shebang during build without patching them #319420

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -1448,6 +1448,12 @@ with pkgs;
#package writers
writers = callPackage ../build-support/writers { };

# Useful for creating /usr/bin/env in a build environment to run build scripts with #!/usr/bin/env shebang
usrBinEnv = makeSetupHook { name = "create-usr-bin-env"; } (pkgs.writeText "create-usr-bin-env.sh" ''
mkdir -m 0755 -p /usr/bin
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm getting

mkdir: cannot create directory '/usr': Permission denied

and ls -la / && id from that hook looks like so

total 0
drwxr-x---   1 nobody nixbld   48 Dec  7 13:51 .
drwxr-x---   1 nobody nixbld   48 Dec  7 13:51 ..
drwxr-xr-x   1 nobody nogroup   4 Dec  7 13:51 bin
drwx------   1 nixbld nixbld    0 Dec  7 13:51 build
drwxr-xr-x   1 nobody nogroup 120 Dec  7 13:51 dev
dr-xr-xr-x   1 nobody nogroup  32 Dec  7 13:51 etc
drwxr-xr-x   1 nobody nogroup  10 Dec  7 13:51 nix
dr-xr-xr-x 418 nobody nogroup   0 Dec  7 13:51 proc
drwxrwxrwt   1 nobody nogroup   0 Dec  7 13:51 tmp

uid=1000(nixbld) gid=100(nixbld) groups=100(nixbld)

ln -sfn "${pkgs.coreutils}/bin/env" /usr/bin/env
'');

# lib functions depending on pkgs
inherit (import ../pkgs-lib {
# The `lib` variable in this scope doesn't include any applied lib overlays,
Expand Down