Add shellHook attr to configure default devShell

This commit is contained in:
Archit Gupta 2023-04-16 11:20:28 -07:00
parent 7509ce4110
commit 03cdbbabdf

View File

@ -6,11 +6,11 @@ localInputs:
let let
inherit (builtins) intersectAttrs isPath readDir; inherit (builtins) intersectAttrs isPath readDir;
inherit (localInputs.nixpkgs.lib) attrNames attrVals callPackageWith inherit (localInputs.nixpkgs.lib) attrNames attrVals callPackageWith
composeManyExtensions concat filter filterAttrs foldAttrs foldl functionArgs composeManyExtensions concat concatStringsSep filter filterAttrs foldAttrs
genAttrs hasSuffix isFunction isList isString listToAttrs mapAttrs foldl functionArgs genAttrs hasSuffix isFunction isList isString listToAttrs
mapAttrsToList mapAttrs' mergeAttrs nameValuePair optional optionalAttrs mapAttrs mapAttrsToList mapAttrs' mergeAttrs nameValuePair optional
optionalString parseDrvName pathExists pipe recursiveUpdate removePrefix optionalAttrs optionalString parseDrvName pathExists pipe recursiveUpdate
removeSuffix zipAttrsWith; removePrefix removeSuffix zipAttrsWith;
/* Attributes in flakelite's lib output. /* Attributes in flakelite's lib output.
*/ */
@ -109,6 +109,7 @@ let
"package" "package"
"packages" "packages"
"devTools" "devTools"
"shellHook"
"devShell" "devShell"
"devShells" "devShells"
"env" "env"
@ -155,15 +156,24 @@ let
fnConcat = liftFn2 concat; fnConcat = liftFn2 concat;
fnMergeAttrs = liftFn2 mergeAttrs; fnMergeAttrs = liftFn2 mergeAttrs;
/* Takes a function which takes a list, and returns a binary function.
Type: mkBinary :: ([a] -> b) -> a -> a -> b
*/
mkBinary = fn: a: b: fn [ a b ];
/* Merges attrsets of overlays, combining overlays with same name. /* Merges attrsets of overlays, combining overlays with same name.
*/ */
mergeOverlayAttrs = a: b: zipAttrsWith (_: composeManyExtensions) [ a b ]; mergeOverlayAttrs = mkBinary (zipAttrsWith (_: composeManyExtensions));
fnConcatScripts = liftFn2 (mkBinary (concatStringsSep "\n"));
mergeModules = a: b: mapAttrs (n: v: v a.${n} b.${n}) { mergeModules = a: b: mapAttrs (n: v: v a.${n} b.${n}) {
inputs = mergeAttrs; inputs = mergeAttrs;
withOverlays = concat; withOverlays = concat;
packages = mergeAttrs; packages = mergeAttrs;
devTools = fnConcat; devTools = fnConcat;
shellHook = fnConcatScripts;
devShells = fnMergeAttrs; devShells = fnMergeAttrs;
env = fnMergeAttrs; env = fnMergeAttrs;
overlays = mergeOverlayAttrs; overlays = mergeOverlayAttrs;
@ -285,6 +295,7 @@ let
withOverlays = [ ]; withOverlays = [ ];
packages = { }; packages = { };
devTools = _: [ ]; devTools = _: [ ];
shellHook = _: "";
devShells = _: { }; devShells = _: { };
env = _: { }; env = _: { };
overlays = { }; overlays = { };
@ -308,6 +319,7 @@ let
default = module'.package; default = module'.package;
}; };
devTools = filterArgs module'.devTools; devTools = filterArgs module'.devTools;
shellHook = filterArgs module'.shellHook;
devShells = fnMergeAttrs (filterArgs module'.devShells) devShells = fnMergeAttrs (filterArgs module'.devShells)
(_: optionalAttrs (module' ? devShell) { (_: optionalAttrs (module' ? devShell) {
default = module'.devShell; default = module'.devShell;
@ -453,6 +465,7 @@ let
inputsFrom = optional (prev ? packages.${system}.default) inputsFrom = optional (prev ? packages.${system}.default)
prev.packages.${system}.default; prev.packages.${system}.default;
packages = merged.devTools pkgs; packages = merged.devTools pkgs;
shellHook = merged.shellHook pkgs;
}); });
} // (callPkgs pkgs (merged.devShells pkgs)))) } // (callPkgs pkgs (merged.devShells pkgs))))
(eachSystem root'.perSystem) (eachSystem root'.perSystem)