2021-04-19 05:29:28 +02:00
|
|
|
{ lib }:
|
|
|
|
|
|
|
|
{ userFlakeSelf, userFlakeNixOS }:
|
2021-03-26 19:57:24 +01:00
|
|
|
|
|
|
|
{ args }:
|
|
|
|
let
|
2021-04-02 04:10:24 +02:00
|
|
|
argOpts = with lib; { config, ... }:
|
2021-03-26 19:57:24 +01:00
|
|
|
let
|
2021-04-18 03:35:05 +02:00
|
|
|
inherit (lib) os;
|
2021-03-26 19:57:24 +01:00
|
|
|
|
|
|
|
inherit (config) self;
|
|
|
|
|
2021-04-12 05:01:13 +02: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 17:42:22 +02:00
|
|
|
moduleType = with types; pathTo (anything // {
|
2021-04-10 03:22:08 +02:00
|
|
|
inherit (submodule { }) check;
|
2021-03-26 19:57:24 +01:00
|
|
|
description = "valid module";
|
2021-04-12 17:42:22 +02:00
|
|
|
});
|
|
|
|
overlayType = pathTo (types.anything // {
|
2021-04-12 05:01:13 +02:00
|
|
|
check = builtins.isFunction;
|
|
|
|
description = "valid Nixpkgs overlay";
|
2021-04-12 17:42:22 +02:00
|
|
|
});
|
2021-04-12 07:25:37 +02:00
|
|
|
systemType = types.enum config.supportedSystems;
|
2021-04-02 04:10:24 +02:00
|
|
|
flakeType = with types; (addCheck attrs lib.isStorePath) // {
|
2021-04-12 05:01:13 +02:00
|
|
|
description = "nix flake";
|
|
|
|
};
|
|
|
|
|
2021-04-12 17:42:22 +02:00
|
|
|
# Apply maybeImport during merge and before check
|
2021-04-12 05:01:13 +02:00
|
|
|
# To simplify apply keys and improve type checking
|
2021-04-12 17:42:22 +02:00
|
|
|
pathTo = elemType: coercedTo path maybeImort elemType;
|
2021-04-12 05:01:13 +02:00
|
|
|
|
2021-04-12 17:42:22 +02:00
|
|
|
# Accepts single item or a list
|
|
|
|
# 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);
|
2021-04-12 05:01:13 +02:00
|
|
|
|
|
|
|
/* Submodules needed for API containers */
|
|
|
|
|
|
|
|
channelsModule = {
|
|
|
|
options = with types; {
|
|
|
|
input = mkOption {
|
|
|
|
type = flakeType;
|
2021-04-19 05:29:28 +02:00
|
|
|
default = userFlakeNixOS;
|
2021-04-12 05:01:13 +02:00
|
|
|
description = ''
|
|
|
|
nixpkgs flake input to use for this channel
|
2021-04-02 04:10:24 +02:00
|
|
|
'';
|
2021-04-12 05:01:13 +02:00
|
|
|
};
|
|
|
|
overlays = mkOption {
|
2021-04-12 17:42:22 +02:00
|
|
|
type = pathToListOf overlayType;
|
2021-04-12 05:01:13 +02:00
|
|
|
default = [ ];
|
|
|
|
description = ''
|
|
|
|
overlays to apply to this channel
|
|
|
|
these will get exported under the 'overlays' flake output as <channel>/<name>
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
externalOverlays = mkOption {
|
2021-04-12 17:42:22 +02:00
|
|
|
type = pathToListOf overlayType;
|
2021-04-12 05:01:13 +02:00
|
|
|
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 {
|
|
|
|
type = pathTo attrs;
|
|
|
|
default = { };
|
|
|
|
description = ''
|
|
|
|
nixpkgs config for this channel
|
|
|
|
'';
|
2021-03-26 19:57:24 +01:00
|
|
|
};
|
|
|
|
};
|
2021-04-12 05:01:13 +02:00
|
|
|
};
|
|
|
|
|
2021-04-12 07:25:37 +02:00
|
|
|
configModule = {
|
2021-04-12 05:01:13 +02:00
|
|
|
options = with types; {
|
|
|
|
system = mkOption {
|
|
|
|
type = systemType;
|
|
|
|
default = "x86_64-linux";
|
|
|
|
description = ''
|
|
|
|
system for this config
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
channelName = mkOption {
|
2021-04-12 07:25:37 +02:00
|
|
|
type = types.enum (builtins.attrValues config.channels);
|
2021-04-12 05:01:13 +02:00
|
|
|
default = "nixpkgs";
|
|
|
|
description = ''
|
|
|
|
Channel this config should follow
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
modules = mkOption {
|
2021-04-12 17:42:22 +02:00
|
|
|
type = pathToListOf moduleType;
|
2021-04-12 05:01:13 +02:00
|
|
|
default = [ ];
|
|
|
|
description = ''
|
|
|
|
The configuration for this config
|
|
|
|
'';
|
|
|
|
};
|
2021-04-12 17:42:22 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
# This is only needed for configDefaults
|
|
|
|
# modules in each config don't get exported
|
|
|
|
externalModulesModule = {
|
|
|
|
options = {
|
2021-04-12 07:25:37 +02:00
|
|
|
externalModules = mkOption {
|
2021-04-12 17:42:22 +02:00
|
|
|
type = pathToListOf moduleType;
|
2021-04-12 05:01:13 +02:00
|
|
|
default = [ ];
|
|
|
|
description = ''
|
|
|
|
The configuration for this config
|
|
|
|
'';
|
|
|
|
};
|
2021-03-26 19:57:24 +01:00
|
|
|
};
|
2021-04-12 05:01:13 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
# Home-manager's configs get exported automatically from nixos.hosts
|
|
|
|
# So there is no need for a config options in the home namespace
|
|
|
|
# This is only needed for nixos
|
2021-04-12 07:25:37 +02:00
|
|
|
includeConfigsModule = { name, ... }: {
|
2021-04-12 05:01:13 +02:00
|
|
|
options = with types; {
|
|
|
|
configDefaults = mkOption {
|
2021-04-12 17:42:22 +02:00
|
|
|
type = submodule [ configModule externalModulesModule ];
|
2021-04-12 05:01:13 +02:00
|
|
|
default = { };
|
|
|
|
description = ''
|
2021-04-12 17:42:22 +02:00
|
|
|
Defaults for all configs.
|
|
|
|
the modules passed under configDefault will be exported
|
|
|
|
to the '${name}Modules' flake output.
|
|
|
|
They will also be added to all configs.
|
2021-04-12 05:01:13 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
configs = mkOption {
|
2021-04-12 17:42:22 +02:00
|
|
|
type = attrsOf (submodule configModule);
|
2021-04-12 05:01:13 +02:00
|
|
|
default = { };
|
|
|
|
description = ''
|
|
|
|
configurations to include in the ${name}Configurations output
|
|
|
|
'';
|
|
|
|
};
|
2021-03-26 19:57:24 +01:00
|
|
|
};
|
2021-04-12 05:01:13 +02:00
|
|
|
};
|
|
|
|
|
2021-04-12 17:42:22 +02:00
|
|
|
# profiles and suites - which are profile collections
|
|
|
|
profilesModule = { name, ... }: {
|
2021-04-12 05:01:13 +02:00
|
|
|
options = with types; {
|
|
|
|
profiles = mkOption {
|
2021-04-12 17:42:22 +02:00
|
|
|
type = coercedListOf path;
|
|
|
|
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;
|
2021-04-12 05:01:13 +02: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 19:57:24 +01:00
|
|
|
inherit suites;
|
2021-04-12 05:01:13 +02:00
|
|
|
inherit (config) profiles;
|
2021-03-26 19:57:24 +01:00
|
|
|
};
|
|
|
|
description = ''
|
2021-04-12 05:01:13 +02: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 19:57:24 +01:00
|
|
|
'';
|
|
|
|
};
|
2021-04-12 05:01:13 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options = with types; {
|
|
|
|
self = mkOption {
|
|
|
|
type = flakeType;
|
|
|
|
description = "The flake to create the devos outputs for";
|
|
|
|
};
|
|
|
|
supportedSystems = mkOption {
|
|
|
|
type = listOf str;
|
2021-04-18 03:56:24 +02:00
|
|
|
default = lib.defaultSystems;
|
2021-03-26 19:57:24 +01:00
|
|
|
description = ''
|
2021-04-12 05:01:13 +02:00
|
|
|
The systems supported by this flake
|
2021-03-26 19:57:24 +01:00
|
|
|
'';
|
|
|
|
};
|
2021-04-12 05:01:13 +02:00
|
|
|
channels =
|
2021-03-26 19:57:24 +01:00
|
|
|
let
|
2021-04-12 05:01:13 +02:00
|
|
|
default = {
|
|
|
|
nixpkgs = {
|
2021-04-19 05:29:28 +02:00
|
|
|
input = userFlakeNixOS;
|
2021-04-12 05:01:13 +02:00
|
|
|
};
|
2021-03-26 19:57:24 +01:00
|
|
|
};
|
|
|
|
in
|
|
|
|
mkOption {
|
2021-04-12 05:01:13 +02:00
|
|
|
type = attrsOf (submodule channelsModule);
|
|
|
|
inherit default;
|
|
|
|
apply = x: default // x;
|
2021-03-26 19:57:24 +01:00
|
|
|
description = ''
|
2021-04-12 05:01:13 +02:00
|
|
|
nixpkgs channels to create
|
2021-03-26 19:57:24 +01:00
|
|
|
'';
|
|
|
|
};
|
2021-04-12 05:01:13 +02:00
|
|
|
nixos = mkOption {
|
|
|
|
type = submodule [ includeConfigsModule importsModule ];
|
|
|
|
default = { };
|
2021-03-26 19:57:24 +01:00
|
|
|
description = ''
|
2021-04-12 05:01:13 +02:00
|
|
|
hosts, modules, suites, and profiles for nixos
|
2021-03-26 19:57:24 +01:00
|
|
|
'';
|
|
|
|
};
|
2021-04-12 05:01:13 +02:00
|
|
|
home = mkOption {
|
|
|
|
type = submodule importsModule;
|
|
|
|
default = { };
|
|
|
|
description = ''
|
|
|
|
hosts, modules, suites, and profiles for home-manager
|
|
|
|
'';
|
2021-03-26 19:57:24 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
in
|
2021-04-02 04:10:24 +02:00
|
|
|
lib.evalModules {
|
2021-04-10 03:22:08 +02:00
|
|
|
modules = [ argOpts args ];
|
|
|
|
}
|