improve passing host and channel arguments to fup

we need to filter out arguments that are added in the devos api
also anything thats null in either hostDefaults and hosts has to be
removed
This commit is contained in:
Pacman99 2021-04-27 08:01:46 -07:00
parent 064ba88cdf
commit 466304c8cd
3 changed files with 25 additions and 21 deletions

View File

@ -81,7 +81,7 @@
"utils": "utils_2"
},
"locked": {
"narHash": "sha256-clwJnNLVOASak2CfkWu3Yztb1uWwtndY4VLDWEa9R3s=",
"narHash": "sha256-TOrVXGFk5rt1Wn14ja2spg44NuZnFM/V6qguQfO+8Kc=",
"path": "./lib",
"type": "path"
},
@ -355,11 +355,11 @@
"flake-utils": "flake-utils"
},
"locked": {
"lastModified": 1619480667,
"narHash": "sha256-KBiMpZcCv7D3wQ51ow7Sq8Xl01hDiRp5f7Py93CeD40=",
"lastModified": 1619532520,
"narHash": "sha256-+xIFAW5J0AcxwAflAX1gg/C8kfaqeZbS4XAZusCrZPY=",
"owner": "gytis-ivaskevicius",
"repo": "flake-utils-plus",
"rev": "be032a4396ad4cd7ea9bb733db8e456ec339ac9c",
"rev": "8eb7f9206713a528174c20c5133521dc37e2bfb1",
"type": "github"
},
"original": {

View File

@ -146,11 +146,11 @@
"flake-utils": "flake-utils"
},
"locked": {
"lastModified": 1619480667,
"narHash": "sha256-KBiMpZcCv7D3wQ51ow7Sq8Xl01hDiRp5f7Py93CeD40=",
"lastModified": 1619532520,
"narHash": "sha256-+xIFAW5J0AcxwAflAX1gg/C8kfaqeZbS4XAZusCrZPY=",
"owner": "gytis-ivaskevicius",
"repo": "flake-utils-plus",
"rev": "be032a4396ad4cd7ea9bb733db8e456ec339ac9c",
"rev": "8eb7f9206713a528174c20c5133521dc37e2bfb1",
"type": "github"
},
"original": {

View File

@ -25,35 +25,39 @@ let
})
];
stripChannel = channel: removeAttrs channel [
# arguments in our channels api that shouldn't be passed to fup
"overlays"
];
getDefaultChannel = channels: channels.${cfg.nixos.hostDefaults.channelName};
# 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) [
# arguments in our hosts/hostDefaults api that shouldn't be passed to fup
"externalModules"
];
hosts = lib.mapAttrs (_: stripHost) cfg.nixos.hosts;
hostDefaults = stripHost cfg.nixos.hostDefaults;
in
lib.systemFlake (lib.recursiveUpdate
otherArguments
{
inherit self inputs;
inherit self inputs hosts;
inherit (cfg) channelsConfig supportedSystems;
channels = mapAttrs
(name: channel:
channel // {
stripChannel (channel // {
# pass channels if "overlay" has three arguments
overlaysBuilder = channels: lib.unifyOverlays channels channel.overlays;
}
})
) cfg.channels;
# the host arguments cannot exist for fup hostDefaults to work
# so evalArgs sets them to null by default and the null args are filtered out here
hosts = mapAttrs (_: host: lib.filterAttrs (_: arg: arg != null) host) cfg.nixos.hosts;
hostDefaults = {
hostDefaults = lib.mergeAny hostDefaults {
specialArgs.suites = cfg.nixos.suites;
modules = cfg.nixos.hostDefaults.modules
++ cfg.nixos.hostDefaults.externalModules
++ defaultModules;
modules = cfg.nixos.hostDefaults.externalModules ++ defaultModules;
builder = os.devosSystem { inherit self inputs; };
inherit (cfg.nixos.hostDefaults)
channelName
system;
};
nixosModules = lib.exporter.modulesFromList cfg.nixos.hostDefaults.modules;