Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sudo paths explicit #253

Merged
merged 3 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions hosts/carcosa/configuration.nix
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,8 @@ in
exit 1
fi

/run/wrappers/bin/sudo rsync -a --delete ~/bookdb-covers/ ${config.nixfiles.bookdb.dataDir}/covers || exit 1
/run/wrappers/bin/sudo chown -R ${config.users.users.bookdb.name}.nogroup ${config.nixfiles.bookdb.dataDir}/covers || exit 1
/run/wrappers/bin/sudo ${pkgs.rsync}/bin/rsync -a --delete ~/bookdb-covers/ ${config.nixfiles.bookdb.dataDir}/covers || exit 1
/run/wrappers/bin/sudo ${pkgs.coreutils}/bin/chown -R ${config.users.users.bookdb.name}.nogroup ${config.nixfiles.bookdb.dataDir}/covers || exit 1
'';
bookdb-receive-elasticsearch = ''
env ES_HOST=${config.systemd.services.bookdb.environment.ES_HOST} \
Expand All @@ -438,7 +438,7 @@ in
users = [ config.users.extraUsers.nyarlathotep-remote-sync.name ];
commands = [
{ command = "${pkgs.rsync}/bin/rsync -a --delete ${config.users.extraUsers.nyarlathotep-remote-sync.home}/bookdb-covers/ ${config.nixfiles.bookdb.dataDir}/covers"; options = [ "NOPASSWD" ]; }
{ command = "${pkgs.coreutils-full}/bin/chown -R ${config.users.users.bookdb.name}.nogroup ${config.nixfiles.bookdb.dataDir}/covers"; options = [ "NOPASSWD" ]; }
{ command = "${pkgs.coreutils}/bin/chown -R ${config.users.users.bookdb.name}.nogroup ${config.nixfiles.bookdb.dataDir}/covers"; options = [ "NOPASSWD" ]; }
];
}
];
Expand Down
4 changes: 2 additions & 2 deletions hosts/nyarlathotep/configuration.nix
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,8 @@ in
ExecStart = pkgs.writeShellScript "bookdb-sync" ''
set -ex

