From 6d681c2c080d4de822ebb6317b99de6f3b3c3df5 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Sat, 20 Apr 2024 19:00:58 +0300 Subject: [PATCH] flake/modules: add options to set default editor to nixos and home-manager modules --- flake/modules/home-manager.nix | 39 ++++++++++++++++++++++++++------ flake/modules/nixos.nix | 41 +++++++++++++++++++++++++++------- 2 files changed, 65 insertions(+), 15 deletions(-) diff --git a/flake/modules/home-manager.nix b/flake/modules/home-manager.nix index 28e2b0f..677a39e 100644 --- a/flake/modules/home-manager.nix +++ b/flake/modules/home-manager.nix @@ -6,9 +6,10 @@ packages: inputs: { ... }: let inherit (lib) maintainers; - inherit (lib.modules) mkIf; + inherit (lib.modules) mkIf mkMerge; + inherit (lib.lists) optionals; inherit (lib.options) mkOption mkEnableOption literalExpression; - inherit (lib.types) attrsOf anything; + inherit (lib.types) attrsOf anything bool; cfg = config.programs.neovim-flake; inherit (import ../../configuration.nix inputs) neovimConfiguration; @@ -21,7 +22,24 @@ in { meta.maintainers = with maintainers; [NotAShelf]; options.programs.neovim-flake = { - enable = mkEnableOption "neovim-flake, the extensible neovim-wrapper"; + enable = mkEnableOption "neovim-flake, the extensible neovim configuration wrapper"; + + enableManpages = mkOption { + type = bool; + default = false; + description = "Whether to enable manpages for neovim-flake."; + }; + + defaultEditor = mkOption { + type = bool; + default = false; + description = '' + Whether to set `neovim-flake` as the default editor. + + This will set the `EDITOR` environment variable as `nvim` + if set to true. + ''; + }; finalPackage = mkOption { type = anything; @@ -56,9 +74,16 @@ in { }; }; - config = mkIf cfg.enable { - home.packages = [cfg.finalPackage]; + config = mkIf cfg.enable mkMerge [ + { + programs.neovim-flake.finalPackage = neovimConfigured.neovim; - programs.neovim-flake.finalPackage = neovimConfigured.neovim; - }; + home = { + sessionVariables.EDITOR = mkIf cfg.defaultEditor (lib.mkOverride 900 "nvim"); + packages = + [cfg.finalPackage] + ++ optionals cfg.enableManpages packages.${pkgs.stdenv.system}.docs-manpages; + }; + } + ]; } diff --git a/flake/modules/nixos.nix b/flake/modules/nixos.nix index 29e97cc..a41e3b6 100644 --- a/flake/modules/nixos.nix +++ b/flake/modules/nixos.nix @@ -1,4 +1,4 @@ -# Home Manager module +# NixOS module packages: inputs: { config, pkgs, @@ -6,9 +6,10 @@ packages: inputs: { ... }: let inherit (lib) maintainers; - inherit (lib.modules) mkIf; + inherit (lib.modules) mkIf mkMerge; + inherit (lib.lists) optionals; inherit (lib.options) mkOption mkEnableOption literalExpression; - inherit (lib.types) attrsOf anything; + inherit (lib.types) attrsOf anything bool; cfg = config.programs.neovim-flake; inherit (import ../../configuration.nix inputs) neovimConfiguration; @@ -21,7 +22,24 @@ in { meta.maintainers = with maintainers; [NotAShelf]; options.programs.neovim-flake = { - enable = mkEnableOption "neovim-flake, the extensible neovim-wrapper"; + enable = mkEnableOption "neovim-flake, the extensible neovim configuration wrapper"; + + enableManpages = mkOption { + type = bool; + default = false; + description = "Whether to enable manpages for neovim-flake."; + }; + + defaultEditor = mkOption { + type = bool; + default = false; + description = '' + Whether to set `neovim-flake` as the default editor. + + This will set the `EDITOR` environment variable as `nvim` + if set to true. + ''; + }; finalPackage = mkOption { type = anything; @@ -56,9 +74,16 @@ in { }; }; - config = mkIf cfg.enable { - environment.systemPackages = [cfg.finalPackage]; + config = mkIf cfg.enable mkMerge [ + { + programs.neovim-flake.finalPackage = neovimConfigured.neovim; - programs.neovim-flake.finalPackage = neovimConfigured.neovim; - }; + environment = { + variables.EDITOR = mkIf cfg.defaultEditor (lib.mkOverride 900 "nvim"); + systemPackages = + [cfg.finalPackage] + ++ optionals cfg.enableManpages packages.${pkgs.stdenv.system}.docs-manpages; + }; + } + ]; }