flake-parts/setups: refactor NixVim integration

This commit is contained in:
Gabriel Arazas 2024-07-22 20:10:17 +08:00
parent 60fe2b8893
commit 64750a7438
No known key found for this signature in database
GPG Key ID: 62104B43D00AA360
4 changed files with 76 additions and 72 deletions

View File

@ -4,7 +4,6 @@
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 = mkHome =
@ -115,21 +114,6 @@ let
home.homeDirectory = lib.mkForce setupConfig.homeDirectory; home.homeDirectory = lib.mkForce setupConfig.homeDirectory;
} }
) )
(lib.mkIf (config.nixvim.instance != null)
({ lib, ... }: {
imports = [
inputs.${config.nixvim.branch}.homeManagerModules.nixvim
];
config.programs.nixvim = { ... }: {
enable = lib.mkDefault true;
imports =
partsConfig.setups.nixvim.configs.${config.nixvim.instance}.modules
++ partsConfig.setups.nixvim.sharedModules
++ config.nixvim.additionalModules;
};
}))
]; ];
nixpkgs.config = cfg.sharedNixpkgsConfig; nixpkgs.config = cfg.sharedNixpkgsConfig;
@ -179,7 +163,6 @@ in
modules = [ modules = [
(import ./shared/nix-conf.nix { inherit inputs; }) (import ./shared/nix-conf.nix { inherit inputs; })
./shared/nixpkgs-options.nix ./shared/nixpkgs-options.nix
./shared/nixvim-instance-options.nix
./shared/config-options.nix ./shared/config-options.nix
configType configType
]; ];

View File

@ -335,22 +335,6 @@ let
} }
)) ))
# Next, we include the chosen NixVim configuration into NixOS.
(lib.mkIf (config.nixvim.instance != null)
(
{ lib, ... }: {
imports = [ inputs.${config.nixvim.branch}.nixosModules.nixvim ];
programs.nixvim = { ... }: {
enable = lib.mkDefault true;
imports =
partsConfig.setups.nixvim.configs.${config.nixvim.instance}.modules
++ partsConfig.setups.nixvim.sharedModules
++ setupConfig.nixvim.additionalModules;
};
}
))
# Then we include the Disko configuration (if there's any). # Then we include the Disko configuration (if there's any).
(lib.mkIf (config.diskoConfigs != [ ]) ( (lib.mkIf (config.diskoConfigs != [ ]) (
let let
@ -413,7 +397,6 @@ in
modules = [ modules = [
(import ./shared/nix-conf.nix { inherit inputs; }) (import ./shared/nix-conf.nix { inherit inputs; })
./shared/config-options.nix ./shared/config-options.nix
./shared/nixvim-instance-options.nix
./shared/home-manager-users.nix ./shared/home-manager-users.nix
./shared/nixpkgs-options.nix ./shared/nixpkgs-options.nix
configType configType

View File

@ -7,6 +7,7 @@
}: }:
let let
partsConfig = config;
cfg = config.setups.nixvim; cfg = config.setups.nixvim;
nixvimModules = ../../nixvim; nixvimModules = ../../nixvim;
@ -106,6 +107,59 @@ let
]; ];
}; };
}; };
nixvimIntegrationModule = { name, config, lib, ... }: {
options.nixvim = {
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 wider-scoped environment.
'';
};
branch = lib.mkOption {
type = lib.types.nonEmptyStr;
default = "nixvim";
example = "nixvim-stable";
description = ''
The branch of NixVim to be used for the module.
::: {.tip}
A rule of thumb for properly setting up NixVim with the wider-scoped
environment is it should match the nixpkgs version of it. For example,
a NixOS system of `nixos-23.11` nixpkgs branch should be paired with a NixVim
branch of `nixos-23.11`.
:::
'';
};
additionalModules = lib.mkOption {
type = with lib.types; listOf raw;
default = [ ];
description = ''
A list of additional NixVim modules to be included.
'';
};
};
config = lib.mkIf (config.nixvim.instance != null) {
modules = [
({ lib, ... }: {
programs.nixvim = { ... }: {
enable = lib.mkDefault true;
imports =
partsConfig.setups.nixvim.configs.${config.nixvim.instance}.modules
++ partsConfig.setups.nixvim.sharedModules
++ config.nixvim.additionalModules;
};
})
];
};
};
in in
{ {
options.setups.nixvim = { options.setups.nixvim = {
@ -141,6 +195,28 @@ in
}; };
}; };
options.setups.nixos.configs = lib.mkOption {
type = with lib.types; attrsOf (submodule [
nixvimIntegrationModule
({ config, lib, ... }: {
config.modules = [
inputs.${config.nixvim.branch}.nixosModules.nixvim
];
})
]);
};
options.setups.home-manager.configs = lib.mkOption {
type = with lib.types; attrsOf (submodule [
nixvimIntegrationModule
({ config, lib, ... }: {
config.modules = [
inputs.${config.nixvim.branch}.homeManagerModules.nixvim
];
})
]);
};
config = lib.mkIf (cfg.configs != { }) { config = lib.mkIf (cfg.configs != { }) {
setups.nixvim.sharedNixpkgsConfig = config.setups.sharedNixpkgsConfig; setups.nixvim.sharedNixpkgsConfig = config.setups.sharedNixpkgsConfig;

View File

@ -1,38 +0,0 @@
{ lib, ... }: {
options.nixvim = {
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 wider-scoped environment.
'';
};
branch = lib.mkOption {
type = lib.types.nonEmptyStr;
default = "nixvim";
example = "nixvim-stable";
description = ''
The branch of NixVim to be used for the module.
::: {.tip}
A rule of thumb for properly setting up NixVim with the wider-scoped
environment is it should match the nixpkgs version of it. For example,
a NixOS system of `nixos-23.11` nixpkgs branch should be paired with a NixVim
branch of `nixos-23.11`.
:::
'';
};
additionalModules = lib.mkOption {
type = with lib.types; listOf raw;
default = [ ];
description = ''
A list of additional NixVim modules to be included.
'';
};
};
}