CASCADE/common/bash-is-needed.nix

39 lines
1009 B
Nix

{ config, lib, pkgs, ... }:
with lib;
{
options = {
environment.binbash.enable = mkOption {
default = true;
type = types.bool;
description = ''
Include a /bin/bash in the system.
'';
};
environment.binbash.bash = mkOption {
type = types.package;
default = pkgs.bashInteractive;
defaultText = literalExpression "pkgs.bashInteractive";
example = literalExpression "pkgs.bash";
description = lib.mdDoc ''
The bash implementation that will be present in
`/bin/bash` after enabling this option.
'';
};
};
config = {
system.activationScripts.binbash = mkMerge [
(mkIf config.environment.binbash.enable ''
mkdir -m 0755 -p /bin
ln -sfn ${config.environment.binbash.bash}/bin/bash /bin/.bash.tmp
mv /bin/.bash.tmp /bin/bash # atomically replace
'')
(mkIf (! config.environment.binbash.enable) ''
rm -f /bin/bash
'')
];
};
}