···
then [ "${name} ${value}" ]
else concatLists (mapAttrsToList (genSection name) value);
+
if config.security.sudo.enable then "sudo"
+
else if config.security.doas.enable then "doas"
+
else throw "The btrbk nixos module needs either sudo or doas enabled in the configuration";
+
addDefaults = settings: { backend = "btrfs-progs-${sudo_doas}"; } // settings;
mkConfigFile = name: settings: pkgs.writeTextFile {
name = "btrbk-${name}.conf";
···
config = mkIf (sshEnabled || serviceEnabled) {
environment.systemPackages = [ pkgs.btrbk ] ++ cfg.extraPackages;
+
security.sudo = mkIf (sudo_doas == "sudo") {
+
{ command = "${pkgs.btrfs-progs}/bin/btrfs"; options = [ "NOPASSWD" ]; }
+
{ command = "${pkgs.coreutils}/bin/mkdir"; options = [ "NOPASSWD" ]; }
+
{ command = "${pkgs.coreutils}/bin/readlink"; options = [ "NOPASSWD" ]; }
+
# for ssh, they are not the same than the one hard coded in ${pkgs.btrbk}
+
{ command = "/run/current-system/bin/btrfs"; options = [ "NOPASSWD" ]; }
+
{ command = "/run/current-system/sw/bin/mkdir"; options = [ "NOPASSWD" ]; }
+
{ command = "/run/current-system/sw/bin/readlink"; options = [ "NOPASSWD" ]; }
+
security.doas = mkIf (sudo_doas == "doas") {
+
doasCmdNoPass = cmd: { users = [ "btrbk" ]; cmd = cmd; noPass = true; };
+
(doasCmdNoPass "${pkgs.btrfs-progs}/bin/btrfs")
+
(doasCmdNoPass "${pkgs.coreutils}/bin/mkdir")
+
(doasCmdNoPass "${pkgs.coreutils}/bin/readlink")
+
# for ssh, they are not the same than the one hard coded in ${pkgs.btrbk}
+
(doasCmdNoPass "/run/current-system/bin/btrfs")
+
(doasCmdNoPass "/run/current-system/sw/bin/mkdir")
+
(doasCmdNoPass "/run/current-system/sw/bin/readlink")
+
# doas matches command, not binary
+
(doasCmdNoPass "btrfs")
+
(doasCmdNoPass "mkdir")
+
(doasCmdNoPass "readlink")
# ssh needs a home directory
···
}.${cfg.ioSchedulingClass};
+
sudo_doas_flag = "--${sudo_doas}";
+
''command="${pkgs.util-linux}/bin/ionice -t -c ${toString ioniceClass} ${optionalString (cfg.niceness >= 1) "${pkgs.coreutils}/bin/nice -n ${toString cfg.niceness}"} ${pkgs.btrbk}/share/btrbk/scripts/ssh_filter_btrbk.sh ${sudo_doas_flag} ${options}" ${v.key}''