rsync: Correctly support using a non-default local user account

Prior to this commit if the local user name was changed but the group
was left at the default then neither the user nor group was created.
This resulted in a failed `chown'.
This commit is contained in:
Peter Jones 2019-10-04 10:01:24 -07:00
parent 899b1db967
commit 374abe15ca
No known key found for this signature in database
GPG key ID: 9DAFAA8D01941E49
2 changed files with 8 additions and 3 deletions

View file

@ -5,7 +5,6 @@ let
cfg = config.phoebe.backup.rsync;
cdir = config.phoebe.backup.directory;
plib = config.phoebe.lib;
user = "backup";
port = builtins.head config.services.openssh.ports;
scripts = (import ../../pkgs/default.nix { inherit pkgs; }).backup-scripts;
@ -157,7 +156,7 @@ in
user = mkOption {
type = types.str;
default = user;
default = config.phoebe.backup.user.name;
description = "User to perform backups as.";
};
@ -176,7 +175,12 @@ in
#### Implementation
config = mkIf cfg.enable {
phoebe.backup.user.enable = cfg.user == user;
# Create user/group if necessary:
phoebe.backup.user.enable =
let user = config.phoebe.backup.user.name;
group = config.phoebe.backup.user.group;
in cfg.user == user || cfg.group == group;
systemd.services = toSystemd service;
systemd.timers = toSystemd timer;
};

View file

@ -20,6 +20,7 @@ pkgs.nixosTest {
phoebe.backup.rsync = {
enable = true;
user = "root";
schedules = [
{ host = "localhost";
directory = "/tmp/backup";