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;
|
|
|
|
})
|
|
|
|
];
|
|
|
|
|
|
|
|
getDefaultChannel = channels: channels.${cfg.nixos.hostDefaults.channelName};
|
|
|
|
in
|
|
|
|
lib.systemFlake (lib.recursiveUpdate
|
|
|
|
otherArguments
|
|
|
|
{
|
|
|
|
inherit self inputs;
|
|
|
|
inherit (cfg) channelsConfig supportedSystems;
|
|
|
|
|
|
|
|
mkFlakeConfig = config;
|
2021-03-30 20:10:58 +02:00
|
|
|
|
2021-04-26 01:50:01 +02:00
|
|
|
channels = mapAttrs
|
|
|
|
(name: channel:
|
|
|
|
channel // {
|
|
|
|
# pass channels if "overlay" has three arguments
|
|
|
|
overlaysBuilder = channels: lib.unifyOverlays channels channel.overlays;
|
|
|
|
}
|
|
|
|
) cfg.channels;
|
2021-03-30 20:10:58 +02:00
|
|
|
|
2021-04-26 01:50:01 +02:00
|
|
|
# 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;
|
2021-03-30 20:10:58 +02:00
|
|
|
|
2021-04-26 01:50:01 +02:00
|
|
|
hostDefaults = {
|
|
|
|
specialArgs.suites = cfg.nixos.suites;
|
|
|
|
modules = cfg.nixos.hostDefaults.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;
|
|
|
|
|
|
|
|
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-26 21:29:18 +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;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
)
|