From 9f73309ff19bda94d6bcbe77dcd72c1c65a9f37d Mon Sep 17 00:00:00 2001 From: NAHO <90870942+trueNAHO@users.noreply.github.com> Date: Tue, 1 Oct 2024 10:35:34 +0200 Subject: [PATCH] modules: pre-commit: make pkgs.buildEnv composable Passing a git-hooks.lib..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 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]: https://github.com/NixOS/nixpkgs/pull/325140 Link: https://github.com/cachix/git-hooks.nix/pull/498 --- modules/pre-commit.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/pre-commit.nix b/modules/pre-commit.nix index a5fae075..1a1701dd 100644 --- a/modules/pre-commit.nix +++ b/modules/pre-commit.nix @@ -78,7 +78,7 @@ let fi exitcode=$? git --no-pager diff --color - touch $out + mkdir $out [ $? -eq 0 ] && exit $exitcode '';