Skip to content

Commit

Permalink
modules: pre-commit: make pkgs.buildEnv composable
Browse files Browse the repository at this point in the history
Passing a git-hooks.lib.<SYSTEM>.run derivation as a path to
pkgs.buildEnv results in the following error due to derivations with an
empty file being treated differently from derivations with an empty
directory:

    The store path <TARGET> is a file and can't be merged into an
    environment using pkgs.buildEnv!

Since Nixpkgs rejected explicitly handling derivations with an empty
file in pkgs.buildEnv [1], affected derivations should transition from
'touch $out' to 'mkdir $out' to be pkgs.buildEnv composable.

This change replaces 'touch $out' with 'mkdir $out' and makes the
following command work:

    nix \
      build \
      --expr '
        let
          flake = builtins.getFlake (toString ./.);
          system = builtins.currentSystem;
        in
          flake.inputs.nixpkgs.legacyPackages.${system}.buildEnv {
            name = "";
            paths = [(flake.outputs.lib.${system}.run {src = ./.;})];
          }
      ' \
      --impure

[1]: NixOS/nixpkgs#325140

Link: #498
  • Loading branch information
trueNAHO committed Oct 1, 2024
1 parent 85f7a71 commit 9f73309
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion modules/pre-commit.nix
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ let
fi
exitcode=$?
git --no-pager diff --color
touch $out
mkdir $out
[ $? -eq 0 ] && exit $exitcode
'';

Expand Down

0 comments on commit 9f73309

Please sign in to comment.