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 let
cfg = config.setups.home-manager; cfg = config.setups.home-manager;
homeManagerModules = ../../home-manager; homeManagerModules = ../../home-manager;
partsConfig = config;
# A thin wrapper around the home-manager configuration function. # A thin wrapper around the home-manager configuration function.
mkHome = { system, nixpkgsBranch ? "nixpkgs", homeManagerBranch ? "home-manager", extraModules ? [ ] }: mkHome = { system, nixpkgsBranch ? "nixpkgs", homeManagerBranch ? "home-manager", extraModules ? [ ] }:
@ -22,19 +23,9 @@ let
deploySettingsType = { config, lib, username, ... }: { deploySettingsType = { config, lib, username, ... }: {
freeformType = with lib.types; attrsOf anything; freeformType = with lib.types; attrsOf anything;
imports = [ ./shared/deploy-node-type.nix ];
options = { 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 { profiles = lib.mkOption {
type = with lib.types; functionTo (attrsOf anything); type = with lib.types; functionTo (attrsOf anything);
default = homeenv: { default = homeenv: {
@ -71,31 +62,8 @@ let
}; };
}; };
configType = configType = { config, name, lib, ... }: {
let
partsConfig = config;
in
{ config, name, lib, ... }: {
options = { 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 { overlays = lib.mkOption {
type = with lib.types; listOf (functionTo raw); type = with lib.types; listOf (functionTo raw);
default = [ ]; default = [ ];
@ -174,6 +142,17 @@ let
home.homeDirectory = lib.mkForce setupConfig.homeDirectory; 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;
};
}))
]; ];
}; };
}; };
@ -209,7 +188,14 @@ in
}; };
configs = lib.mkOption { 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 = { }; default = { };
description = '' description = ''
An attribute set of metadata for the declarative home-manager setups. An attribute set of metadata for the declarative home-manager setups.

View File

@ -54,19 +54,9 @@ let
deployNodeType = { config, lib, ... }: { deployNodeType = { config, lib, ... }: {
freeformType = with lib.types; attrsOf anything; freeformType = with lib.types; attrsOf anything;
imports = [ ./shared/deploy-node-type.nix ];
options = { 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 { profiles = lib.mkOption {
type = with lib.types; functionTo (attrsOf anything); type = with lib.types; functionTo (attrsOf anything);
default = os: { default = os: {
@ -144,17 +134,6 @@ let
configType = { config, name, lib, ... }: { configType = { config, name, lib, ... }: {
options = { 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 { formats = lib.mkOption {
type = with lib.types; nullOr (listOf str); type = with lib.types; nullOr (listOf str);
default = [ "iso" ]; 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 { overlays = lib.mkOption {
type = with lib.types; listOf (functionTo raw); type = with lib.types; listOf (functionTo raw);
default = [ ]; 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 { deploy = lib.mkOption {
type = with lib.types; nullOr (submodule deployNodeType); type = with lib.types; nullOr (submodule deployNodeType);
default = null; default = null;
@ -499,7 +439,14 @@ in
}; };
configs = lib.mkOption { 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 = { }; default = { };
description = '' description = ''
An attribute set of metadata for the declarative NixOS setups. This An attribute set of metadata for the declarative NixOS setups. This

View File

@ -41,16 +41,6 @@ let
configType = { name, lib, config, ... }: { configType = { name, lib, config, ... }: {
options = { 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 { nixpkgsBranches = lib.mkOption {
type = with lib.types; listOf str; type = with lib.types; listOf str;
description = '' description = ''
@ -62,14 +52,6 @@ let
"nixos-stable" "nixos-stable"
]; ];
}; };
modules = lib.mkOption {
type = with lib.types; listOf raw;
default = [];
description = ''
Additional NixVim modules to use.
'';
};
}; };
config = { config = {
@ -82,7 +64,13 @@ in
{ {
options.setups.nixvim = { options.setups.nixvim = {
configs = lib.mkOption { 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 = {}; default = {};
description = '' description = ''
A set of NixVim configurations to be integrated into the declarative 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.
'';
};
}