aboutsummaryrefslogtreecommitdiff
path: root/nixos.nix
blob: 4dc23c9ca288cdbfa7022cf7ccb352dc7eb7d432 (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
overlays: {
  config,
  lib,
  pkgs,
  ...
}:
with lib; let
  cnf = config.programs.shellrc;
  zshEnable = config.programs.zsh.enable;
in {
  options = {
    programs.shellrc = {
      enable = mkOption {
        type = types.bool;
        default = true;
        description = "If shellrc should be enabled.";
      };
      desktop = mkOption {
        type = types.bool;
        default = false;
        description = "If shellrc's desktop specific files should be used.";
      };
    };
  };

  config = mkMerge [
    {
      nixpkgs.overlays = overlays;

      environment.pathsToLink = ["/etc/shellrc.d" "/etc/bashrc.d"] ++ optional zshEnable "/etc/zshrc.d";
      programs.bash.interactiveShellInit = ''
        # Load files provided by packages
        for p in $NIX_PROFILES; do
          [ -e $p/etc/bashrc.d ] || continue
          for file in $p/etc/bashrc.d/*; do
            [ -f "$file" ] || continue
            . "$file"
          done
        done
      '';
      programs.zsh.interactiveShellInit = mkIf zshEnable ''
        # Load files provided by packages
        for p in ''${=NIX_PROFILES}; do
          [ -e $p/etc/zshrc.d ] || continue
          for file in $p/etc/zshrc.d/*; do
            [ -f "$file" ] || continue
            . "$file"
          done
        done
      '';
    }
    (mkIf cnf.enable {
      environment.systemPackages =
        [pkgs.shellrc-generic pkgs.shellrc-bash]
        ++ optional cnf.desktop pkgs.shellrc-desktop
        ++ optional zshEnable pkgs.shellrc-zsh;

      # Disable default prompt as we have our own
      programs.bash.promptInit = "";
      programs.zsh.promptInit = ""; # Disable default prompt as we have our own
    })
  ];
}