From e757e3506578b1197b4915c03ea5bceaa9c66c5c Mon Sep 17 00:00:00 2001 From: Colin Date: Sun, 25 Feb 2024 17:37:10 +0000 Subject: [PATCH] static-nix-shell: add a `srcRoot` argument which allows more precisely specifying the source files and avoiding unnecessary rebuilds --- pkgs/additional/static-nix-shell/default.nix | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pkgs/additional/static-nix-shell/default.nix b/pkgs/additional/static-nix-shell/default.nix index febabf60..dcc010ca 100644 --- a/pkgs/additional/static-nix-shell/default.nix +++ b/pkgs/additional/static-nix-shell/default.nix @@ -37,10 +37,19 @@ in rec { pkgsEnv, pkgExprs, srcPath ? pname, + srcRoot ? null, extraMakeWrapperArgs ? [], ... }@attrs: let + extraDerivArgs = lib.optionalAttrs (srcRoot != null) { + # use can use `srcRoot` instead of `src` in most scenarios, to avoid include the entire directory containing their + # source file in the closure, but *just* the source file itself. + # `lib.fileset` docs: + src = lib.fileset.toSource { + root = srcRoot; fileset = lib.path.append srcRoot srcPath; + }; + }; pkgsStr = concatStringsSep "" (map (pname: " -p ${pname}") pkgExprs @@ -79,7 +88,7 @@ in rec { runHook postInstall ''; - } // (removeAttrs attrs [ "extraMakeWrapperArgs" "interpreter" "interpreterName" "pkgsEnv" "pkgExprs" "srcPath" ]) + } // extraDerivArgs // (removeAttrs attrs [ "extraMakeWrapperArgs" "interpreter" "interpreterName" "pkgsEnv" "pkgExprs" "srcPath" ]) ); # `mkShell` specialization for `nix-shell -i bash` scripts.