evalArgs: general api improvements

drop default channel, it is confusing and complicates api
don't take nixos input, using channels is better
manually pass names for outputs to improve documentation
This commit is contained in:
Pacman99 2021-04-25 16:52:02 -07:00
parent 3bb26330b4
commit f8315a293c

View File

@ -1,11 +1,12 @@
{ lib }: { lib }:
{ nixos, args }: { args }:
let let
argOpts = with lib; { config, ... }: argOpts = with lib; { config, ... }:
let let
inherit (lib) os; inherit (lib) os;
cfg = config;
inherit (config) self; inherit (config) self;
maybeImport = obj: maybeImport = obj:
@ -33,23 +34,19 @@ let
# To simplify apply keys and improve type checking # To simplify apply keys and improve type checking
pathTo = elemType: with types; coercedTo path maybeImport elemType; pathTo = elemType: with types; coercedTo path maybeImport elemType;
# Accepts single item or a list pathToListOf = elemType: with types; pathTo (listOf elemType);
# apply keys end up with a list
# This should not be used if expecting a nested list
# all lists will get flattened by this
coercedListOf = elemType:
let coerceToList = x: flatten (singleton x); in
with types; coercedTo elemType coerceToList (listOf elemType);
pathToListOf = x: pathTo (coercedListOf x); coercedListOf = elemType: with types;
coercedTo elemType (x: flatten (singleton x)) (listOf elemType);
/* Submodules needed for API containers */ /* Submodules needed for API containers */
channelsModule = { channelsModule = { name, ... }: {
options = with types; { options = with types; {
input = mkOption { input = mkOption {
type = flakeType; type = flakeType;
default = nixos; default = cfg.inputs.${name};
defaultText = escape [ "<" ">" ] "inputs.<name>";
description = '' description = ''
nixpkgs flake input to use for this channel nixpkgs flake input to use for this channel
''; '';
@ -57,22 +54,15 @@ let
overlays = mkOption { overlays = mkOption {
type = pathToListOf overlayType; type = pathToListOf overlayType;
default = [ ]; default = [ ];
description = '' description = escape [ "<" ">" ] ''
overlays to apply to this channel overlays to apply to this channel
these will get exported under the 'overlays' flake output as <channel>/<name> these will get exported under the 'overlays' flake output as <channel>/<name>
''; '';
}; };
externalOverlays = mkOption {
type = pathToListOf overlayType;
default = [ ];
description = ''
overlays to apply to the channel that don't get exported to the flake output
useful to include overlays from inputs
'';
};
config = mkOption { config = mkOption {
type = pathTo attrs; type = pathTo attrs;
default = { }; default = { };
apply = lib.recursiveUpdate cfg.channelsConfig;
description = '' description = ''
nixpkgs config for this channel nixpkgs config for this channel
''; '';
@ -82,21 +72,21 @@ let
hostModule = { hostModule = {
options = with types; { options = with types; {
# anything null in hosts gets filtered out by mkFlake
system = mkOption { system = mkOption {
type = systemType; type = nullOr systemType;
default = "x86_64-linux"; default = null;
description = '' description = ''
system for this host system for this host
''; '';
}; };
channelName = mkOption { channelName = mkOption {
type = types.enum (builtins.attrValues config.channels); type = nullOr (types.enum (builtins.attrNames config.channels));
default = "nixpkgs"; default = null;
description = '' description = ''
Channel this host should follow Channel this host should follow
''; '';
}; };
}; };
}; };
@ -105,7 +95,7 @@ let
externalModulesModule = { externalModulesModule = {
options = { options = {
externalModules = mkOption { externalModules = mkOption {
type = pathToListOf moduleType; type = with types; listOf moduleType;
default = [ ]; default = [ ];
description = '' description = ''
The configuration for this host The configuration for this host
@ -117,7 +107,7 @@ let
modulesModule = { modulesModule = {
options = { options = {
modules = mkOption { modules = mkOption {
type = pathToListOf moduleType; type = with types; coercedListOf moduleType;
default = [ ]; default = [ ];
description = '' description = ''
modules to include modules to include
@ -126,13 +116,34 @@ let
}; };
}; };
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
'';
};
};
};
# Home-manager's configs get exported automatically from nixos.hosts # Home-manager's configs get exported automatically from nixos.hosts
# So there is no need for a host options in the home namespace # So there is no need for a host options in the home namespace
# This is only needed for nixos # This is only needed for nixos
includeHostsModule = { name, ... }: { includeHostsModule = name: {
options = with types; { options = with types; {
hostDefaults = mkOption { hostDefaults = mkOption {
type = submodule [ hostModule externalModulesModule modulesModule ]; type = submodule [
hostModule
externalModulesModule
(exportModulesModule name)
];
default = { }; default = { };
description = '' description = ''
Defaults for all hosts. Defaults for all hosts.
@ -152,15 +163,11 @@ let
}; };
# profiles and suites - which are profile collections # profiles and suites - which are profile collections
profilesModule = { name, ... }: { profilesModule = { config, ... }: {
options = with types; { options = with types; {
profiles = mkOption { profiles = mkOption {
type = coercedListOf path; type = listOf path;
default = [ ]; default = [ ];
apply = list:
# Merge a list of profiles to one set
let profileList = map (x: os.mkProfileAttrs (toString x)) list; in
foldl (a: b: a // b) { } profileList;
description = "path to profiles folder that can be collected into suites"; description = "path to profiles folder that can be collected into suites";
}; };
suites = mkOption { suites = mkOption {
@ -185,6 +192,13 @@ let
type = flakeType; type = flakeType;
description = "The flake to create the devos outputs for"; description = "The flake to create the devos outputs for";
}; };
inputs = mkOption {
type = attrsOf flakeType;
description = ''
inputs for this flake
used to set channel defaults and create registry
'';
};
supportedSystems = mkOption { supportedSystems = mkOption {
type = listOf str; type = listOf str;
default = lib.defaultSystems; default = lib.defaultSystems;
@ -192,31 +206,33 @@ let
The systems supported by this flake The systems supported by this flake
''; '';
}; };
channels = channelsConfig = mkOption {
let type = pathTo attrs;
default = { default = { };
nixpkgs = { description = ''
input = nixos; nixpkgs config for all channels
}; '';
}; };
in channels = mkOption {
mkOption { type = attrsOf (submodule channelsModule);
type = attrsOf (submodule channelsModule); default = { };
inherit default; description = ''
apply = x: default // x; nixpkgs channels to create
description = '' '';
nixpkgs channels to create };
''; nixos = mkOption {
}; type = submodule [ (includeHostsModule "nixos") profilesModule ];
os = mkOption {
type = submodule [ includeHostsModule profilesModule ];
default = { }; default = { };
description = '' description = ''
hosts, modules, suites, and profiles for nixos hosts, modules, suites, and profiles for nixos
''; '';
}; };
home = mkOption { home = mkOption {
type = submodule [ profilesModule modulesModule ]; type = submodule [
profilesModule
(exportModulesModule "home")
externalModulesModule
];
default = { }; default = { };
description = '' description = ''
hosts, modules, suites, and profiles for home-manager hosts, modules, suites, and profiles for home-manager