/run/wrappers/bin/sudo cp -r ${config.nixfiles.bookdb.dataDir}/covers/ ~/bookdb-covers
trap "/run/wrappers/bin/sudo rm -rf ~/bookdb-covers" EXIT
/run/wrappers/bin/sudo ${pkgs.coreutils}/bin/cp -r ${config.nixfiles.bookdb.dataDir}/covers/ ~/bookdb-covers
trap "/run/wrappers/bin/sudo ${pkgs.coreutils}/bin/rm -rf ~/bookdb-covers" EXIT
rsync -az\
-e "ssh -i $SSH_KEY_FILE -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" \
~/bookdb-covers/ \
Expand Down
2 changes: 1 addition & 1 deletion shared/bookdb/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ in
# TODO: figure out how to get `sudo` in the unit's path (adding the
# package doesn't help - need the wrapper)
nixfiles.backups.scripts.bookdb = ''
/run/wrappers/bin/sudo cp -a ${cfg.dataDir}/covers covers
/run/wrappers/bin/sudo ${pkgs.coreutils}/bin/cp -a ${cfg.dataDir}/covers covers
env ES_HOST=${config.systemd.services.bookdb.environment.ES_HOST} ${pkgs.nixfiles.bookdb}/bin/python -m bookdb.index.dump | gzip -9 > dump.json.gz
'';
nixfiles.backups.sudoRules = [
Expand Down
9 changes: 3 additions & 6 deletions shared/concourse/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ with lib;
let
cfg = config.nixfiles.concourse;
backend = config.nixfiles.oci-containers.backend;
backendPkg = if backend == "docker" then pkgs.docker else pkgs.podman;
in
{
imports = [
Expand Down Expand Up @@ -91,14 +92,10 @@ in
];

nixfiles.backups.scripts.concourse = ''
/run/wrappers/bin/sudo ${backend} exec -i concourse-db pg_dump -U concourse --no-owner concourse | gzip -9 > dump.sql.gz
/run/wrappers/bin/sudo ${backendPkg}/bin/${backend} exec -i concourse-db pg_dump -U concourse --no-owner concourse | gzip -9 > dump.sql.gz
'';
nixfiles.backups.sudoRules = [
{
command =
let pkg = if backend == "docker" then pkgs.docker else pkgs.podman;
in "${pkg}/bin/${backend} exec -i concourse-db pg_dump -U concourse --no-owner concourse";
}
{ command = "${backendPkg}/bin/${backend} exec -i concourse-db pg_dump -U concourse --no-owner concourse"; }
];
};
}
8 changes: 4 additions & 4 deletions shared/foundryvtt/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ in
# TODO: figure out how to get `sudo` in the unit's path (adding the
# package doesn't help - need the wrapper)
nixfiles.backups.scripts.foundryvtt = ''
/run/wrappers/bin/sudo systemctl stop foundryvtt
/run/wrappers/bin/sudo tar cfz bin.tar.gz ${cfg.dataDir}/bin
/run/wrappers/bin/sudo cp -a ${cfg.dataDir}/data data
/run/wrappers/bin/sudo systemctl start foundryvtt
/run/wrappers/bin/sudo ${pkgs.systemd}/bin/systemctl stop foundryvtt
/run/wrappers/bin/sudo ${pkgs.gnutar}/bin/tar cfz bin.tar.gz ${cfg.dataDir}/bin
/run/wrappers/bin/sudo ${pkgs.coreutils}/bin/cp -a ${cfg.dataDir}/data data
/run/wrappers/bin/sudo ${pkgs.systemd}/bin/systemctl start foundryvtt
'';
nixfiles.backups.sudoRules = [
{ command = "${pkgs.systemd}/bin/systemctl stop foundryvtt"; }
Expand Down
13 changes: 5 additions & 8 deletions shared/pleroma/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ with lib;
let
cfg = config.nixfiles.pleroma;
backend = config.nixfiles.oci-containers.backend;
backendPkg = if backend == "docker" then pkgs.docker else pkgs.podman;
in
{
imports = [
Expand Down Expand Up @@ -92,18 +93,14 @@ in
# TODO: figure out how to get `sudo` in the unit's path (adding the package
# doesn't help - need the wrapper)
nixfiles.backups.scripts.pleroma = ''
/run/wrappers/bin/sudo cp -a ${config.users.users.pleroma.home}/uploads uploads
/run/wrappers/bin/sudo cp -a ${config.users.users.pleroma.home}/static/emoji/custom emoji
/run/wrappers/bin/sudo ${backend} exec -i pleroma-db pg_dump -U pleroma --no-owner -Fc pleroma > postgres.dump
/run/wrappers/bin/sudo ${pkgs.coreutils}/bin/cp -a ${config.users.users.pleroma.home}/uploads uploads
/run/wrappers/bin/sudo ${pkgs.coreutils}/bin/cp -a ${config.users.users.pleroma.home}/static/emoji/custom emoji
/run/wrappers/bin/sudo ${backendPkg}/bin/${backend} exec -i pleroma-db pg_dump -U pleroma --no-owner -Fc pleroma > postgres.dump
'';
nixfiles.backups.sudoRules = [
{ command = "${pkgs.coreutils}/bin/cp -a ${config.users.users.pleroma.home}/uploads uploads"; }
{ command = "${pkgs.coreutils}/bin/cp -a ${config.users.users.pleroma.home}/static/emoji/custom emoji"; }
{
command =
let pkg = if backend == "docker" then pkgs.docker else pkgs.podman;
in "${pkg}/bin/${backend} exec -i pleroma-db pg_dump -U pleroma --no-owner -Fc pleroma";
}
{ command = "${backendPkg}/bin/${backend} exec -i pleroma-db pg_dump -U pleroma --no-owner -Fc pleroma"; }
];
};
}
9 changes: 3 additions & 6 deletions shared/umami/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ with lib;
let
cfg = config.nixfiles.umami;
backend = config.nixfiles.oci-containers.backend;
backendPkg = if backend == "docker" then pkgs.docker else pkgs.podman;
in
{
imports = [
Expand Down Expand Up @@ -42,14 +43,10 @@ in
};

nixfiles.backups.scripts.umami = ''
/run/wrappers/bin/sudo ${backend} exec -i umami-db pg_dump -U umami --no-owner umami | gzip -9 > dump.sql.gz
/run/wrappers/bin/sudo ${backendPkg}/bin/${backend} exec -i umami-db pg_dump -U umami --no-owner umami | gzip -9 > dump.sql.gz
'';
nixfiles.backups.sudoRules = [
{
command =
let pkg = if backend == "docker" then pkgs.docker else pkgs.podman;
in "${pkg}/bin/${backend} exec -i umami-db pg_dump -U umami --no-owner umami";
}
{ command = "${backendPkg}/bin/${backend} exec -i umami-db pg_dump -U umami --no-owner umami"; }
];
};
}