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