static-nix-shell: add a `srcRoot` argument which allows more precisely specifying the source files and avoiding unnecessary rebuilds

This commit is contained in:
Colin 2024-02-25 17:37:10 +00:00
parent 953dd98b0f
commit e757e35065
1 changed files with 10 additions and 1 deletions

View File

@ -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: <https://ryantm.github.io/nixpkgs/functions/library/fileset/>
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.