flake/modules: add options to set default editor to nixos and home-manager modules

This commit is contained in:
raf 2024-04-20 19:00:58 +03:00
parent 4d8dcc7e49
commit 6d681c2c08
No known key found for this signature in database
GPG key ID: 02D1DD3FA08B6B29
2 changed files with 65 additions and 15 deletions

View file

@ -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;
home = {
sessionVariables.EDITOR = mkIf cfg.defaultEditor (lib.mkOverride 900 "nvim");
packages =
[cfg.finalPackage]
++ optionals cfg.enableManpages packages.${pkgs.stdenv.system}.docs-manpages;
};
}
];
}

View file

@ -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;
environment = {
variables.EDITOR = mkIf cfg.defaultEditor (lib.mkOverride 900 "nvim");
systemPackages =
[cfg.finalPackage]
++ optionals cfg.enableManpages packages.${pkgs.stdenv.system}.docs-manpages;
};
}
];
}