2021-04-19 03:29:28 +00:00
|
|
|
{ lib, deploy }:
|
2021-03-30 18:10:58 +00:00
|
|
|
let
|
2021-04-19 03:29:28 +00:00
|
|
|
inherit (lib) os;
|
2021-04-25 23:50:01 +00:00
|
|
|
inherit (builtins) mapAttrs attrNames attrValues head isFunction;
|
2021-03-30 18:10:58 +00:00
|
|
|
in
|
|
|
|
|
2021-04-25 23:50:01 +00:00
|
|
|
_: { self, inputs, ... } @ args:
|
2021-03-30 18:10:58 +00:00
|
|
|
let
|
|
|
|
|
2021-04-25 23:50:01 +00:00
|
|
|
config = lib.mkFlake.evalArgs {
|
2021-04-27 04:32:26 +00:00
|
|
|
inherit args;
|
2021-04-25 23:50:01 +00:00
|
|
|
};
|
2021-03-30 18:10:58 +00:00
|
|
|
|
2021-04-25 23:50:01 +00:00
|
|
|
cfg = config.config;
|
2021-03-30 18:10:58 +00:00
|
|
|
|
2021-04-25 23:50:01 +00:00
|
|
|
otherArguments = removeAttrs args (attrNames config.options);
|
2021-03-30 18:10:58 +00:00
|
|
|
|
2021-04-25 23:50:01 +00: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 18:10:58 +00:00
|
|
|
|
2021-04-25 23:50:01 +00: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 18:10:58 +00:00
|
|
|
|
2021-04-25 23:50:01 +00: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 18:10:58 +00:00
|
|
|
|
2021-04-25 23:50:01 +00: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 18:10:58 +00:00
|
|
|
|
2021-04-24 01:13:03 +00:00
|
|
|
deploy.nodes = os.mkNodes deploy self.nixosConfigurations;
|
2021-03-30 18:10:58 +00:00
|
|
|
|
2021-04-26 19:20:16 +00:00
|
|
|
overlays = lib.exporter.overlaysFromChannelsExporter {
|
2021-04-26 19:29:18 +00: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 19:20:16 +00:00
|
|
|
inherit inputs;
|
|
|
|
inherit (self) pkgs;
|
|
|
|
};
|
2021-04-25 23:50:01 +00:00
|
|
|
|
|
|
|
packagesBuilder = lib.builder.packagesFromOverlaysBuilderConstructor self.overlays;
|
|
|
|
|
|
|
|
checksBuilder = channels:
|
|
|
|
lib.pkgs-lib.tests.mkChecks {
|
|
|
|
pkgs = getDefaultChannel channels;
|
2021-04-24 01:13:03 +00:00
|
|
|
inherit (self.deploy) nodes;
|
|
|
|
hosts = self.nixosConfigurations;
|
|
|
|
homes = self.homeConfigurations;
|
2021-04-10 17:59:10 +00:00
|
|
|
};
|
2021-03-30 18:10:58 +00:00
|
|
|
|
2021-04-25 23:50:01 +00:00
|
|
|
devShellBuilder = channels:
|
|
|
|
lib.pkgs-lib.shell {
|
|
|
|
pkgs = getDefaultChannel channels;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
)
|