2021-04-19 03:29:28 +00:00
|
|
|
{ lib }:
|
|
|
|
|
2021-04-25 23:52:02 +00:00
|
|
|
{ args }:
|
2021-03-26 18:57:24 +00:00
|
|
|
let
|
2021-04-02 02:10:24 +00:00
|
|
|
argOpts = with lib; { config, ... }:
|
2021-03-26 18:57:24 +00:00
|
|
|
let
|
2021-04-18 01:35:05 +00:00
|
|
|
inherit (lib) os;
|
2021-03-26 18:57:24 +00:00
|
|
|
|
2021-04-25 23:52:02 +00:00
|
|
|
cfg = config;
|
2021-03-26 18:57:24 +00:00
|
|
|
inherit (config) self;
|
|
|
|
|
2021-04-12 03:01:13 +00:00
|
|
|
maybeImport = obj:
|
|
|
|
if (builtins.typeOf obj == "path") || (builtins.typeOf obj == "string") then
|
|
|
|
import obj
|
|
|
|
else
|
|
|
|
obj;
|
|
|
|
|
|
|
|
/* Custom types needed for arguments */
|
|
|
|
|
2021-04-12 15:42:22 +00:00
|
|
|
moduleType = with types; pathTo (anything // {
|
2021-04-10 01:22:08 +00:00
|
|
|
inherit (submodule { }) check;
|
2021-03-26 18:57:24 +00:00
|
|
|
description = "valid module";
|
2021-04-12 15:42:22 +00:00
|
|
|
});
|
|
|
|
overlayType = pathTo (types.anything // {
|
2021-04-12 03:01:13 +00:00
|
|
|
check = builtins.isFunction;
|
|
|
|
description = "valid Nixpkgs overlay";
|
2021-04-12 15:42:22 +00:00
|
|
|
});
|
2021-04-12 05:25:37 +00:00
|
|
|
systemType = types.enum config.supportedSystems;
|
2021-04-02 02:10:24 +00:00
|
|
|
flakeType = with types; (addCheck attrs lib.isStorePath) // {
|
2021-04-12 03:01:13 +00:00
|
|
|
description = "nix flake";
|
|
|
|
};
|
|
|
|
|
2021-04-12 15:42:22 +00:00
|
|
|
# Apply maybeImport during merge and before check
|
2021-04-12 03:01:13 +00:00
|
|
|
# To simplify apply keys and improve type checking
|
2021-04-24 00:59:01 +00:00
|
|
|
pathTo = elemType: with types; coercedTo path maybeImport elemType;
|
2021-04-12 03:01:13 +00:00
|
|
|
|
2021-04-25 23:52:02 +00:00
|
|
|
pathToListOf = elemType: with types; pathTo (listOf elemType);
|
2021-04-12 15:42:22 +00:00
|
|
|
|
2021-04-25 23:52:02 +00:00
|
|
|
coercedListOf = elemType: with types;
|
|
|
|
coercedTo elemType (x: flatten (singleton x)) (listOf elemType);
|
2021-04-12 03:01:13 +00:00
|
|
|
|
|
|
|
/* Submodules needed for API containers */
|
|
|
|
|
2021-04-25 23:52:02 +00:00
|
|
|
channelsModule = { name, ... }: {
|
2021-04-12 03:01:13 +00:00
|
|
|
options = with types; {
|
|
|
|
input = mkOption {
|
|
|
|
type = flakeType;
|
2021-04-25 23:52:02 +00:00
|
|
|
default = cfg.inputs.${name};
|
|
|
|
defaultText = escape [ "<" ">" ] "inputs.<name>";
|
2021-04-12 03:01:13 +00:00
|
|
|
description = ''
|
|
|
|
nixpkgs flake input to use for this channel
|
2021-04-24 01:13:03 +00:00
|
|
|
'';
|
2021-04-12 03:01:13 +00:00
|
|
|
};
|
|
|
|
overlays = mkOption {
|
2021-04-12 15:42:22 +00:00
|
|
|
type = pathToListOf overlayType;
|
2021-04-12 03:01:13 +00:00
|
|
|
default = [ ];
|
2021-04-25 23:52:02 +00:00
|
|
|
description = escape [ "<" ">" ] ''
|
2021-04-12 03:01:13 +00:00
|
|
|
overlays to apply to this channel
|
|
|
|
these will get exported under the 'overlays' flake output as <channel>/<name>
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
config = mkOption {
|
|
|
|
type = pathTo attrs;
|
|
|
|
default = { };
|
2021-04-25 23:52:02 +00:00
|
|
|
apply = lib.recursiveUpdate cfg.channelsConfig;
|
2021-04-12 03:01:13 +00:00
|
|
|
description = ''
|
|
|
|
nixpkgs config for this channel
|
|
|
|
'';
|
2021-03-26 18:57:24 +00:00
|
|
|
};
|
|
|
|
};
|
2021-04-12 03:01:13 +00:00
|
|
|
};
|
|
|
|
|
2021-04-22 02:44:08 +00:00
|
|
|
hostModule = {
|
2021-04-12 03:01:13 +00:00
|
|
|
options = with types; {
|
2021-04-25 23:52:02 +00:00
|
|
|
# anything null in hosts gets filtered out by mkFlake
|
2021-04-12 03:01:13 +00:00
|
|
|
system = mkOption {
|
2021-04-25 23:52:02 +00:00
|
|
|
type = nullOr systemType;
|
|
|
|
default = null;
|
2021-04-12 03:01:13 +00:00
|
|
|
description = ''
|
2021-04-22 02:44:08 +00:00
|
|
|
system for this host
|
2021-04-12 03:01:13 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
channelName = mkOption {
|
2021-04-25 23:52:02 +00:00
|
|
|
type = nullOr (types.enum (builtins.attrNames config.channels));
|
|
|
|
default = null;
|
2021-04-12 03:01:13 +00:00
|
|
|
description = ''
|
2021-04-22 02:44:08 +00:00
|
|
|
Channel this host should follow
|
2021-04-12 03:01:13 +00:00
|
|
|
'';
|
|
|
|
};
|
2021-04-24 00:59:01 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
# This is only needed for hostDefaults
|
|
|
|
# modules in each host don't get exported
|
|
|
|
externalModulesModule = {
|
|
|
|
options = {
|
|
|
|
externalModules = mkOption {
|
2021-04-25 23:52:02 +00:00
|
|
|
type = with types; listOf moduleType;
|
2021-04-12 03:01:13 +00:00
|
|
|
default = [ ];
|
|
|
|
description = ''
|
2021-04-22 02:44:08 +00:00
|
|
|
The configuration for this host
|
2021-04-12 03:01:13 +00:00
|
|
|
'';
|
|
|
|
};
|
2021-04-12 15:42:22 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-04-24 00:59:01 +00:00
|
|
|
modulesModule = {
|
2021-04-12 15:42:22 +00:00
|
|
|
options = {
|
2021-04-24 00:59:01 +00:00
|
|
|
modules = mkOption {
|
2021-04-25 23:52:02 +00:00
|
|
|
type = with types; coercedListOf moduleType;
|
2021-04-12 03:01:13 +00:00
|
|
|
default = [ ];
|
|
|
|
description = ''
|
2021-04-24 00:59:01 +00:00
|
|
|
modules to include
|
2021-04-12 03:01:13 +00:00
|
|
|
'';
|
|
|
|
};
|
2021-03-26 18:57:24 +00:00
|
|
|
};
|
2021-04-12 03:01:13 +00:00
|
|
|
};
|
|
|
|
|
2021-04-25 23:52:02 +00:00
|
|
|
exportModulesModule = name: {
|
|
|
|
options = {
|
|
|
|
modules = mkOption {
|
|
|
|
type = with types; pathToListOf
|
|
|
|
# check if the path evaluates to a proper module
|
|
|
|
# but this must be a path for the export to work
|
|
|
|
(addCheck path (x: moduleType.check (import x)));
|
|
|
|
default = [ ];
|
|
|
|
description = ''
|
|
|
|
modules to include in all hosts and export to ${name}Modules output
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-12 03:01:13 +00:00
|
|
|
# Home-manager's configs get exported automatically from nixos.hosts
|
2021-04-22 02:44:08 +00:00
|
|
|
# So there is no need for a host options in the home namespace
|
2021-04-12 03:01:13 +00:00
|
|
|
# This is only needed for nixos
|
2021-04-25 23:52:02 +00:00
|
|
|
includeHostsModule = name: {
|
2021-04-12 03:01:13 +00:00
|
|
|
options = with types; {
|
2021-04-22 02:44:08 +00:00
|
|
|
hostDefaults = mkOption {
|
2021-04-25 23:52:02 +00:00
|
|
|
type = submodule [
|
|
|
|
hostModule
|
|
|
|
externalModulesModule
|
|
|
|
(exportModulesModule name)
|
|
|
|
];
|
2021-04-12 03:01:13 +00:00
|
|
|
default = { };
|
|
|
|
description = ''
|
2021-04-22 02:44:08 +00:00
|
|
|
Defaults for all hosts.
|
|
|
|
the modules passed under hostDefaults will be exported
|
2021-04-12 15:42:22 +00:00
|
|
|
to the '${name}Modules' flake output.
|
2021-04-22 02:44:08 +00:00
|
|
|
They will also be added to all hosts.
|
2021-04-12 03:01:13 +00:00
|
|
|
'';
|
|
|
|
};
|
2021-04-22 02:44:08 +00:00
|
|
|
hosts = mkOption {
|
2021-04-24 00:59:01 +00:00
|
|
|
type = attrsOf (submodule [ hostModule modulesModule ]);
|
2021-04-12 03:01:13 +00:00
|
|
|
default = { };
|
|
|
|
description = ''
|
|
|
|
configurations to include in the ${name}Configurations output
|
|
|
|
'';
|
|
|
|
};
|
2021-03-26 18:57:24 +00:00
|
|
|
};
|
2021-04-12 03:01:13 +00:00
|
|
|
};
|
|
|
|
|
2021-04-12 15:42:22 +00:00
|
|
|
# profiles and suites - which are profile collections
|
2021-04-25 23:52:02 +00:00
|
|
|
profilesModule = { config, ... }: {
|
2021-04-12 03:01:13 +00:00
|
|
|
options = with types; {
|
|
|
|
profiles = mkOption {
|
2021-04-25 23:52:02 +00:00
|
|
|
type = listOf path;
|
2021-04-12 15:42:22 +00:00
|
|
|
default = [ ];
|
2021-04-12 03:01:13 +00:00
|
|
|
description = "path to profiles folder that can be collected into suites";
|
|
|
|
};
|
|
|
|
suites = mkOption {
|
|
|
|
type = pathTo (functionTo attrs);
|
|
|
|
default = _: { };
|
|
|
|
apply = suites: os.mkSuites {
|
2021-03-26 18:57:24 +00:00
|
|
|
inherit suites;
|
2021-04-12 03:01:13 +00:00
|
|
|
inherit (config) profiles;
|
2021-03-26 18:57:24 +00:00
|
|
|
};
|
|
|
|
description = ''
|
2021-04-12 03:01:13 +00:00
|
|
|
Function with the input of 'profiles' that returns an attribute set
|
|
|
|
with the suites for this config system.
|
|
|
|
These can be accessed through the 'suites' special argument.
|
2021-03-26 18:57:24 +00:00
|
|
|
'';
|
|
|
|
};
|
2021-04-12 03:01:13 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
in
|
|
|
|
{
|
2021-04-27 04:32:26 +00:00
|
|
|
# this does not get propagated to submodules
|
|
|
|
# to allow passing flake outputs directly to mkFlake
|
|
|
|
config._module.check = false;
|
|
|
|
|
2021-04-12 03:01:13 +00:00
|
|
|
options = with types; {
|
|
|
|
self = mkOption {
|
|
|
|
type = flakeType;
|
|
|
|
description = "The flake to create the devos outputs for";
|
|
|
|
};
|
2021-04-25 23:52:02 +00:00
|
|
|
inputs = mkOption {
|
|
|
|
type = attrsOf flakeType;
|
|
|
|
description = ''
|
|
|
|
inputs for this flake
|
|
|
|
used to set channel defaults and create registry
|
|
|
|
'';
|
|
|
|
};
|
2021-04-12 03:01:13 +00:00
|
|
|
supportedSystems = mkOption {
|
|
|
|
type = listOf str;
|
2021-04-18 01:56:24 +00:00
|
|
|
default = lib.defaultSystems;
|
2021-03-26 18:57:24 +00:00
|
|
|
description = ''
|
2021-04-12 03:01:13 +00:00
|
|
|
The systems supported by this flake
|
2021-03-26 18:57:24 +00:00
|
|
|
'';
|
|
|
|
};
|
2021-04-25 23:52:02 +00:00
|
|
|
channelsConfig = mkOption {
|
|
|
|
type = pathTo attrs;
|
|
|
|
default = { };
|
|
|
|
description = ''
|
|
|
|
nixpkgs config for all channels
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
channels = mkOption {
|
|
|
|
type = attrsOf (submodule channelsModule);
|
|
|
|
default = { };
|
|
|
|
description = ''
|
|
|
|
nixpkgs channels to create
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
nixos = mkOption {
|
|
|
|
type = submodule [ (includeHostsModule "nixos") profilesModule ];
|
2021-04-12 03:01:13 +00:00
|
|
|
default = { };
|
2021-03-26 18:57:24 +00:00
|
|
|
description = ''
|
2021-04-12 03:01:13 +00:00
|
|
|
hosts, modules, suites, and profiles for nixos
|
2021-03-26 18:57:24 +00:00
|
|
|
'';
|
|
|
|
};
|
2021-04-12 03:01:13 +00:00
|
|
|
home = mkOption {
|
2021-04-25 23:52:02 +00:00
|
|
|
type = submodule [
|
|
|
|
profilesModule
|
|
|
|
(exportModulesModule "home")
|
|
|
|
externalModulesModule
|
|
|
|
];
|
2021-04-12 03:01:13 +00:00
|
|
|
default = { };
|
|
|
|
description = ''
|
|
|
|
hosts, modules, suites, and profiles for home-manager
|
|
|
|
'';
|
2021-03-26 18:57:24 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
in
|
2021-04-02 02:10:24 +00:00
|
|
|
lib.evalModules {
|
2021-04-10 01:22:08 +00:00
|
|
|
modules = [ argOpts args ];
|
|
|
|
}
|