From 64750a7438b82cc04a5a21ee857d06868c0e5dca Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Mon, 22 Jul 2024 20:10:17 +0800 Subject: [PATCH] flake-parts/setups: refactor NixVim integration --- modules/flake-parts/setups/home-manager.nix | 17 ----- modules/flake-parts/setups/nixos.nix | 17 ----- modules/flake-parts/setups/nixvim.nix | 76 +++++++++++++++++++ .../setups/shared/nixvim-instance-options.nix | 38 ---------- 4 files changed, 76 insertions(+), 72 deletions(-) delete mode 100644 modules/flake-parts/setups/shared/nixvim-instance-options.nix diff --git a/modules/flake-parts/setups/home-manager.nix b/modules/flake-parts/setups/home-manager.nix index 975041ed..f5c2c06e 100644 --- a/modules/flake-parts/setups/home-manager.nix +++ b/modules/flake-parts/setups/home-manager.nix @@ -4,7 +4,6 @@ let cfg = config.setups.home-manager; homeManagerModules = ../../home-manager; - partsConfig = config; # A thin wrapper around the home-manager configuration function. mkHome = @@ -115,21 +114,6 @@ let 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; @@ -179,7 +163,6 @@ in modules = [ (import ./shared/nix-conf.nix { inherit inputs; }) ./shared/nixpkgs-options.nix - ./shared/nixvim-instance-options.nix ./shared/config-options.nix configType ]; diff --git a/modules/flake-parts/setups/nixos.nix b/modules/flake-parts/setups/nixos.nix index cb57b278..6cf6e735 100644 --- a/modules/flake-parts/setups/nixos.nix +++ b/modules/flake-parts/setups/nixos.nix @@ -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). (lib.mkIf (config.diskoConfigs != [ ]) ( let @@ -413,7 +397,6 @@ in modules = [ (import ./shared/nix-conf.nix { inherit inputs; }) ./shared/config-options.nix - ./shared/nixvim-instance-options.nix ./shared/home-manager-users.nix ./shared/nixpkgs-options.nix configType diff --git a/modules/flake-parts/setups/nixvim.nix b/modules/flake-parts/setups/nixvim.nix index 888b756f..ae4e8b7d 100644 --- a/modules/flake-parts/setups/nixvim.nix +++ b/modules/flake-parts/setups/nixvim.nix @@ -7,6 +7,7 @@ }: let + partsConfig = config; cfg = config.setups.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.` 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 { 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 != { }) { setups.nixvim.sharedNixpkgsConfig = config.setups.sharedNixpkgsConfig; diff --git a/modules/flake-parts/setups/shared/nixvim-instance-options.nix b/modules/flake-parts/setups/shared/nixvim-instance-options.nix deleted file mode 100644 index c2b627a1..00000000 --- a/modules/flake-parts/setups/shared/nixvim-instance-options.nix +++ /dev/null @@ -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.` 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. - ''; - }; - }; -}