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

gzip: Don't depend on gzip being in $PATH #81227

Merged
merged 1 commit into from Apr 21, 2020
Merged

Conversation

chkno
Copy link
Member

@chkno chkno commented Feb 28, 2020

Motivation for this change

Direct references to gunzip & zcat ought to work in minimal environments like systemd scripts without having to ensure than gzip is added to PATH.

(This only addresses gzip's executables referencing each other -- it does not fix zgrep expecting grep to be in PATH or zdiff expecting diff to be in PATH. I think fixing those would need to be done with care to avoid introducing circular dependencies, since gzip is used to extract sources when grep's source is fetched.)

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option sandbox in nix.conf on non-NixOS linux)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Determined the impact on package closure size (by running nix path-info -S before and after)
  • Ensured that relevant documentation is up to date
  • Fits CONTRIBUTING.md.

mv "$f.new" "$f"
chmod +x "$f"
fi
done
Copy link
Member

Choose a reason for hiding this comment

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

Any reason not to use wrapProgram?

Copy link
Member Author

@chkno chkno Feb 28, 2020

Choose a reason for hiding this comment

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

I was trying to minimise dependencies, since gzip seems like the sort of thing that other low-level stuff would want to depend upon. Bash is already in use here, and this can be done in pure bash, so I did it in pure bash.

At your suggestion I tried it with wrapProgram here, and it didn't immediately blow up, so maybe that's fine?

I don't know which is more valuable here: minimal dependencies or the simpler build script.

Copy link
Member

Choose a reason for hiding this comment

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

What dependencies does wrapProgram bring in? From what I can see it's just a shell?

Copy link
Member Author

Choose a reason for hiding this comment

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

$ nix-store -q --references "$(nix-instantiate --expr 'with import <nixpkgs> {}; makeWrapper')"
/nix/store/0s9...-make-wrapper.sh
/nix/store/9kr...-default-builder.sh
/nix/store/hla...-bash-4.4-p23.drv
/nix/store/jxg...-stdenv-linux.drv
/nix/store/l64...-hook.drv

But then stdenv-linux depends upon gzip:

$ nix-store -q --requisites "$(nix-instantiate --expr 'with import <nixpkgs> {}; makeWrapper')" | grep gzip
/nix/store/310...-gzip-1.10.tar.xz.drv
/nix/store/lqm...-gzip-1.10.drv

Copy link
Member

Choose a reason for hiding this comment

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

Argh, well, I say keep this as-is then

Copy link
Contributor

@gnprice gnprice Apr 5, 2020

Choose a reason for hiding this comment

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

I think the set of dependencies that is always OK to use even in build scripts for low-level tools is the ones in bootstrap-tools. After all, everything requires tools to build, and Bash is no exception. 🙂

Those tools include, notably, GNU sed and the GNU coreutils:

$ ls $(nix-build -A stdenv.bootstrapTools)/bin
'['         cksum       env      install   nohup      rmdir    test
 ar         cmp         expand   join      nproc      sdiff    timeout
 as         comm        expr     kill      numfmt     sed      touch
 awk        coreutils   false    ld        objdump    seq      tr
 b2sum      cp          fgrep    link      od         sh       true
 base32     cpp         find     ln        paste      sleep    truncate
 base64     csplit      fmt      logname   patch      sort     tsort
 basename   cut         fold     ls        patchelf   split    tty
 basenc     date        g++      make      pr         stat     uname
 bash       dd          gawk     md5sum    printenv   stdbuf   unexpand
 bunzip2    df          gcc      mkdir     printf     strip    uniq
 bzip2      diff        grep     mkfifo    ptx        stty     unlink
 cat        diff3       groups   mknod     pwd        sum      uptime
 chcon      dircolors   gunzip   mktemp    ranlib     sync     wc
 chgrp      dirname     gzip     mv        readelf    tac      xargs
 chmod      du          head     nice      readlink   tail     xz
 chown      echo        hostid   nl        realpath   tar      yes
 chroot     egrep       id       nm        rm         tee

So I think that opens up some ways to keep the script simpler. For example something like (untested):

  preFixup = ''
    for f in $out/bin/*; do
      if head -1 "$f" | grep -qxF '#!/bin/sh'; then
        sed -i '2iPATH='$out'/bin:"$PATH"' "$f"
      fi
    done
  '';

That should do exactly the same thing as the all-Bash implementation in the current version of the PR.

(But if I'm mistaken about the meaning of bootstrap-tools, I'd be glad to learn! I tried looking in the docs and didn't succeed in finding much there about this.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Cool, thanks! I shortened it to a single sed -i.

@FRidh FRidh added this to WIP in Staging via automation Mar 6, 2020
@FRidh FRidh moved this from WIP to Needs review in Staging Mar 6, 2020
@FRidh FRidh merged commit d2d7fbc into NixOS:staging Apr 21, 2020
Staging automation moved this from Needs review to Done Apr 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Staging
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

5 participants