mirror of
https://github.com/divnix/digga.git
synced 2024-12-23 08:02:21 +03:00
refactor: prepare host configs in fup adapter
This commit is contained in:
parent
251395e7bd
commit
1c977a3cb5
@ -126,6 +126,7 @@
|
||||
# a little extra service ...
|
||||
overlays = import ./overlays { inherit inputs; };
|
||||
nixosModules = import ./modules;
|
||||
darwinModules = import ./modules;
|
||||
|
||||
defaultTemplate = self.templates.devos;
|
||||
templates.devos.path = ./examples/devos;
|
||||
|
@ -1,3 +1 @@
|
||||
{ inputs }: {
|
||||
|
||||
}
|
||||
{ inputs }: { }
|
||||
|
@ -47,23 +47,67 @@ let
|
||||
# arguments in our channels api that shouldn't be passed to fup
|
||||
"overlays"
|
||||
];
|
||||
|
||||
|
||||
# evalArgs sets channelName and system to null by default
|
||||
# but for proper default handling in fup, null args have to be removed
|
||||
stripHost = args: removeAttrs (lib.filterAttrs (_: arg: arg != null) args) [
|
||||
stripNull = args: (lib.filterAttrs (_: arg: arg != null) args);
|
||||
|
||||
stripHost = args: removeAttrs (stripNull args) [
|
||||
# arguments in our hosts/hostDefaults api that shouldn't be passed to fup
|
||||
"externalModules" # TODO: remove deprecated option
|
||||
"exportedModules"
|
||||
"tests"
|
||||
];
|
||||
|
||||
nixosHostDefaults = flake-utils-plus.lib.mergeAny
|
||||
{
|
||||
system = "x86_64-linux";
|
||||
output = "nixosConfigurations";
|
||||
|
||||
# add `self` & `inputs` as specialargs so their libs can be used in imports
|
||||
specialArgs = config.nixos.importables // { inherit (config) self inputs; };
|
||||
modules = config.nixos.hostDefaults.exportedModules ++ defaultHostModules;
|
||||
}
|
||||
(stripNull config.nixos.hostDefaults);
|
||||
nixosHosts = lib.mapAttrs
|
||||
(
|
||||
_: hostConfig:
|
||||
flake-utils-plus.lib.mergeAny
|
||||
nixosHostDefaults
|
||||
(stripNull hostConfig)
|
||||
)
|
||||
config.nixos.hosts;
|
||||
|
||||
darwinHostDefaults = flake-utils-plus.lib.mergeAny
|
||||
{
|
||||
system = "x86_64-darwin";
|
||||
output = "darwinConfigurations";
|
||||
builder = darwin.lib.darwinSystem;
|
||||
|
||||
# add `self` & `inputs` as specialargs so their libs can be used in imports
|
||||
specialArgs = config.darwin.importables // { inherit (config) self inputs; };
|
||||
modules = config.darwin.hostDefaults.exportedModules ++ defaultHostModules;
|
||||
}
|
||||
(stripNull config.darwin.hostDefaults);
|
||||
darwinHosts = lib.mapAttrs
|
||||
(
|
||||
_: hostConfig: flake-utils-plus.lib.mergeAny
|
||||
darwinHostDefaults
|
||||
(stripNull hostConfig)
|
||||
)
|
||||
config.darwin.hosts;
|
||||
|
||||
diggaFupArgs = {
|
||||
inherit (config)
|
||||
channelsConfig
|
||||
supportedSystems;
|
||||
inherit self inputs sharedOverlays;
|
||||
|
||||
hosts = builtins.mapAttrs (_: stripHost) config.nixos.hosts;
|
||||
hosts = builtins.mapAttrs (_: stripHost) (
|
||||
flake-utils-plus.lib.mergeAny
|
||||
nixosHosts
|
||||
darwinHosts
|
||||
);
|
||||
|
||||
channels = builtins.mapAttrs
|
||||
(name: channel:
|
||||
@ -74,14 +118,10 @@ let
|
||||
)
|
||||
config.channels;
|
||||
|
||||
hostDefaults = flake-utils-plus.lib.mergeAny (stripHost config.nixos.hostDefaults) {
|
||||
# add `self` & `inputs` as specialargs so their libs can be used in imports
|
||||
specialArgs = config.nixos.importables // { inherit self inputs; };
|
||||
modules = config.nixos.hostDefaults.exportedModules ++ defaultHostModules;
|
||||
};
|
||||
|
||||
nixosModules = flake-utils-plus.lib.exportModules config.nixos.hostDefaults.exportedModules;
|
||||
|
||||
darwinModules = flake-utils-plus.lib.exportModules config.darwin.hostDefaults.exportedModules;
|
||||
|
||||
homeModules = flake-utils-plus.lib.exportModules config.home.exportedModules;
|
||||
|
||||
devshellModules = flake-utils-plus.lib.exportModules config.devshell.exportedModules;
|
||||
@ -95,14 +135,14 @@ let
|
||||
};
|
||||
|
||||
outputsBuilder = channels:
|
||||
flake-utils-plus.lib.mergeAny (defaultOutputsBuilder channels) (config.outputsBuilder channels);
|
||||
|
||||
flake-utils-plus.lib.mergeAny
|
||||
(defaultOutputsBuilder channels)
|
||||
(config.outputsBuilder channels);
|
||||
};
|
||||
|
||||
in
|
||||
flake-utils-plus.lib.mkFlake
|
||||
(
|
||||
flake-utils-plus.lib.mergeAny
|
||||
diggaFupArgs
|
||||
extraArgs # for overlays list order
|
||||
)
|
||||
flake-utils-plus.lib.mkFlake (
|
||||
flake-utils-plus.lib.mergeAny
|
||||
diggaFupArgs
|
||||
extraArgs # for overlays list order
|
||||
)
|
||||
|
@ -137,6 +137,42 @@ in
|
||||
customTests
|
||||
else { }
|
||||
)
|
||||
//
|
||||
(
|
||||
# for self.darwinConfigurations if present & non-empty
|
||||
if (
|
||||
(builtins.hasAttr "darwinConfigurations" self) &&
|
||||
(self.darwinConfigurations != { })
|
||||
) then
|
||||
let
|
||||
systemSieve = _: host: host.config.nixpkgs.system == system;
|
||||
hostConfigsOnThisSystem = lib.filterAttrs systemSieve self.darwinConfigurations;
|
||||
|
||||
createCustomTestOp = n: host: test:
|
||||
lib.warnIf (!(test ? name)) ''
|
||||
'${n}' has a test without a name. To distinguish tests in the flake output
|
||||
all darwin tests must have names.
|
||||
''
|
||||
{
|
||||
name = "customTestFor-${n}-${test.name}";
|
||||
value = tests.mkTest host test;
|
||||
};
|
||||
|
||||
createCustomTestsOp = n: host:
|
||||
let
|
||||
op = createCustomTestOp n host;
|
||||
in
|
||||
builtins.listToAttrs (map op config.darwin.hosts.${n}.tests);
|
||||
|
||||
customTests =
|
||||
if (hostConfigsOnThisSystem != [ ])
|
||||
then lib.foldl (a: b: a // b) { } (lib.attrValues (lib.mapAttrs createCustomTestsOp hostConfigsOnThisSystem))
|
||||
else { };
|
||||
|
||||
in
|
||||
customTests
|
||||
else { }
|
||||
)
|
||||
;
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user