summaryrefslogtreecommitdiff
path: root/modules/programs/bash.nix
blob: ae8e399c3105f46b9656348c05cc8d2e42b140bf (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
{ config, lib, pkgs, ... }:

with lib;

let

  cfg = config.programs.bash;

  bash = pkgs.runCommand pkgs.zsh.name
    { buildInputs = [ pkgs.makeWrapper ]; }
    ''
      source $stdenv/setup

      mkdir -p $out/bin
      makeWrapper ${pkgs.bash}/bin/bash $out/bin/bash
    '';

in

{
  options = {

    programs.bash.enable = mkOption {
      type = types.bool;
      default = false;
      description = ''
        Whether to configure bash as an interactive shell.
      '';
    };

    programs.bash.shell = mkOption {
      type = types.path;
      default = "${bash}/bin/bash";
      description = ''
        Zsh shell to use.
      '';
    };

    programs.bash.interactiveShellInit = mkOption {
      default = "";
      description = ''
        Shell script code called during interactive bash shell initialisation.
      '';
      type = types.lines;
    };

  };

  config = mkIf cfg.enable {

    environment.systemPackages =
      [ # Include bash package
        pkgs.bash
      ];

    environment.variables.SHELL = "${cfg.shell}";

    environment.etc."bashrc".text = ''
      # /etc/bashrc: DO NOT EDIT -- this file has been generated automatically.
      # This file is read for interactive shells.

      # Only execute this file once per shell.
      if [ -n "$__ETC_BASHRC_SOURCED" -o -n "$NOSYSBASHRC" ]; then return; fi
      __ETC_BASHRC_SOURCED=1

      export PATH=${config.environment.systemPath}''${PATH:+:$PATH}
      ${config.system.build.setEnvironment}
      ${config.system.build.setAliases}

      ${cfg.interactiveShellInit}
      ${config.environment.extraInit}

      # Read system-wide modifications.
      if test -f /etc/bash.local; then
        . /etc/bash.local
      fi
    '';

  };
}