flake-parts/setups: refactor

This commit is contained in:
Gabriel Arazas 2024-01-17 14:02:02 +08:00
parent 8a9e20b5f4
commit d2993a367b
No known key found for this signature in database
GPG Key ID: ADE0C41DAB221FCC
2 changed files with 56 additions and 59 deletions

View File

@ -251,18 +251,17 @@ in
) )
metadata.systems); metadata.systems);
in in
lib.mapAttrs lib.mapAttrs generatePureConfigs cfg.configs;
(hostname: metadata:
generatePureConfigs hostname metadata)
cfg.configs;
in in
{ {
homeConfigurations = homeConfigurations =
let
renameSystems = name: system: config:
lib.nameValuePair "${name}-${system}" config;
in
lib.concatMapAttrs lib.concatMapAttrs
(name: configs: (name: configs:
lib.mapAttrs' lib.mapAttrs' (renameSystems name) configs)
(system: config: lib.nameValuePair "${name}-${system}" config)
configs)
pureHomeManagerConfigs; pureHomeManagerConfigs;
deploy.nodes = deploy.nodes =
@ -271,12 +270,9 @@ in
lib.filterAttrs lib.filterAttrs
(name: _: cfg.configs.${name}.deploy != null) (name: _: cfg.configs.${name}.deploy != null)
pureHomeManagerConfigs; pureHomeManagerConfigs;
in
lib.concatMapAttrs generateDeployNode = name: system: config:
(name: configs: lib.nameValuePair "home-manager-${name}-${system}" (
lib.mapAttrs'
(system: config: lib.nameValuePair "home-manager-${name}-${system}"
(
let let
deployConfig = cfg.configs.${name}.deploy; deployConfig = cfg.configs.${name}.deploy;
deployConfig' = lib.attrsets.removeAttrs deployConfig [ "profiles" ]; deployConfig' = lib.attrsets.removeAttrs deployConfig [ "profiles" ];
@ -288,8 +284,11 @@ in
inherit name config system; inherit name config system;
}; };
} }
)) );
configs) in
lib.concatMapAttrs
(name: configs:
lib.mapAttrs' (generateDeployNode name) configs)
validConfigs; validConfigs;
}; };
}; };

View File

@ -330,18 +330,17 @@ in
) )
metadata.systems); metadata.systems);
in in
lib.mapAttrs lib.mapAttrs generatePureConfigs validConfigs;
(hostname: metadata:
generatePureConfigs hostname metadata)
validConfigs;
in in
{ {
nixosConfigurations = nixosConfigurations =
let
renameSystems = name: system: config:
lib.nameValuePair "${name}-${system}" config;
in
lib.concatMapAttrs lib.concatMapAttrs
(name: configs: (name: configs:
lib.mapAttrs' lib.mapAttrs' (renameSystems name) configs)
(system: config: lib.nameValuePair "${name}-${system}" config)
configs)
pureNixosConfigs; pureNixosConfigs;
deploy.nodes = deploy.nodes =
@ -350,11 +349,9 @@ in
lib.filterAttrs lib.filterAttrs
(name: _: cfg.configs.${name}.deploy != null) (name: _: cfg.configs.${name}.deploy != null)
pureNixosConfigs; pureNixosConfigs;
in
lib.concatMapAttrs generateDeployNode = name: system: config:
(name: configs: lib.nameValuePair "nixos-${name}-${system}"
lib.mapAttrs'
(system: config: lib.nameValuePair "nixos-${name}-${system}"
( (
let let
deployConfig = cfg.configs.${name}.deploy; deployConfig = cfg.configs.${name}.deploy;
@ -367,8 +364,11 @@ in
inherit name config system; inherit name config system;
}; };
} }
)) );
configs) in
lib.concatMapAttrs
(name: configs:
lib.mapAttrs' (generateDeployNode name) configs)
validConfigs; validConfigs;
}; };
@ -382,23 +382,21 @@ in
generateImages = name: metadata: generateImages = name: metadata:
let let
images = buildImage = format:
builtins.map
(format:
lib.nameValuePair lib.nameValuePair
"${name}-${format}" "${name}-${format}"
(mkImage { (mkImage {
inherit (metadata) nixpkgsBranch; inherit (metadata) nixpkgsBranch;
inherit system format; inherit system format;
extraModules = cfg.sharedModules ++ metadata.modules; extraModules = cfg.sharedModules ++ metadata.modules;
})) });
metadata.formats;
images =
builtins.map buildImage metadata.formats;
in in
lib.listToAttrs images; lib.listToAttrs images;
in in
lib.concatMapAttrs lib.concatMapAttrs generateImages validImages;
(name: metadata: generateImages name metadata)
validImages;
}; };
}; };
} }