Skip to content

Commit

Permalink
Add pulseaudio CLI tools
Browse files Browse the repository at this point in the history
  • Loading branch information
pborzenkov committed Dec 3, 2024
1 parent 2c566e7 commit 0d3964a
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 110 deletions.
1 change: 1 addition & 0 deletions machines/rock/configs/backup.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{config, ...}: {
pbor.backup = {
enable = true;
host = "zh1012.rsync.net";
user = "zh1012";
sshKeyFile = "/etc/ssh/ssh_host_ed25519_key";
Expand Down
2 changes: 1 addition & 1 deletion machines/rock/configs/valheim.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{config, ...}: {
services.valheim = {
enable = false;
enable = true;
serverName = "Geest";
worldName = "Geest";
openFirewall = true;
Expand Down
1 change: 1 addition & 0 deletions machines/rock/configs/webapps.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
ssoPort = 8082;
in {
pbor.webapps = {
enable = true;
domain = "lab.borzenkov.net";
userIDHeader = "X-User";

Expand Down
87 changes: 44 additions & 43 deletions modules/backup/db.nix
Original file line number Diff line number Diff line change
Expand Up @@ -33,47 +33,48 @@ in {

config = let
exporter = pkgs.writeShellScriptBin "restic-exporter" (builtins.readFile ./restic-exporter.sh);
in {
systemd.services =
lib.mapAttrs'
(
name: backup: let
extraOptions = lib.concatMapStrings (arg: " -o ${arg}") config.lib.pbor.backup.extraOptions;
resticCmd = "${pkgs.restic}/bin/restic${extraOptions}";
backupName = "restic-backups-db-${name}";
pg = config.services.postgresql;
pgsu = "${pkgs.sudo}/bin/sudo -u ${pg.superUser}";
in
lib.nameValuePair backupName {
environment = {
RESTIC_PASSWORD_FILE = cfg.passwordFile;
RESTIC_REPOSITORY = config.lib.pbor.backup.repository;
};
path = [pkgs.openssh pkgs.gawk pkgs.gnugrep];
restartIfChanged = false;
serviceConfig = {
Type = "oneshot";
User = "root";
RuntimeDirectory = backupName;
ExecStartPost = "${exporter}/bin/restic-exporter %n";
};
script = ''
set -o pipefail
${pgsu} ${pg.package}/bin/pg_dump -c -d ${backup.database} | \
${resticCmd} backup --stdin --stdin-filename /db/${backup.database}.sql
'';
}
)
cfg.dbBackups;
systemd.timers =
lib.mapAttrs'
(
name: backup:
lib.nameValuePair "restic-backups-db-${name}" {
wantedBy = ["timers.target"];
timerConfig = config.lib.pbor.backup.timerConfig;
}
)
cfg.dbBackups;
};
in
lib.mkIf cfg.enable {
systemd.services =
lib.mapAttrs'
(
name: backup: let
extraOptions = lib.concatMapStrings (arg: " -o ${arg}") config.lib.pbor.backup.extraOptions;
resticCmd = "${pkgs.restic}/bin/restic${extraOptions}";
backupName = "restic-backups-db-${name}";
pg = config.services.postgresql;
pgsu = "${pkgs.sudo}/bin/sudo -u ${pg.superUser}";
in
lib.nameValuePair backupName {
environment = {
RESTIC_PASSWORD_FILE = cfg.passwordFile;
RESTIC_REPOSITORY = config.lib.pbor.backup.repository;
};
path = [pkgs.openssh pkgs.gawk pkgs.gnugrep];
restartIfChanged = false;
serviceConfig = {
Type = "oneshot";
User = "root";
RuntimeDirectory = backupName;
ExecStartPost = "${exporter}/bin/restic-exporter %n";
};
script = ''
set -o pipefail
${pgsu} ${pg.package}/bin/pg_dump -c -d ${backup.database} | \
${resticCmd} backup --stdin --stdin-filename /db/${backup.database}.sql
'';
}
)
cfg.dbBackups;
systemd.timers =
lib.mapAttrs'
(
name: backup:
lib.nameValuePair "restic-backups-db-${name}" {
wantedBy = ["timers.target"];
timerConfig = config.lib.pbor.backup.timerConfig;
}
)
cfg.dbBackups;
};
}
78 changes: 40 additions & 38 deletions modules/backup/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ in {
];

options.pbor.backup = {
enable = lib.mkEnableOption "Enable backup";
host = lib.mkOption {
type = lib.types.str;
description = ''
Expand Down Expand Up @@ -115,46 +116,47 @@ in {
'';

pruneName = "restic-backups-prune";
in {
lib.pbor.backup.repository = "sftp::${cfg.repository}";
lib.pbor.backup.extraOptions = [
"sftp.command='${sftpCommand}'"
];
lib.pbor.backup.timerConfig =
{
OnCalendar = cfg.timerConfig.OnCalendar;
}
// lib.optionalAttrs (cfg.timerConfig.RandomizedDelaySec != null) {
RandomizedDelaySec = cfg.timerConfig.RandomizedDelaySec;
};

systemd.services."${pruneName}" = let
extraOptions = lib.concatMapStrings (arg: " -o ${arg}") config.lib.pbor.backup.extraOptions;
resticCmd = "${pkgs.restic}/bin/restic${extraOptions}";
in
lib.mkIf (builtins.length cfg.prune.options > 0) {
environment = {
RESTIC_PASSWORD_FILE = cfg.passwordFile;
RESTIC_REPOSITORY = config.lib.pbor.backup.repository;
in
lib.mkIf cfg.enable {
lib.pbor.backup.repository = "sftp::${cfg.repository}";
lib.pbor.backup.extraOptions = [
"sftp.command='${sftpCommand}'"
];
lib.pbor.backup.timerConfig =
{
OnCalendar = cfg.timerConfig.OnCalendar;
}
// lib.optionalAttrs (cfg.timerConfig.RandomizedDelaySec != null) {
RandomizedDelaySec = cfg.timerConfig.RandomizedDelaySec;
};
path = [pkgs.openssh];
restartIfChanged = false;
serviceConfig = {
Type = "oneshot";
ExecStart = [
(resticCmd + " forget --prune " + (lib.concatStringsSep " " cfg.prune.options))
(resticCmd + " check")
];
ExecStartPost = "${checkRepoSpace}/bin/check-repo-space";
User = "root";
RuntimeDirectory = pruneName;
CacheDirectory = pruneName;
CacheDirectoryMode = "0700";

systemd.services."${pruneName}" = let
extraOptions = lib.concatMapStrings (arg: " -o ${arg}") config.lib.pbor.backup.extraOptions;
resticCmd = "${pkgs.restic}/bin/restic${extraOptions}";
in
lib.mkIf (builtins.length cfg.prune.options > 0) {
environment = {
RESTIC_PASSWORD_FILE = cfg.passwordFile;
RESTIC_REPOSITORY = config.lib.pbor.backup.repository;
};
path = [pkgs.openssh];
restartIfChanged = false;
serviceConfig = {
Type = "oneshot";
ExecStart = [
(resticCmd + " forget --prune " + (lib.concatStringsSep " " cfg.prune.options))
(resticCmd + " check")
];
ExecStartPost = "${checkRepoSpace}/bin/check-repo-space";
User = "root";
RuntimeDirectory = pruneName;
CacheDirectory = pruneName;
CacheDirectoryMode = "0700";
};
};
systemd.timers."${pruneName}" = lib.mkIf (builtins.length cfg.prune.options > 0) {
wantedBy = ["timers.target"];
timerConfig = cfg.prune.timerConfig;
};
systemd.timers."${pruneName}" = lib.mkIf (builtins.length cfg.prune.options > 0) {
wantedBy = ["timers.target"];
timerConfig = cfg.prune.timerConfig;
};
};
}
55 changes: 28 additions & 27 deletions modules/backup/fs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -51,32 +51,33 @@ in {

config = let
exporter = pkgs.writeShellScriptBin "restic-exporter" (builtins.readFile ./restic-exporter.sh);
in {
services.restic.backups =
lib.mapAttrs'
(
name: backup:
lib.nameValuePair "fs-${name}" {
repository = config.lib.pbor.backup.repository;
passwordFile = cfg.passwordFile;
extraOptions = config.lib.pbor.backup.extraOptions;
extraBackupArgs = ["--exclude-caches"];
paths = backup.paths;
exclude = backup.excludes;
timerConfig = config.lib.pbor.backup.timerConfig;
}
)
cfg.fsBackups;
in
lib.mkIf cfg.enable {
services.restic.backups =
lib.mapAttrs'
(
name: backup:
lib.nameValuePair "fs-${name}" {
repository = config.lib.pbor.backup.repository;
passwordFile = cfg.passwordFile;
extraOptions = config.lib.pbor.backup.extraOptions;
extraBackupArgs = ["--exclude-caches"];
paths = backup.paths;
exclude = backup.excludes;
timerConfig = config.lib.pbor.backup.timerConfig;
}
)
cfg.fsBackups;

systemd.services =
lib.mapAttrs'
(
name: backup:
lib.nameValuePair "restic-backups-fs-${name}" {
path = [pkgs.gawk pkgs.gnugrep];
serviceConfig.ExecStartPost = "${exporter}/bin/restic-exporter %n";
}
)
cfg.fsBackups;
};
systemd.services =
lib.mapAttrs'
(
name: backup:
lib.nameValuePair "restic-backups-fs-${name}" {
path = [pkgs.gawk pkgs.gnugrep];
serviceConfig.ExecStartPost = "${exporter}/bin/restic-exporter %n";
}
)
cfg.fsBackups;
};
}
1 change: 1 addition & 0 deletions modules/media/audio/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ in {
home = {
packages = with pkgs; [
playerctl
pulseaudio
ncpamixer
picard
shntool
Expand Down
3 changes: 2 additions & 1 deletion modules/webapps/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
cfg = config.pbor.webapps;
in {
options.pbor.webapps = {
enable = lib.mkEnableOption "Enable webapps";
domain = lib.mkOption {
type = lib.types.str;
description = ''
Expand Down Expand Up @@ -179,7 +180,7 @@ in {
};
};

config = {
config = lib.mkIf cfg.enable {
security.acme = {
acceptTerms = true;
defaults.email = "pavel@borzenkov.net";
Expand Down

0 comments on commit 0d3964a

Please sign in to comment.