flake-parts/setups: fix module config scoping

It's getting confusing.
This commit is contained in:
Gabriel Arazas 2024-01-17 21:46:18 +08:00
parent cce282dbcf
commit 521424e7f1
No known key found for this signature in database
GPG Key ID: ADE0C41DAB221FCC
2 changed files with 188 additions and 180 deletions

View File

@ -70,89 +70,93 @@ let
}; };
}; };
configType = { config, name, lib, ... }: { configType =
options = { let
systems = lib.mkOption { partsConfig = config;
type = with lib.types; listOf str; in
default = config.systems; { config, name, lib, ... }: {
defaultText = "config.systems"; options = {
example = [ "x86_64-linux" "aarch64-linux" ]; systems = lib.mkOption {
description = '' type = with lib.types; listOf str;
A list of platforms that the NixOS configuration is supposed to be default = partsConfig.systems;
deployed on. defaultText = "config.systems";
''; example = [ "x86_64-linux" "aarch64-linux" ];
}; description = ''
A list of platforms that the NixOS configuration is supposed to be
deployed on.
'';
};
modules = lib.mkOption { modules = lib.mkOption {
type = with lib.types; listOf raw; type = with lib.types; listOf raw;
default = [ ]; default = [ ];
description = '' description = ''
A list of NixOS modules specific for that host. A list of NixOS modules specific for that host.
''; '';
}; };
overlays = lib.mkOption { overlays = lib.mkOption {
type = with lib.types; listOf (functionTo raw); type = with lib.types; listOf (functionTo raw);
default = [ ]; default = [ ];
example = lib.literalExpression '' example = lib.literalExpression ''
[ [
inputs.neovim-nightly-overlay.overlays.default inputs.neovim-nightly-overlay.overlays.default
inputs.emacs-overlay.overlays.default inputs.emacs-overlay.overlays.default
] ]
''; '';
description = '' description = ''
A list of overlays to be applied for that host. A list of overlays to be applied for that host.
''; '';
}; };
nixpkgsBranch = lib.mkOption { nixpkgsBranch = lib.mkOption {
type = lib.types.str; type = lib.types.str;
default = "nixpkgs"; default = "nixpkgs";
example = "nixos-unstable-small"; example = "nixos-unstable-small";
description = '' description = ''
The nixpkgs branch to be used for evaluating the NixOS configuration. The nixpkgs branch to be used for evaluating the NixOS configuration.
By default, it will use the `nixpkgs` flake input. By default, it will use the `nixpkgs` flake input.
::: {.note} ::: {.note}
This is based from your flake inputs and not somewhere else. If you This is based from your flake inputs and not somewhere else. If you
want to have support for multiple nixpkgs branch, simply add them as want to have support for multiple nixpkgs branch, simply add them as
a flake input. a flake input.
::: :::
''; '';
}; };
homeManagerBranch = lib.mkOption { homeManagerBranch = lib.mkOption {
type = lib.types.str; type = lib.types.str;
default = "home-manager"; default = "home-manager";
example = "home-manager-stable"; example = "home-manager-stable";
description = '' description = ''
The home-manager branch to be used for the NixOS module. By default, The home-manager branch to be used for the NixOS module. By default,
it will use the `home-manager` flake input. it will use the `home-manager` flake input.
''; '';
}; };
homeDirectory = lib.mkOption { homeDirectory = lib.mkOption {
type = lib.types.path; type = lib.types.path;
default = "/home/${name}"; default = "/home/${name}";
example = "/var/home/public-user"; example = "/var/home/public-user";
description = '' description = ''
The home directory of the home-manager user. The home directory of the home-manager user.
''; '';
}; };
deploy = lib.mkOption { deploy = lib.mkOption {
type = with lib.types; nullOr (submoduleWith { type = with lib.types; nullOr (submoduleWith {
specialArgs = { specialArgs = {
username = name; username = name;
}; };
modules = [ deploySettingsType ]; modules = [ deploySettingsType ];
}); });
default = null; default = null;
description = '' description = ''
deploy-rs settings to be passed onto the home-manager configuration deploy-rs settings to be passed onto the home-manager configuration
node. node.
''; '';
}; };
}; };
config = { config = {

View File

@ -99,109 +99,113 @@ let
}; };
}; };
configType = { config, name, lib, ... }: { configType =
options = { let
systems = lib.mkOption { partsConfig = config;
type = with lib.types; listOf str; in
default = config.systems; { config, name, lib, ... }: {
defaultText = "config.systems"; options = {
example = [ "x86_64-linux" "aarch64-linux" ]; systems = lib.mkOption {
description = '' type = with lib.types; listOf str;
A list of platforms that the NixOS configuration is supposed to be default = partsConfig.systems;
deployed on. defaultText = "config.systems";
''; example = [ "x86_64-linux" "aarch64-linux" ];
}; description = ''
A list of platforms that the NixOS configuration is supposed to be
formats = lib.mkOption { deployed on.
type = with lib.types; nullOr (listOf str); '';
default = [ "iso" ]; };
description = ''
The image formats to be generated from nixos-generators. When given formats = lib.mkOption {
as `null`, it is listed as part of `nixosConfigurations` and excluded type = with lib.types; nullOr (listOf str);
from `images` flake output which is often the case for desktop NixOS default = [ "iso" ];
systems. description = ''
''; The image formats to be generated from nixos-generators. When given
}; as `null`, it is listed as part of `nixosConfigurations` and excluded
from `images` flake output which is often the case for desktop NixOS
modules = lib.mkOption { systems.
type = with lib.types; listOf raw; '';
default = [ ]; };
description = ''
A list of NixOS modules specific for that host. modules = lib.mkOption {
''; type = with lib.types; listOf raw;
}; default = [ ];
description = ''
overlays = lib.mkOption { A list of NixOS modules specific for that host.
type = with lib.types; listOf (functionTo raw); '';
default = [ ]; };
example = lib.literalExpression ''
[ overlays = lib.mkOption {
inputs.neovim-nightly-overlay.overlays.default type = with lib.types; listOf (functionTo raw);
inputs.emacs-overlay.overlays.default default = [ ];
] example = lib.literalExpression ''
''; [
description = '' inputs.neovim-nightly-overlay.overlays.default
A list of overlays to be applied for that host. inputs.emacs-overlay.overlays.default
''; ]
}; '';
description = ''
hostname = lib.mkOption { A list of overlays to be applied for that host.
type = lib.types.nonEmptyStr; '';
default = name; };
example = "MyWhatNow";
description = "The hostname of the NixOS configuration."; hostname = lib.mkOption {
}; type = lib.types.nonEmptyStr;
default = name;
domain = lib.mkOption { example = "MyWhatNow";
type = with lib.types; nullOr nonEmptyStr; description = "The hostname of the NixOS configuration.";
default = null; };
example = "work.example.com";
description = "The domain of the NixOS system."; domain = lib.mkOption {
}; type = with lib.types; nullOr nonEmptyStr;
default = null;
nixpkgsBranch = lib.mkOption { example = "work.example.com";
type = lib.types.str; description = "The domain of the NixOS system.";
default = "nixpkgs"; };
description = ''
The nixpkgs branch to be used for evaluating the NixOS configuration. nixpkgsBranch = lib.mkOption {
By default, it will use the `nixpkgs` flake input. type = lib.types.str;
default = "nixpkgs";
::: {.note} description = ''
This is based from your flake inputs and not somewhere else. If you The nixpkgs branch to be used for evaluating the NixOS configuration.
want to have support for multiple nixpkgs branch, simply add them as By default, it will use the `nixpkgs` flake input.
a flake input.
::: ::: {.note}
''; This is based from your flake inputs and not somewhere else. If you
example = "nixos-unstable-small"; want to have support for multiple nixpkgs branch, simply add them as
}; a flake input.
:::
homeManagerBranch = lib.mkOption { '';
type = lib.types.str; example = "nixos-unstable-small";
default = "home-manager"; };
example = "home-manager-stable";
description = '' homeManagerBranch = lib.mkOption {
The home-manager branch to be used for the NixOS module. By default, type = lib.types.str;
it will use the `home-manager` flake input. default = "home-manager";
''; example = "home-manager-stable";
}; description = ''
The home-manager branch to be used for the NixOS module. By default,
deploy = lib.mkOption { it will use the `home-manager` flake input.
type = with lib.types; nullOr (submodule deployNodeType); '';
default = null; };
description = ''
deploy-rs node settings for the resulting NixOS configuration. When deploy = lib.mkOption {
this attribute is given with a non-null value, it will be included in type = with lib.types; nullOr (submodule deployNodeType);
`nixosConfigurations` even if default = null;
{option}`setups.nixos.configs.<config>.formats` is set. description = ''
''; deploy-rs node settings for the resulting NixOS configuration. When
example = { this attribute is given with a non-null value, it will be included in
hostname = "work1.example.com"; `nixosConfigurations` even if
fastConnection = true; {option}`setups.nixos.configs.<config>.formats` is set.
autoRollback = true; '';
magicRollback = true; example = {
remoteBuild = true; hostname = "work1.example.com";
fastConnection = true;
autoRollback = true;
magicRollback = true;
remoteBuild = true;
};
}; };
};
}; };
config = { config = {
@ -213,14 +217,14 @@ let
let let
setupConfig = config; setupConfig = config;
in in
{ lib, ... }: { { config, lib, ... }: {
config = lib.mkMerge [ config = lib.mkMerge [
{ {
nixpkgs.overlays = setupConfig.overlays; nixpkgs.overlays = setupConfig.overlays;
networking.hostName = lib.mkDefault setupConfig.hostname; networking.hostName = lib.mkDefault setupConfig.hostname;
} }
(lib.mkIf (config.domain != null) { (lib.mkIf (setupConfig.domain != null) {
networking.domain = lib.mkForce setupConfig.domain; networking.domain = lib.mkForce setupConfig.domain;
}) })
]; ];