os/lib/mkFlake/default.nix
Pacman99 c41d3eed06 drop debugging related mkFlakeConfig output
was only meant for debugging, not meant to be commited
2021-04-26 21:32:57 -07:00

91 lines
2.5 KiB
Nix

{ lib, deploy }:
let
inherit (lib) os;
inherit (builtins) mapAttrs attrNames attrValues head isFunction;
in
_: { self, inputs, ... } @ args:
let
config = lib.mkFlake.evalArgs {
inherit args;
};
cfg = config.config;
otherArguments = removeAttrs args (attrNames config.options);
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;
channels = mapAttrs
(name: channel:
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 = {
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;
deploy.nodes = os.mkNodes deploy self.nixosConfigurations;
overlays = lib.exporter.overlaysFromChannelsExporter {
/* 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
*/
inherit inputs;
inherit (self) pkgs;
};
packagesBuilder = lib.builder.packagesFromOverlaysBuilderConstructor self.overlays;
checksBuilder = channels:
lib.pkgs-lib.tests.mkChecks {
pkgs = getDefaultChannel channels;
inherit (self.deploy) nodes;
hosts = self.nixosConfigurations;
homes = self.homeConfigurations;
};
devShellBuilder = channels:
lib.pkgs-lib.shell {
pkgs = getDefaultChannel channels;
};
}
)