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

stdenv.mkDerivation: fix unpackPhase for archives with bad permissions #5

Open
milahu opened this issue Aug 14, 2023 · 0 comments
Open

Comments

@milahu
Copy link
Owner

milahu commented Aug 14, 2023

this fails in unpackPhase, because the lib/ folder in https://registry.npmjs.org/pngjs/-/pngjs-6.0.0.tgz has mode 0444, but should have mode 0555

when the executable flag is missing on a directory, its contents cannot be listed, which gives the Cannot open: Permission denied errors

nix-build -E '
  with import <nixpkgs> { };
  stdenv.mkDerivation {
    name = "x";
    src = fetchurl {
      url = "https://registry.npmjs.org/pngjs/-/pngjs-6.0.0.tgz";
      hash = "sha512-TRzzuFRRmEoSW/p1KVAmiOgPco2Irlah+bGFCeNfJXxxYGwSw7YwAOAcd7X28K/m5bjBWKsC29KyoMfHbypayg==";
    };
    buildPhase = "ls -l $src; exit 1";
  }'
this derivation will be built:
  /nix/store/5nvbj071zy4bdxx73gw5f6dlhxcb8fw3-x.drv
building '/nix/store/5nvbj071zy4bdxx73gw5f6dlhxcb8fw3-x.drv'...
unpacking sources
unpacking source archive /nix/store/jb1wi55v5z2gzx2rjma0v5323fij6wjp-pngjs-6.0.0.tgz
tar: package/lib/bitmapper.js: Cannot open: Permission denied
tar: package/lib/bitpacker.js: Cannot open: Permission denied
tar: package/lib/chunkstream.js: Cannot open: Permission denied
tar: package/lib/constants.js: Cannot open: Permission denied
tar: package/lib/crc.js: Cannot open: Permission denied
tar: package/lib/filter-pack.js: Cannot open: Permission denied
tar: package/lib/filter-parse-async.js: Cannot open: Permission denied
tar: package/lib/filter-parse-sync.js: Cannot open: Permission denied
tar: package/lib/filter-parse.js: Cannot open: Permission denied
tar: package/lib/format-normaliser.js: Cannot open: Permission denied
tar: package/lib/interlace.js: Cannot open: Permission denied
tar: package/lib/packer-async.js: Cannot open: Permission denied
tar: package/lib/packer-sync.js: Cannot open: Permission denied
tar: package/lib/packer.js: Cannot open: Permission denied
tar: package/lib/paeth-predictor.js: Cannot open: Permission denied
tar: package/lib/parser-async.js: Cannot open: Permission denied
tar: package/lib/parser-sync.js: Cannot open: Permission denied
tar: package/lib/parser.js: Cannot open: Permission denied
tar: package/lib/png-sync.js: Cannot open: Permission denied
tar: package/lib/png.js: Cannot open: Permission denied
tar: package/lib/sync-inflate.js: Cannot open: Permission denied
tar: package/lib/sync-reader.js: Cannot open: Permission denied
tar: Exiting with failure status due to previous errors
do not know how to unpack source archive /nix/store/jb1wi55v5z2gzx2rjma0v5323fij6wjp-pngjs-6.0.0.tgz
error: builder for '/nix/store/5nvbj071zy4bdxx73gw5f6dlhxcb8fw3-x.drv' failed with exit code 1;

why

cd $(mktemp -d)

wget https://registry.npmjs.org/pngjs/-/pngjs-6.0.0.tgz

tar xf *.tgz --warning=no-timestamp --warning=no-unknown-keyword --no-same-owner --no-same-permissions --delay-directory-restore

stat -c%a package/
# 644

chmod -R +wX package/

stat -c%a package/
# 755

fix

1. add more arguments to tar xf "$fn" --warning=no-timestamp

for example tar xf "$fn" --warning=no-timestamp --warning=no-unknown-keyword --no-same-owner --no-same-permissions --delay-directory-restore

2. after tar xf run chmod -R +X "${sourceRoot}" to add the executable flag on all directories. this can be merged with chmod -R +w "${sourceRoot}" to chmod -R +wX "${sourceRoot}"

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

No branches or pull requests

1 participant