flake-parts/setups: refactor and add NixVim instance for home-manager configs

This commit is contained in:
Gabriel Arazas 2024-01-26 21:12:22 +08:00
parent f5e9d12bb6
commit ed1264c062
No known key found for this signature in database
GPG Key ID: ADE0C41DAB221FCC
6 changed files with 184 additions and 194 deletions

View File

@ -4,6 +4,7 @@
let
cfg = config.setups.home-manager;
homeManagerModules = ../../home-manager;
partsConfig = config;
# A thin wrapper around the home-manager configuration function.
mkHome = { system, nixpkgsBranch ? "nixpkgs", homeManagerBranch ? "home-manager", extraModules ? [ ] }:
@ -22,19 +23,9 @@ let
deploySettingsType = { config, lib, username, ... }: {
freeformType = with lib.types; attrsOf anything;
imports = [ ./shared/deploy-node-type.nix ];
options = {
fastConnection =
lib.mkEnableOption "deploy-rs to assume the target machine is considered fast";
autoRollback =
lib.mkEnableOption "deploy-rs auto-rollback feature" // {
default = true;
};
magicRollback =
lib.mkEnableOption "deploy-rs magic rollback feature" // {
default = true;
};
remoteBuild = lib.mkEnableOption "pass the build process to the remote machine";
profiles = lib.mkOption {
type = with lib.types; functionTo (attrsOf anything);
default = homeenv: {
@ -71,112 +62,100 @@ let
};
};
configType =
let
partsConfig = config;
in
{ config, name, lib, ... }: {
options = {
systems = lib.mkOption {
type = with lib.types; listOf str;
default = partsConfig.systems;
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 {
type = with lib.types; listOf raw;
default = [ ];
description = ''
A list of NixOS modules specific for that host.
'';
};
overlays = lib.mkOption {
type = with lib.types; listOf (functionTo raw);
default = [ ];
example = lib.literalExpression ''
[
inputs.neovim-nightly-overlay.overlays.default
inputs.emacs-overlay.overlays.default
]
'';
description = ''
A list of overlays to be applied for that host.
'';
};
nixpkgsBranch = lib.mkOption {
type = lib.types.str;
default = "nixpkgs";
example = "nixos-unstable-small";
description = ''
The nixpkgs branch to be used for evaluating the NixOS configuration.
By default, it will use the `nixpkgs` flake input.
::: {.note}
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
a flake input.
:::
'';
};
homeManagerBranch = lib.mkOption {
type = lib.types.str;
default = "home-manager";
example = "home-manager-stable";
description = ''
The home-manager branch to be used for the NixOS module. By default,
it will use the `home-manager` flake input.
'';
};
homeDirectory = lib.mkOption {
type = lib.types.path;
default = "/home/${name}";
example = "/var/home/public-user";
description = ''
The home directory of the home-manager user.
'';
};
deploy = lib.mkOption {
type = with lib.types; nullOr (submoduleWith {
specialArgs = {
username = name;
};
modules = [ deploySettingsType ];
});
default = null;
description = ''
deploy-rs settings to be passed onto the home-manager configuration
node.
'';
};
configType = { config, name, lib, ... }: {
options = {
overlays = lib.mkOption {
type = with lib.types; listOf (functionTo raw);
default = [ ];
example = lib.literalExpression ''
[
inputs.neovim-nightly-overlay.overlays.default
inputs.emacs-overlay.overlays.default
]
'';
description = ''
A list of overlays to be applied for that host.
'';
};
config = {
modules = [
../../../configs/home-manager/${name}
nixpkgsBranch = lib.mkOption {
type = lib.types.str;
default = "nixpkgs";
example = "nixos-unstable-small";
description = ''
The nixpkgs branch to be used for evaluating the NixOS configuration.
By default, it will use the `nixpkgs` flake input.
(
let
setupConfig = config;
in
{ config, lib, ... }: {
nixpkgs.overlays = setupConfig.overlays;
home.username = lib.mkForce name;
home.homeDirectory = lib.mkForce setupConfig.homeDirectory;
}
)
];
::: {.note}
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
a flake input.
:::
'';
};
homeManagerBranch = lib.mkOption {
type = lib.types.str;
default = "home-manager";
example = "home-manager-stable";
description = ''
The home-manager branch to be used for the NixOS module. By default,
it will use the `home-manager` flake input.
'';
};
homeDirectory = lib.mkOption {
type = lib.types.path;
default = "/home/${name}";
example = "/var/home/public-user";
description = ''
The home directory of the home-manager user.
'';
};
deploy = lib.mkOption {
type = with lib.types; nullOr (submoduleWith {
specialArgs = {
username = name;
};
modules = [ deploySettingsType ];
});
default = null;
description = ''
deploy-rs settings to be passed onto the home-manager configuration
node.
'';
};
};
config = {
modules = [
../../../configs/home-manager/${name}
(
let
setupConfig = config;
in
{ config, lib, ... }: {
nixpkgs.overlays = setupConfig.overlays;
home.username = lib.mkForce name;
home.homeDirectory = lib.mkForce setupConfig.homeDirectory;
}
)
(lib.mkIf (config.nixvim.instance != null)
({ lib, ... }: {
programs.nixvim = {
enable = true;
imports =
partsConfig.setups.nixvim.configs.${config.nixvim.instance}.modules
++ partsConfig.setups.nixvim.sharedModules
++ config.nixvim.additionalModules;
};
}))
];
};
};
in
{
options.setups.home-manager = {
@ -209,7 +188,14 @@ in
};
configs = lib.mkOption {
type = with lib.types; attrsOf (submodule configType);
type = with lib.types; attrsOf (submoduleWith {
specialArgs = { inherit (config) systems; };
modules = [
./shared/nixvim-instance-options.nix
./shared/config-options.nix
configType
];
});
default = { };
description = ''
An attribute set of metadata for the declarative home-manager setups.

View File

@ -54,19 +54,9 @@ let
deployNodeType = { config, lib, ... }: {
freeformType = with lib.types; attrsOf anything;
imports = [ ./shared/deploy-node-type.nix ];
options = {
fastConnection =
lib.mkEnableOption "deploy-rs to assume the target machine is considered fast";
autoRollback =
lib.mkEnableOption "deploy-rs auto-rollback feature" // {
default = true;
};
magicRollback =
lib.mkEnableOption "deploy-rs magic rollback feature" // {
default = true;
};
remoteBuild = lib.mkEnableOption "pass the build process to the remote machine";
profiles = lib.mkOption {
type = with lib.types; functionTo (attrsOf anything);
default = os: {
@ -144,17 +134,6 @@ let
configType = { config, name, lib, ... }: {
options = {
systems = lib.mkOption {
type = with lib.types; listOf str;
default = partsConfig.systems;
defaultText = "config.systems";
example = [ "x86_64-linux" "aarch64-linux" ];
description = ''
A list of platforms that the NixOS configuration is supposed to be
deployed on.
'';
};
formats = lib.mkOption {
type = with lib.types; nullOr (listOf str);
default = [ "iso" ];
@ -166,14 +145,6 @@ let
'';
};
modules = lib.mkOption {
type = with lib.types; listOf raw;
default = [ ];
description = ''
A list of NixOS modules specific for that host.
'';
};
overlays = lib.mkOption {
type = with lib.types; listOf (functionTo raw);
default = [ ];
@ -305,37 +276,6 @@ let
'';
};
nixvim = lib.mkOption {
type = lib.types.submodule {
options = {
instance = lib.mkOption {
type = with lib.types; nullOr str;
default = null;
example = "fiesta";
description = ''
The name of the NixVim configuration from
{option}`setups.nixvim.configs.<name>` to be included as part
of the NixOS system.
'';
};
additionalModules = lib.mkOption {
type = with lib.types; listOf raw;
default = [ ];
description = ''
A list of additional NixVim modules to be included.
'';
};
};
};
default = { };
description = ''
An optional NixVim inclusion for the NixOS system. Take note, this
will override whatever Neovim configuration from your NixOS system so
be sure to only use this if you have none.
'';
};
deploy = lib.mkOption {
type = with lib.types; nullOr (submodule deployNodeType);
default = null;
@ -499,7 +439,14 @@ in
};
configs = lib.mkOption {
type = with lib.types; attrsOf (submodule configType);
type = with lib.types; attrsOf (submoduleWith {
specialArgs = { inherit (config) systems; };
modules = [
./shared/config-options.nix
./shared/nixvim-instance-options.nix
configType
];
});
default = { };
description = ''
An attribute set of metadata for the declarative NixOS setups. This

View File

@ -41,16 +41,6 @@ let
configType = { name, lib, config, ... }: {
options = {
systems = lib.mkOption {
type = with lib.types; listOf str;
default = partsConfig.systems;
defaultText = "config.systems";
example = [ "x86_64-linux" "aarch64-linux" ];
description = ''
A list of systems the NixVim configuration will be built against.
'';
};
nixpkgsBranches = lib.mkOption {
type = with lib.types; listOf str;
description = ''
@ -62,14 +52,6 @@ let
"nixos-stable"
];
};
modules = lib.mkOption {
type = with lib.types; listOf raw;
default = [];
description = ''
Additional NixVim modules to use.
'';
};
};
config = {
@ -82,7 +64,13 @@ in
{
options.setups.nixvim = {
configs = lib.mkOption {
type = with lib.types; attrsOf (submodule configType);
type = with lib.types; attrsOf (submoduleWith {
specialArgs = { inherit (config) systems; };
modules = [
./shared/config-options.nix
configType
];
});
default = {};
description = ''
A set of NixVim configurations to be integrated into the declarative

View File

@ -0,0 +1,22 @@
{ lib, systems, ... }: {
options = {
systems = lib.mkOption {
type = with lib.types; listOf str;
default = systems;
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 {
type = with lib.types; listOf raw;
default = [ ];
description = ''
A list of NixOS modules specific for that host.
'';
};
};
}

View File

@ -0,0 +1,15 @@
{ lib, ... }: {
options = {
fastConnection =
lib.mkEnableOption "deploy-rs to assume the target machine is considered fast";
autoRollback =
lib.mkEnableOption "deploy-rs auto-rollback feature" // {
default = true;
};
magicRollback =
lib.mkEnableOption "deploy-rs magic rollback feature" // {
default = true;
};
remoteBuild = lib.mkEnableOption "pass the build process to the remote machine";
};
}

View File

@ -0,0 +1,32 @@
{ lib, ... }: {
options.nixvim = lib.mkOption {
type = lib.types.submodule {
options = {
instance = lib.mkOption {
type = with lib.types; nullOr str;
default = null;
example = "fiesta";
description = ''
The name of the NixVim configuration from
{option}`setups.nixvim.configs.<name>` to be included as part
of the NixOS system.
'';
};
additionalModules = lib.mkOption {
type = with lib.types; listOf raw;
default = [ ];
description = ''
A list of additional NixVim modules to be included.
'';
};
};
};
default = { };
description = ''
An optional NixVim inclusion for the environment. Take note, this
will override whatever Neovim configuration from your environment so
be sure to only use this if you have none.
'';
};
}