fork/home-manager

git clone https://git.julia.blue/fork/home-manager

Robert HelgessonMerge PR #421575790441

master
2.1 KiB82 linesraw
1{ config, pkgs, lib, ... }:
2
3let
4
5  cfg = config.programs.pyenv;
6
7  tomlFormat = pkgs.formats.toml { };
8
9in {
10  meta.maintainers = with lib.maintainers; [ tmarkus ];
11
12  options.programs.pyenv = {
13    enable = lib.mkEnableOption "pyenv";
14
15    package = lib.mkOption {
16      type = lib.types.package;
17      default = pkgs.pyenv;
18      defaultText = lib.literalExpression "pkgs.pyenv";
19      description = "The package to use for pyenv.";
20    };
21
22    enableBashIntegration = lib.mkOption {
23      type = lib.types.bool;
24      default = true;
25      description = ''
26        Whether to enable pyenv's Bash integration.
27      '';
28    };
29
30    enableZshIntegration = lib.mkOption {
31      type = lib.types.bool;
32      default = true;
33      description = ''
34        Whether to enable pyenv's Zsh integration.
35      '';
36    };
37
38    enableFishIntegration = lib.mkOption {
39      type = lib.types.bool;
40      default = true;
41      description = ''
42        Whether to enable pyenv's Fish integration.
43      '';
44    };
45
46    rootDirectory = lib.mkOption {
47      type = lib.types.path;
48      apply = toString;
49      default = "${config.xdg.dataHome}/pyenv";
50      defaultText = "\${config.xdg.dataHome}/pyenv";
51      description = ''
52        The pyenv root directory ({env}`PYENV_ROOT`).
53
54        ::: {.note}
55        This deviates from upstream, which uses {file}`$HOME/.pyenv`.
56        The default path in Home Manager is set according to the XDG
57        base directory specification.
58        :::
59      '';
60    };
61  };
62
63  config = lib.mkIf cfg.enable {
64    # Always add the configured `pyenv` package.
65    home.packages = [ cfg.package ];
66
67    programs.bash.initExtra = lib.mkIf cfg.enableBashIntegration ''
68      export PYENV_ROOT="${cfg.rootDirectory}"
69      eval "$(${lib.getExe cfg.package} init - bash)"
70    '';
71
72    programs.zsh.initExtra = lib.mkIf cfg.enableZshIntegration ''
73      export PYENV_ROOT="${cfg.rootDirectory}"
74      eval "$(${lib.getExe cfg.package} init - zsh)"
75    '';
76
77    programs.fish.interactiveShellInit = lib.mkIf cfg.enableFishIntegration ''
78      set -Ux PYENV_ROOT "${cfg.rootDirectory}"
79      ${lib.getExe cfg.package} init - fish | source
80    '';
81  };
82}