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,25 +270,25 @@ in
lib.filterAttrs lib.filterAttrs
(name: _: cfg.configs.${name}.deploy != null) (name: _: cfg.configs.${name}.deploy != null)
pureHomeManagerConfigs; pureHomeManagerConfigs;
generateDeployNode = name: system: config:
lib.nameValuePair "home-manager-${name}-${system}" (
let
deployConfig = cfg.configs.${name}.deploy;
deployConfig' = lib.attrsets.removeAttrs deployConfig [ "profiles" ];
in
deployConfig'
// {
profiles =
cfg.configs.${name}.deploy.profiles {
inherit name config system;
};
}
);
in in
lib.concatMapAttrs lib.concatMapAttrs
(name: configs: (name: configs:
lib.mapAttrs' lib.mapAttrs' (generateDeployNode name) configs)
(system: config: lib.nameValuePair "home-manager-${name}-${system}"
(
let
deployConfig = cfg.configs.${name}.deploy;
deployConfig' = lib.attrsets.removeAttrs deployConfig [ "profiles" ];
in
deployConfig'
// {
profiles =
cfg.configs.${name}.deploy.profiles {
inherit name config system;
};
}
))
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,25 +349,26 @@ in
lib.filterAttrs lib.filterAttrs
(name: _: cfg.configs.${name}.deploy != null) (name: _: cfg.configs.${name}.deploy != null)
pureNixosConfigs; pureNixosConfigs;
generateDeployNode = name: system: config:
lib.nameValuePair "nixos-${name}-${system}"
(
let
deployConfig = cfg.configs.${name}.deploy;
deployConfig' = lib.attrsets.removeAttrs deployConfig [ "profiles" ];
in
deployConfig'
// {
profiles =
cfg.configs.${name}.deploy.profiles {
inherit name config system;
};
}
);
in in
lib.concatMapAttrs lib.concatMapAttrs
(name: configs: (name: configs:
lib.mapAttrs' lib.mapAttrs' (generateDeployNode name) configs)
(system: config: lib.nameValuePair "nixos-${name}-${system}"
(
let
deployConfig = cfg.configs.${name}.deploy;
deployConfig' = lib.attrsets.removeAttrs deployConfig [ "profiles" ];
in
deployConfig'
// {
profiles =
cfg.configs.${name}.deploy.profiles {
inherit name config system;
};
}
))
configs)
validConfigs; validConfigs;
}; };
@ -382,23 +382,21 @@ in
generateImages = name: metadata: generateImages = name: metadata:
let let
buildImage = format:
lib.nameValuePair
"${name}-${format}"
(mkImage {
inherit (metadata) nixpkgsBranch;
inherit system format;
extraModules = cfg.sharedModules ++ metadata.modules;
});
images = images =
builtins.map builtins.map buildImage metadata.formats;
(format:
lib.nameValuePair
"${name}-${format}"
(mkImage {
inherit (metadata) nixpkgsBranch;
inherit system format;
extraModules = cfg.sharedModules ++ metadata.modules;
}))
metadata.formats;
in in
lib.listToAttrs images; lib.listToAttrs images;
in in
lib.concatMapAttrs lib.concatMapAttrs generateImages validImages;
(name: metadata: generateImages name metadata)
validImages;
}; };
}; };
} }