From 1c6f3054ca36466a45972bf163fa934c33d69a15 Mon Sep 17 00:00:00 2001 From: Mario Rodas Date: Tue, 17 Jan 2023 04:20:00 +0000 Subject: [PATCH] rbenv: add module --- .github/CODEOWNERS | 2 + modules/misc/news.nix | 7 +++ modules/modules.nix | 1 + modules/programs/rbenv.nix | 93 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 103 insertions(+) create mode 100644 modules/programs/rbenv.nix diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index e2668548..375be75a 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -276,6 +276,8 @@ Makefile @thiagokokada /modules/programs/pylint.nix @florpe +/modules/programs/rbenv.nix @marsam + /modules/programs/rbw.nix @ambroisie /tests/modules/programs/rbw @ambroisie diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 950ad289..12d83bd4 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -900,6 +900,13 @@ in A new module is available: 'programs.wlogout'. ''; } + + { + time = "2023-01-31T22:08:41+00:00"; + message = '' + A new module is available: 'programs.rbenv'. + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index b5056417..7bd4a49b 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -189,6 +189,7 @@ let ./programs/vscode.nix ./programs/vscode/haskell.nix ./programs/pywal.nix + ./programs/rbenv.nix ./programs/watson.nix ./programs/waybar.nix ./programs/wezterm.nix diff --git a/modules/programs/rbenv.nix b/modules/programs/rbenv.nix new file mode 100644 index 00000000..b204d4f0 --- /dev/null +++ b/modules/programs/rbenv.nix @@ -0,0 +1,93 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + + cfg = config.programs.rbenv; + + pluginModule = types.submodule { + options = { + src = mkOption { + type = types.path; + description = '' + Path to the plugin folder. + ''; + }; + name = mkOption { + type = types.str; + description = '' + Name of the plugin. + ''; + }; + }; + }; + +in { + meta.maintainers = [ maintainers.marsam ]; + + options.programs.rbenv = { + enable = mkEnableOption "rbenv"; + + package = mkPackageOption pkgs "rbenv" { }; + + plugins = mkOption { + type = types.listOf pluginModule; + default = [ ]; + example = literalExpression '' + [ + { + name = "ruby-build"; + src = pkgs.fetchFromGitHub { + owner = "rbenv"; + repo = "ruby-build"; + rev = "v20221225"; + hash = "sha256-Kuq0Z1kh2mvq7rHEgwVG9XwzR5ZUtU/h8SQ7W4/mBU0="; + }; + } + ] + ''; + description = '' + rbenv plugins to install in $HOME/.rbenv/plugins/. + + See + for the full list of plugins. + ''; + }; + + enableBashIntegration = mkEnableOption "Bash integration" // { + default = true; + }; + + enableZshIntegration = mkEnableOption "Zsh integration" // { + default = true; + }; + + enableFishIntegration = mkEnableOption "Fish integration" // { + default = true; + }; + }; + + config = mkIf cfg.enable { + home.packages = [ cfg.package ]; + + home.file.".rbenv/plugins" = mkIf (cfg.plugins != [ ]) { + source = pkgs.linkFarm "rbenv-plugins" (builtins.map (p: { + name = p.name; + path = p.src; + }) cfg.plugins); + }; + + programs.bash.initExtra = mkIf cfg.enableBashIntegration '' + eval "$(${cfg.package}/bin/rbenv init - bash)" + ''; + + programs.zsh.initExtra = mkIf cfg.enableZshIntegration '' + eval "$(${cfg.package}/bin/rbenv init - zsh)" + ''; + + programs.fish.shellInit = mkIf cfg.enableFishIntegration '' + ${cfg.package}/bin/rbenv init - fish | source + ''; + }; +}