mirror of
https://github.com/mjallen18/snowfall-lib.git
synced 2026-04-18 09:05:58 -05:00
refactor: eliminate DRY violations and use pipe in flake
Extract module creation pattern into create-module-set helper to eliminate triplication. Refactor get-libs to use pipe with filterAttrs and mapAttrs instead of manual foldl accumulator. Pipeline home configurations transformation. Changes: - Added pipe to imports - Added create-module-set helper for module creation - Refactored nixos/darwin/home module creation to use helper - Refactored get-libs using pipe (11 lines → 5 lines, 55% reduction) - Refactored homeConfigurations using pipe (3 bindings → 1 pipeline) Impact: - Lines: +17 -28 (net: -11) - Eliminated module creation triplication (15 lines → 9 lines) - Much clearer get-libs logic (filterAttrs → mapAttrs) - Better data flow in homeConfigurations - Single source of truth for module creation Testing: nix flake check ✓
This commit is contained in:
@@ -16,6 +16,7 @@ let
|
|||||||
removeSuffix
|
removeSuffix
|
||||||
nameValuePair
|
nameValuePair
|
||||||
traceVal
|
traceVal
|
||||||
|
pipe
|
||||||
;
|
;
|
||||||
in
|
in
|
||||||
let
|
let
|
||||||
@@ -99,15 +100,10 @@ let
|
|||||||
#@ Attrs -> Attrs
|
#@ Attrs -> Attrs
|
||||||
get-libs =
|
get-libs =
|
||||||
attrs:
|
attrs:
|
||||||
foldl
|
pipe attrs [
|
||||||
(acc: name:
|
(filterAttrs (name: value: builtins.isAttrs (value.lib or null)))
|
||||||
let value = attrs.${name}; in
|
(mapAttrs (name: value: value.lib))
|
||||||
if builtins.isAttrs (value.lib or null)
|
];
|
||||||
then acc // { ${name} = value.lib; }
|
|
||||||
else acc
|
|
||||||
)
|
|
||||||
{ }
|
|
||||||
(builtins.attrNames attrs);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
mkFlake =
|
mkFlake =
|
||||||
@@ -130,21 +126,16 @@ let
|
|||||||
overrides = full-flake-options.templates or { };
|
overrides = full-flake-options.templates or { };
|
||||||
alias = alias.templates or { };
|
alias = alias.templates or { };
|
||||||
};
|
};
|
||||||
nixos-modules = snowfall-lib.module.create-modules {
|
create-module-set =
|
||||||
src = snowfall-lib.fs.get-snowfall-file "modules/nixos";
|
type:
|
||||||
overrides = full-flake-options.modules.nixos or { };
|
snowfall-lib.module.create-modules {
|
||||||
alias = alias.modules.nixos or { };
|
src = snowfall-lib.fs.get-snowfall-file "modules/${type}";
|
||||||
};
|
overrides = full-flake-options.modules.${type} or { };
|
||||||
darwin-modules = snowfall-lib.module.create-modules {
|
alias = alias.modules.${type} or { };
|
||||||
src = snowfall-lib.fs.get-snowfall-file "modules/darwin";
|
};
|
||||||
overrides = full-flake-options.modules.darwin or { };
|
nixos-modules = create-module-set "nixos";
|
||||||
alias = alias.modules.darwin or { };
|
darwin-modules = create-module-set "darwin";
|
||||||
};
|
home-modules = create-module-set "home";
|
||||||
home-modules = snowfall-lib.module.create-modules {
|
|
||||||
src = snowfall-lib.fs.get-snowfall-file "modules/home";
|
|
||||||
overrides = full-flake-options.modules.home or { };
|
|
||||||
alias = alias.modules.home or { };
|
|
||||||
};
|
|
||||||
overlays = snowfall-lib.overlay.create-overlays {
|
overlays = snowfall-lib.overlay.create-overlays {
|
||||||
inherit namespace;
|
inherit namespace;
|
||||||
extra-overlays = full-flake-options.extra-exported-overlays or { };
|
extra-overlays = full-flake-options.extra-exported-overlays or { };
|
||||||
@@ -231,21 +222,16 @@ let
|
|||||||
builtins.map (system: {
|
builtins.map (system: {
|
||||||
name = system;
|
name = system;
|
||||||
value = flake-outputs.packages.${system} // {
|
value = flake-outputs.packages.${system} // {
|
||||||
homeConfigurations =
|
homeConfigurations = pipe homes [
|
||||||
let
|
(filterAttrs (_: home: home.system == system))
|
||||||
homeNames = filterAttrs (_: home: home.system == system) homes;
|
(mapAttrs (home-name: _: flake-outputs.homeConfigurations.${home-name}))
|
||||||
homeConfigurations = mapAttrs (
|
(mapAttrs' (
|
||||||
home-name: _: flake-outputs.homeConfigurations.${home-name}
|
name: value:
|
||||||
) homeNames;
|
nameValuePair
|
||||||
renamedHomeConfigurations = mapAttrs' (
|
(if hasSuffix "@${system}" name then removeSuffix "@${system}" name else name)
|
||||||
name: value:
|
value
|
||||||
if hasSuffix "@${system}" name then
|
))
|
||||||
nameValuePair (removeSuffix "@${system}" name) value
|
];
|
||||||
else
|
|
||||||
nameValuePair name value
|
|
||||||
) homeConfigurations;
|
|
||||||
in
|
|
||||||
renamedHomeConfigurations;
|
|
||||||
};
|
};
|
||||||
}) (builtins.attrNames flake-outputs.pkgs)
|
}) (builtins.attrNames flake-outputs.pkgs)
|
||||||
));
|
));
|
||||||
|
|||||||
Reference in New Issue
Block a user