Skip to content

Instantly share code, notes, and snippets.

@eiel
Last active February 16, 2026 04:11
Show Gist options
  • Select an option

  • Save eiel/187bea21288b3033155709aadca30508 to your computer and use it in GitHub Desktop.

Select an option

Save eiel/187bea21288b3033155709aadca30508 to your computer and use it in GitHub Desktop.
volta用のnixOS module

home.nix や configuration.nix で importして使います。

    imports = [
      ./modules/volta.nix
    ]
  programs.volta = {
    enable = true;
    enablePnpm = true;
  };
{
config,
lib,
pkgs,
...
}:
with lib;
let
cfg = config.programs.volta;
in
{
options.programs.volta = {
enable = mkEnableOption "Volta Node.js version manager";
package = mkOption {
type = types.package;
default = pkgs.volta;
description = "The Volta package to use.";
};
enablePnpm = mkOption {
type = types.bool;
default = true;
description = "Enable pnpm support in Volta.";
};
};
config = mkIf cfg.enable {
home.packages = [ cfg.package ];
home.sessionVariables = mkIf cfg.enablePnpm {
VOLTA_FEATURE_PNPM = "1";
};
programs.fish.loginShellInit = mkIf config.programs.fish.enable ''
# setup Volta
set -gx VOLTA_HOME "$HOME/.volta"
set -gx PATH "$VOLTA_HOME/bin" $PATH
'';
programs.bash.bashrcExtra = mkIf config.programs.bash.enable ''
# setup Volta
export VOLTA_HOME="$HOME/.volta"
export PATH="$VOLTA_HOME/bin:$PATH"
'';
programs.zsh.initExtra = mkIf config.programs.zsh.enable ''
# setup Volta
export VOLTA_HOME="$HOME/.volta"
export PATH="$VOLTA_HOME/bin:$PATH"
'';
programs.emacs.extraConfig = mkIf config.programs.emacs.enable ''
;; setup Volta
(setenv "VOLTA_HOME" (expand-file-name "~/.volta"))
(setenv "PATH" (concat (getenv "VOLTA_HOME") "/bin:" (getenv "PATH")))
${if cfg.enablePnpm then ''(setenv "VOLTA_FEATURE_PNPM" "1")'' else ""}
'';
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment