1
1
Fork 0
nixos/options/custom/programs/sudo.nix
Myned 5a7d93217e
security: separate sudo/polkit into modules
Signed-off-by: Myned <dev@bjork.tech>
2024-12-23 14:45:36 -05:00

40 lines
788 B
Nix

{
config,
lib,
pkgs,
...
}:
with lib; let
cfg = config.custom.programs.sudo;
in {
options.custom.programs.sudo = {
enable = mkOption {default = false;};
bypass = mkOption {default = true;};
confirm = mkOption {default = true;};
};
config = mkIf cfg.enable {
# https://wiki.nixos.org/wiki/Sudo
#?? sudo echo
security.sudo = {
enable = true;
wheelNeedsPassword = !cfg.bypass;
};
environment.shellAliases = mkIf cfg.confirm {
# Interactive confirmation prompt
sudo = pkgs.writeShellScript "sudo" ''
read -p "Execute as root? [Y/n] "
case "$REPLY" in
"" | [Yy])
command sudo "$@"
;;
*)
exit 1
;;
esac
'';
};
};
}