From 37955437a78e6effe93022d70a131ff88e92a08e Mon Sep 17 00:00:00 2001 From: Sam Pointon Date: Sun, 26 Apr 2026 17:18:59 +0100 Subject: [PATCH] fetchPnpmDeps: don't fail on empty lockfile If the lockfile is empty, no files will be put in the output directory. In this case, the find invocations produce an empty list of results. xargs' default behaviour is to always invoke its command at least once; if its input is empty, then its command will not be passed any filenames. This produces an invocation like `chmod 555`. chmod, however, fails in this case, expecting an operand. So we need to tell xargs not to invoke its command at all in the case of empty input. --- .../node/fetch-pnpm-deps/default.nix | 6 ++-- pkgs/test/default.nix | 2 ++ pkgs/test/pnpm/default.nix | 4 +++ .../test/pnpm/pnpm-empty-lockfile/default.nix | 32 +++++++++++++++++++ pkgs/test/pnpm/pnpm-empty-lockfile/main.mjs | 0 .../pnpm/pnpm-empty-lockfile/package.json | 6 ++++ .../pnpm/pnpm-empty-lockfile/pnpm-lock.yaml | 9 ++++++ 7 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 pkgs/test/pnpm/default.nix create mode 100644 pkgs/test/pnpm/pnpm-empty-lockfile/default.nix create mode 100644 pkgs/test/pnpm/pnpm-empty-lockfile/main.mjs create mode 100644 pkgs/test/pnpm/pnpm-empty-lockfile/package.json create mode 100644 pkgs/test/pnpm/pnpm-empty-lockfile/pnpm-lock.yaml diff --git a/pkgs/build-support/node/fetch-pnpm-deps/default.nix b/pkgs/build-support/node/fetch-pnpm-deps/default.nix index 582ea27150114..6b33c263b895b 100644 --- a/pkgs/build-support/node/fetch-pnpm-deps/default.nix +++ b/pkgs/build-support/node/fetch-pnpm-deps/default.nix @@ -162,9 +162,9 @@ in # See https://github.com/NixOS/nixpkgs/pull/350063 # See https://github.com/NixOS/nixpkgs/issues/422889 if [[ ${toString fetcherVersion} -ge 2 ]]; then - find $storePath -type f -name "*-exec" -print0 | xargs -0 chmod 555 - find $storePath -type f -not -name "*-exec" -print0 | xargs -0 chmod 444 - find $storePath -type d -print0 | xargs -0 chmod 555 + find $storePath -type f -name "*-exec" -print0 | xargs --no-run-if-empty -0 chmod 555 + find $storePath -type f -not -name "*-exec" -print0 | xargs --no-run-if-empty -0 chmod 444 + find $storePath -type d -print0 | xargs --no-run-if-empty -0 chmod 555 fi if [[ ${toString fetcherVersion} -ge 3 ]]; then diff --git a/pkgs/test/default.nix b/pkgs/test/default.nix index 9270784835803..63e8e2b32aaef 100644 --- a/pkgs/test/default.nix +++ b/pkgs/test/default.nix @@ -170,6 +170,8 @@ in php = recurseIntoAttrs (callPackages ./php { }); + pnpm = recurseIntoAttrs (callPackages ./pnpm { }); + go = recurseIntoAttrs (callPackage ../build-support/go/tests.nix { }); lake = callPackage ../build-support/lake/test { }; diff --git a/pkgs/test/pnpm/default.nix b/pkgs/test/pnpm/default.nix new file mode 100644 index 0000000000000..1e7d882ce295e --- /dev/null +++ b/pkgs/test/pnpm/default.nix @@ -0,0 +1,4 @@ +{ callPackage }: +{ + pnpm-empty-lockfile = callPackage ./pnpm-empty-lockfile { }; +} diff --git a/pkgs/test/pnpm/pnpm-empty-lockfile/default.nix b/pkgs/test/pnpm/pnpm-empty-lockfile/default.nix new file mode 100644 index 0000000000000..bb40b0aa749a0 --- /dev/null +++ b/pkgs/test/pnpm/pnpm-empty-lockfile/default.nix @@ -0,0 +1,32 @@ +{ + pkgs, + stdenv, + fetchPnpmDeps, + nodejs, + pnpm_10, + pnpmConfigHook, +}: +stdenv.mkDerivation { + name = "pnpm-empty-lockfile"; + + src = ./.; + + nativeBuildInputs = [ + pnpm_10 + pnpmConfigHook + ]; + + pnpmDeps = fetchPnpmDeps { + pname = "pnpm-empty-lockfile"; + fetcherVersion = 3; + pnpm = pnpm_10; + src = ./.; + hash = "sha256-u0GOAX5B1f2ANWbOezScp/eKQRRZA/JoYfQ5zLrNip4="; + }; + + buildPhase = '' + runHook preBuild + touch $out + runHook postBuild + ''; +} diff --git a/pkgs/test/pnpm/pnpm-empty-lockfile/main.mjs b/pkgs/test/pnpm/pnpm-empty-lockfile/main.mjs new file mode 100644 index 0000000000000..e69de29bb2d1d diff --git a/pkgs/test/pnpm/pnpm-empty-lockfile/package.json b/pkgs/test/pnpm/pnpm-empty-lockfile/package.json new file mode 100644 index 0000000000000..5fde86ab7086a --- /dev/null +++ b/pkgs/test/pnpm/pnpm-empty-lockfile/package.json @@ -0,0 +1,6 @@ +{ + "name": "pnpm-empty-lockfile", + "main": "main.mjs", + "dependencies": { + } +} diff --git a/pkgs/test/pnpm/pnpm-empty-lockfile/pnpm-lock.yaml b/pkgs/test/pnpm/pnpm-empty-lockfile/pnpm-lock.yaml new file mode 100644 index 0000000000000..9b60ae1782d6d --- /dev/null +++ b/pkgs/test/pnpm/pnpm-empty-lockfile/pnpm-lock.yaml @@ -0,0 +1,9 @@ +lockfileVersion: '9.0' + +settings: + autoInstallPeers: true + excludeLinksFromLockfile: false + +importers: + + .: {}