mirror of
https://github.com/SebastianStork/nixos-config.git
synced 2026-01-21 18:41:34 +01:00
Integrate suspend-service into restic module
This commit is contained in:
parent
cdeabbcc84
commit
b5e7d9dce2
5 changed files with 43 additions and 91 deletions
|
|
@ -11,30 +11,10 @@ in
|
||||||
options.custom.services.actualbudget.backups.enable = lib.mkEnableOption "";
|
options.custom.services.actualbudget.backups.enable = lib.mkEnableOption "";
|
||||||
|
|
||||||
config = lib.mkIf config.custom.services.actualbudget.backups.enable {
|
config = lib.mkIf config.custom.services.actualbudget.backups.enable {
|
||||||
security.polkit = {
|
|
||||||
enable = true;
|
|
||||||
extraConfig =
|
|
||||||
let
|
|
||||||
service = "actual.service";
|
|
||||||
in
|
|
||||||
''
|
|
||||||
polkit.addRule(function(action, subject) {
|
|
||||||
if (action.id == "org.freedesktop.systemd1.manage-units" &&
|
|
||||||
action.lookup("unit") == "${service}" &&
|
|
||||||
subject.user == "${user}") {
|
|
||||||
return polkit.Result.YES;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
custom.services.resticBackups.actual = {
|
custom.services.resticBackups.actual = {
|
||||||
inherit user;
|
inherit user;
|
||||||
extraConfig = {
|
suspendService = "actual.service";
|
||||||
backupPrepareCommand = "${lib.getExe' pkgs.systemd "systemctl"} stop actual.service";
|
extraConfig.paths = [ config.services.actual.settings.dataDir ];
|
||||||
backupCleanupCommand = "${lib.getExe' pkgs.systemd "systemctl"} start actual.service";
|
|
||||||
paths = [ config.services.actual.settings.dataDir ];
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
environment.systemPackages = [
|
environment.systemPackages = [
|
||||||
|
|
|
||||||
|
|
@ -11,30 +11,10 @@ in
|
||||||
options.custom.services.forgejo.backups.enable = lib.mkEnableOption "";
|
options.custom.services.forgejo.backups.enable = lib.mkEnableOption "";
|
||||||
|
|
||||||
config = lib.mkIf config.custom.services.forgejo.backups.enable {
|
config = lib.mkIf config.custom.services.forgejo.backups.enable {
|
||||||
security.polkit = {
|
|
||||||
enable = true;
|
|
||||||
extraConfig =
|
|
||||||
let
|
|
||||||
service = "forgejo.service";
|
|
||||||
in
|
|
||||||
''
|
|
||||||
polkit.addRule(function(action, subject) {
|
|
||||||
if (action.id == "org.freedesktop.systemd1.manage-units" &&
|
|
||||||
action.lookup("unit") == "${service}" &&
|
|
||||||
subject.user == "${user}") {
|
|
||||||
return polkit.Result.YES;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
custom.services.resticBackups.forgejo = {
|
custom.services.resticBackups.forgejo = {
|
||||||
inherit user;
|
inherit user;
|
||||||
extraConfig = {
|
suspendService = "forgejo.service";
|
||||||
backupPrepareCommand = "${lib.getExe' pkgs.systemd "systemctl"} stop forgejo.service";
|
extraConfig.paths = [ config.services.forgejo.stateDir ];
|
||||||
backupCleanupCommand = "${lib.getExe' pkgs.systemd "systemctl"} start forgejo.service";
|
|
||||||
paths = [ config.services.forgejo.stateDir ];
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
environment.systemPackages = [
|
environment.systemPackages = [
|
||||||
|
|
|
||||||
|
|
@ -11,34 +11,14 @@ in
|
||||||
options.custom.services.hedgedoc.backups.enable = lib.mkEnableOption "";
|
options.custom.services.hedgedoc.backups.enable = lib.mkEnableOption "";
|
||||||
|
|
||||||
config = lib.mkIf config.custom.services.hedgedoc.backups.enable {
|
config = lib.mkIf config.custom.services.hedgedoc.backups.enable {
|
||||||
security.polkit = {
|
|
||||||
enable = true;
|
|
||||||
extraConfig =
|
|
||||||
let
|
|
||||||
service = "hedgedoc.service";
|
|
||||||
in
|
|
||||||
''
|
|
||||||
polkit.addRule(function(action, subject) {
|
|
||||||
if (action.id == "org.freedesktop.systemd1.manage-units" &&
|
|
||||||
action.lookup("unit") == "${service}" &&
|
|
||||||
subject.user == "${user}") {
|
|
||||||
return polkit.Result.YES;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
custom.services.resticBackups.hedgedoc = {
|
custom.services.resticBackups.hedgedoc = {
|
||||||
inherit user;
|
inherit user;
|
||||||
extraConfig = {
|
suspendService = "hedgedoc.service";
|
||||||
backupPrepareCommand = "${lib.getExe' pkgs.systemd "systemctl"} stop hedgedoc.service";
|
extraConfig.paths = with config.services.hedgedoc.settings; [
|
||||||
backupCleanupCommand = "${lib.getExe' pkgs.systemd "systemctl"} start hedgedoc.service";
|
|
||||||
paths = with config.services.hedgedoc.settings; [
|
|
||||||
uploadsPath
|
uploadsPath
|
||||||
db.storage
|
db.storage
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
};
|
|
||||||
|
|
||||||
environment.systemPackages = [
|
environment.systemPackages = [
|
||||||
(pkgs.writeShellApplication {
|
(pkgs.writeShellApplication {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
{
|
{
|
||||||
config,
|
config,
|
||||||
|
pkgs,
|
||||||
lib,
|
lib,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
|
|
@ -20,6 +21,10 @@ in
|
||||||
type = lib.types.str;
|
type = lib.types.str;
|
||||||
default = config.users.users.root.name;
|
default = config.users.users.root.name;
|
||||||
};
|
};
|
||||||
|
suspendService = lib.mkOption {
|
||||||
|
type = lib.types.nullOr lib.types.nonEmptyStr;
|
||||||
|
default = null;
|
||||||
|
};
|
||||||
extraConfig = lib.mkOption {
|
extraConfig = lib.mkOption {
|
||||||
type = lib.types.attrsOf lib.types.anything;
|
type = lib.types.attrsOf lib.types.anything;
|
||||||
default = { };
|
default = { };
|
||||||
|
|
@ -52,6 +57,27 @@ in
|
||||||
"restic/password" = resticPermissions;
|
"restic/password" = resticPermissions;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
security.polkit = {
|
||||||
|
enable = resticBackups |> lib.attrValues |> lib.any (value: value.suspendService != null);
|
||||||
|
extraConfig =
|
||||||
|
let
|
||||||
|
mkAllowRule = service: user: ''
|
||||||
|
polkit.addRule(function(action, subject) {
|
||||||
|
if (action.id == "org.freedesktop.systemd1.manage-units" &&
|
||||||
|
action.lookup("unit") == "${service}" &&
|
||||||
|
subject.user == "${user}") {
|
||||||
|
return polkit.Result.YES;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
'';
|
||||||
|
in
|
||||||
|
resticBackups
|
||||||
|
|> lib.attrValues
|
||||||
|
|> lib.filter (value: value.suspendService != null)
|
||||||
|
|> lib.map (value: mkAllowRule value.suspendService value.user)
|
||||||
|
|> lib.concatLines;
|
||||||
|
};
|
||||||
|
|
||||||
services.restic.backups =
|
services.restic.backups =
|
||||||
resticBackups
|
resticBackups
|
||||||
|> lib.mapAttrs (
|
|> lib.mapAttrs (
|
||||||
|
|
@ -63,6 +89,12 @@ in
|
||||||
repository = "s3:https://s3.eu-central-003.backblazeb2.com/stork-atlas/${name}";
|
repository = "s3:https://s3.eu-central-003.backblazeb2.com/stork-atlas/${name}";
|
||||||
environmentFile = config.sops.secrets."restic/environment".path;
|
environmentFile = config.sops.secrets."restic/environment".path;
|
||||||
passwordFile = config.sops.secrets."restic/password".path;
|
passwordFile = config.sops.secrets."restic/password".path;
|
||||||
|
backupPrepareCommand = lib.mkIf (value.suspendService != null) (
|
||||||
|
lib.mkBefore "${lib.getExe' pkgs.systemd "systemctl"} stop ${value.suspendService}"
|
||||||
|
);
|
||||||
|
backupCleanupCommand = lib.mkIf (value.suspendService != null) (
|
||||||
|
lib.mkAfter "${lib.getExe' pkgs.systemd "systemctl"} start ${value.suspendService}"
|
||||||
|
);
|
||||||
pruneOpts = [
|
pruneOpts = [
|
||||||
"--keep-daily 7"
|
"--keep-daily 7"
|
||||||
"--keep-weekly 5"
|
"--keep-weekly 5"
|
||||||
|
|
|
||||||
|
|
@ -20,30 +20,10 @@ in
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
security.polkit = {
|
|
||||||
enable = true;
|
|
||||||
extraConfig =
|
|
||||||
let
|
|
||||||
service = "syncthing.service";
|
|
||||||
in
|
|
||||||
''
|
|
||||||
polkit.addRule(function(action, subject) {
|
|
||||||
if (action.id == "org.freedesktop.systemd1.manage-units" &&
|
|
||||||
action.lookup("unit") == "${service}" &&
|
|
||||||
subject.user == "${user}") {
|
|
||||||
return polkit.Result.YES;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
custom.services.resticBackups.syncthing = {
|
custom.services.resticBackups.syncthing = {
|
||||||
inherit user;
|
inherit user;
|
||||||
extraConfig = {
|
suspendService = "syncthing.service";
|
||||||
backupPrepareCommand = "${lib.getExe' pkgs.systemd "systemctl"} stop syncthing.service";
|
extraConfig.paths = [ config.services.syncthing.dataDir ];
|
||||||
backupCleanupCommand = "${lib.getExe' pkgs.systemd "systemctl"} start syncthing.service";
|
|
||||||
paths = [ config.services.syncthing.dataDir ];
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
environment.systemPackages = [
|
environment.systemPackages = [
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue