CASCADE/common/bash-is-needed.nix

39 lines
1009 B
Nix
Raw Normal View History

2022-09-24 03:24:58 +00:00
{ 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 ''
2022-09-24 03:24:58 +00:00
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) ''
2022-09-24 03:24:58 +00:00
rm -f /bin/bash
'')
];
2022-09-24 03:24:58 +00:00
};
}