summaryrefslogtreecommitdiffstats
path: root/nixos/modules/programs/nushell.nix
blob: a588ef71a71d2d7a42a0f1a161dce66af42599f1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
{
  config,
  lib,
  pkgs,
  ...
}:
let
  cfg = config.programs.nushell;
in
{
  options.programs.nushell = {
    enable = lib.mkEnableOption "nushell";

    package = lib.mkPackageOption pkgs "nushell" { };

    plugins = lib.mkOption {
      type = lib.types.listOf lib.types.package;
      default = [ ];
      example = lib.literalExpression "[ pkgs.nushellPlugins.formats ]";
      description = ''
        List of nushell plugins to install to `lib/nushell/plugins/`.

        Plugins are registered via nushell's vendor autoload on the first
        interactive launch of each user. After registration, plugins persist
        in the user's `plugin.msgpackz` and can be managed at runtime with
        `plugin rm` and `plugin add`.

        See https://www.nushell.sh/book/plugins.html.
      '';
    };

    autoloads = lib.mkOption {
      type = lib.types.listOf lib.types.package;
      default = [ ];
      description = ''
        Vendor autoload scripts to install. The default location is
        `share/nushell/vendor/autoload/<name>.nu`.

        By default, when `programs.nushell.plugins` is non-empty, a
        script that registers the listed plugins via `plugin add` is
        generated here.

        Set this to override the generated script(s).
      '';
    };
  };

  config = lib.mkIf cfg.enable {
    programs.nushell.autoloads = lib.mkDefault (
      lib.optional (cfg.plugins != [ ]) (
        pkgs.writeTextDir "share/nushell/vendor/autoload/50-nixos-plugins.nu" (
          lib.concatLines (map (p: "plugin add ${lib.getExe p}") cfg.plugins)
        )
      )
    );

    environment.systemPackages = [
      cfg.package
    ]
    ++ cfg.plugins
    ++ cfg.autoloads;

    environment.pathsToLink = [ "/share/nushell" ];
  };
}