54 lines
1.2 KiB
Nix
54 lines
1.2 KiB
Nix
|
{ config, pkgs, lib, ... }:
|
||
|
with lib;
|
||
|
let
|
||
|
makeBackup = pkgs.writeScript "make-backupdl" ''
|
||
|
#!${pkgs.bash}/bin/bash
|
||
|
|
||
|
set -e
|
||
|
|
||
|
export PATH=${pkgs.rsync}/bin:${pkgs.openssh}/bin
|
||
|
|
||
|
rsync --ignore-existing -av nixbld.m-labs.hk:/home/backupdl /var/lib/backupdl
|
||
|
'';
|
||
|
|
||
|
cfg = config.services.backupdl;
|
||
|
in
|
||
|
{
|
||
|
options.services.backupdl = {
|
||
|
enable = mkOption {
|
||
|
type = types.bool;
|
||
|
default = false;
|
||
|
description = "Enable backups";
|
||
|
};
|
||
|
};
|
||
|
|
||
|
config = mkIf cfg.enable {
|
||
|
systemd.services.backupdl = {
|
||
|
description = "Nixbld backups download";
|
||
|
serviceConfig = {
|
||
|
Type = "oneshot";
|
||
|
User = "backupdl";
|
||
|
Group = "backupdl";
|
||
|
ExecStart = "${makeBackup}";
|
||
|
};
|
||
|
};
|
||
|
|
||
|
users.users.backupdl = {
|
||
|
name = "backupdl";
|
||
|
group = "backupdl";
|
||
|
description = "Nixbld backups download";
|
||
|
isSystemUser = true;
|
||
|
createHome = true;
|
||
|
home = "/var/lib/backupdl";
|
||
|
useDefaultShell = true;
|
||
|
};
|
||
|
users.extraGroups.backupdl = {};
|
||
|
|
||
|
systemd.timers.backupdl = {
|
||
|
description = "Nixbld backups download";
|
||
|
wantedBy = [ "timers.target" ];
|
||
|
timerConfig.OnCalendar = "*-*-* 18:00:00";
|
||
|
};
|
||
|
};
|
||
|
}
|