2021-04-19 05:29:28 +02:00
|
|
|
{ lib, deploy }:
|
2021-03-30 20:10:58 +02:00
|
|
|
let
|
2021-04-19 05:29:28 +02:00
|
|
|
inherit (lib) os;
|
2021-04-26 01:50:01 +02:00
|
|
|
inherit (builtins) mapAttrs attrNames attrValues head isFunction;
|
2021-03-30 20:10:58 +02:00
|
|
|
in
|
|
|
|
|
2021-04-26 01:50:01 +02:00
|
|
|
_: { self, inputs, ... } @ args:
|
2021-03-30 20:10:58 +02:00
|
|
|
let
|
|
|
|
|
2021-04-26 01:50:01 +02:00
|
|
|
config = lib.mkFlake.evalArgs {
|
2021-04-27 06:32:26 +02:00
|
|
|
inherit args;
|
2021-04-26 01:50:01 +02:00
|
|
|
};
|
2021-03-30 20:10:58 +02:00
|
|
|
|
2021-04-26 01:50:01 +02:00
|
|
|
cfg = config.config;
|
2021-03-30 20:10:58 +02:00
|
|
|
|
2021-04-26 01:50:01 +02:00
|
|
|
otherArguments = removeAttrs args (attrNames config.options);
|
2021-03-30 20:10:58 +02:00
|
|
|
|
2021-04-26 01:50:01 +02:00
|
|
|
defaultModules = with lib.modules; [
|
|
|
|
(hmDefaults {
|
|
|
|
inherit (cfg.home) suites;
|
|
|
|
modules = cfg.home.modules ++ cfg.home.externalModules;
|
|
|
|
})
|
|
|
|
(globalDefaults {
|
|
|
|
inherit self inputs;
|
|
|
|
})
|
|
|
|
];
|
|
|
|
|
2021-04-27 17:01:46 +02:00
|
|
|
stripChannel = channel: removeAttrs channel [
|
|
|
|
# arguments in our channels api that shouldn't be passed to fup
|
|
|
|
"overlays"
|
|
|
|
];
|
2021-04-26 01:50:01 +02:00
|
|
|
getDefaultChannel = channels: channels.${cfg.nixos.hostDefaults.channelName};
|
2021-04-27 17:01:46 +02:00
|
|
|
|
|
|
|
# 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;
|
2021-04-26 01:50:01 +02:00
|
|
|
in
|
|
|
|
lib.systemFlake (lib.recursiveUpdate
|
|
|
|
otherArguments
|
|
|
|
{
|
2021-04-27 17:01:46 +02:00
|
|
|
inherit self inputs hosts;
|
2021-04-26 01:50:01 +02:00
|
|
|
inherit (cfg) channelsConfig supportedSystems;
|
|
|
|
|
|
|
|
channels = mapAttrs
|
|
|
|
(name: channel:
|
2021-04-27 17:01:46 +02:00
|
|
|
stripChannel (channel // {
|
2021-04-26 01:50:01 +02:00
|
|
|
# pass channels if "overlay" has three arguments
|
|
|
|
overlaysBuilder = channels: lib.unifyOverlays channels channel.overlays;
|
2021-04-27 17:01:46 +02:00
|
|
|
})
|
2021-04-27 18:32:12 +02:00
|
|
|
)
|
|
|
|
cfg.channels;
|
2021-03-30 20:10:58 +02:00
|
|
|
|
2021-04-27 17:01:46 +02:00
|
|
|
hostDefaults = lib.mergeAny hostDefaults {
|
2021-04-26 01:50:01 +02:00
|
|
|
specialArgs.suites = cfg.nixos.suites;
|
2021-04-27 17:01:46 +02:00
|
|
|
modules = cfg.nixos.hostDefaults.externalModules ++ defaultModules;
|
2021-04-26 01:50:01 +02:00
|
|
|
builder = os.devosSystem { inherit self inputs; };
|
|
|
|
};
|
|
|
|
|
|
|
|
nixosModules = lib.exporter.modulesFromList cfg.nixos.hostDefaults.modules;
|
|
|
|
|
|
|
|
homeModules = lib.exporter.modulesFromList cfg.home.modules;
|
|
|
|
homeConfigurations = os.mkHomeConfigurations self.nixosConfigurations;
|
2021-03-30 20:10:58 +02:00
|
|
|
|
2021-04-24 03:13:03 +02:00
|
|
|
deploy.nodes = os.mkNodes deploy self.nixosConfigurations;
|
2021-03-30 20:10:58 +02:00
|
|
|
|
2021-04-26 21:20:16 +02:00
|
|
|
overlays = lib.exporter.overlaysFromChannelsExporter {
|
2021-04-27 18:32:12 +02:00
|
|
|
# since we can't detect overlays owned by self
|
|
|
|
# we have to filter out ones exported by the inputs
|
|
|
|
# optimally we would want a solution for NixOS/nix#4740
|
2021-04-26 21:20:16 +02:00
|
|
|
inherit inputs;
|
|
|
|
inherit (self) pkgs;
|
|
|
|
};
|
2021-04-26 01:50:01 +02:00
|
|
|
|
|
|
|
packagesBuilder = lib.builder.packagesFromOverlaysBuilderConstructor self.overlays;
|
|
|
|
|
|
|
|
checksBuilder = channels:
|
|
|
|
lib.pkgs-lib.tests.mkChecks {
|
|
|
|
pkgs = getDefaultChannel channels;
|
2021-04-24 03:13:03 +02:00
|
|
|
inherit (self.deploy) nodes;
|
|
|
|
hosts = self.nixosConfigurations;
|
|
|
|
homes = self.homeConfigurations;
|
2021-04-10 19:59:10 +02:00
|
|
|
};
|
2021-03-30 20:10:58 +02:00
|
|
|
|
2021-04-26 01:50:01 +02:00
|
|
|
devShellBuilder = channels:
|
|
|
|
lib.pkgs-lib.shell {
|
|
|
|
pkgs = getDefaultChannel channels;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
)
|