summary refs log tree commit diff
path: root/pkgs/build-support/usernixos/bashrc.nix
blob: 1860f4b2e89cbe2ee1dc7dc7287ca727cd1a50cd (plain) (blame)
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
# Generator for .bashrc
{pkgs, config, ...}:

with pkgs.lib;

let
  bashrcFile = pkgs.writeScript "bashrc" config.bashrc.contents;
  cfg = config.bashrc;
in
{
  options = {
    environment.editor = mkOption {
      default = "${pkgs.vim}/bin/vim";
      type = types.string;
      description = ''
        Editor
      '';
    };

    bashrc = {
      enable = mkOption {
        default = false;
        type = types.bool;
        description = ''
          Enable of .bashrc generation on activation
        '';
      };

      destination = mkOption {
        default = "~/.bashrc";
        type = types.string;
        description = ''
          The symlink that will point to the generated bashrc at activation time
        '';
      };

      contents = mkOption {
        default = "";
        type = types.string;
        merge = concatStringsSep "\n";
        description = ''
          Enable of .bashrc generation on activation
        '';
      };
    };
  };

  config.bashrc.contents = ''
    export EDITOR="${config.environment.editor}"
  '';

  config.activationContents = mkIf cfg.enable ''
    if [ -e "${cfg.destination}" ]; then
      echo Cannot set "${cfg.destination}", it exists
      exit 1
    fi
    ln -sf ${bashrcFile} "${cfg.destination}"
  '';
}