FUCK YOU MODULES HOMELAB RULES
This commit is contained in:
@@ -15,12 +15,12 @@ in a borg archive to the specified repo
|
||||
*/
|
||||
|
||||
let
|
||||
cfg = config.modules.system.backups;
|
||||
cfg = config.system.backups;
|
||||
sec = config.sops.secrets;
|
||||
borg = "${pkgs.borgbackup}/bin/borg";
|
||||
in
|
||||
{
|
||||
options.modules.system.backups = {
|
||||
options.system.backups = {
|
||||
enable = lib.mkEnableOption "enables backups with borg";
|
||||
baks = lib.mkOption {
|
||||
type = lib.types.attrsOf (lib.types.attrsOf (lib.types.listOf lib.types.path));
|
||||
|
||||
@@ -1,102 +0,0 @@
|
||||
{ config, lib, pkgs, ... }:
|
||||
|
||||
let
|
||||
cfg = config.modules.system.backups;
|
||||
borg = "${pkgs.borgbackup}/bin/borg";
|
||||
backup_paths = lib.unique config.modules.system.backups.paths;
|
||||
passwd_file = config.sops.secrets."borg_passwd".path;
|
||||
in
|
||||
{
|
||||
options.modules.system.backups = {
|
||||
enable = lib.mkEnableOption "enables backups with borg";
|
||||
paths = lib.mkOption {
|
||||
type = lib.types.listOf lib.types.path;
|
||||
default = [];
|
||||
description = "list of directories to back up";
|
||||
};
|
||||
repo = lib.mkOption {
|
||||
type = lib.types.path;
|
||||
default = "/holocron/borg";
|
||||
description = "borg repository path";
|
||||
};
|
||||
passphraseFile = lib.mkOption {
|
||||
type = lib.types.path;
|
||||
default = passwd_file;
|
||||
description = "borg repository passphrase file";
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf (cfg.enable && backup_paths != []) {
|
||||
|
||||
# systemd.tmpfiles.rules = [
|
||||
# "d ${cfg.repo} 0755 root root"
|
||||
# ];
|
||||
|
||||
systemd.services.backups = {
|
||||
description = "backup service with borg!";
|
||||
path = [ pkgs.borgbackup ];
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
EnvironmentFile = config.modules.system.backups.passphraseFile;
|
||||
# the actual script borg is using
|
||||
ExecStart = pkgs.writeShellScript "borg-backup" ''
|
||||
set -euo pipefail
|
||||
export BORG_PASSPHRASE="$(cat ${passwd_file})"
|
||||
export BORG_REPO="${cfg.repo}"
|
||||
timestamp="$(date +'%Y-%m-%dT%H:%M:%S')"
|
||||
|
||||
# Initialize repo if it doesn't exist
|
||||
if ! borg info "$BORG_REPO" >/dev/null 2>&1; then
|
||||
echo "init borg repo at $BORG_REPO"
|
||||
borg init --encryption=repokey "$BORG_REPO"
|
||||
fi
|
||||
|
||||
# Create backup
|
||||
echo "starting backup..."
|
||||
borg create \
|
||||
--verbose \
|
||||
--filter AME \
|
||||
--list \
|
||||
--stats \
|
||||
--show-rc \
|
||||
--compression lzma,9 \
|
||||
"$BORG_REPO::${toString config.networking.hostName}-$timestamp" \
|
||||
${lib.concatStringsSep " " cfg.paths}
|
||||
|
||||
# Prune old backups according to retention policy
|
||||
echo "Pruning old backups..."
|
||||
borg prune -v --list "$BORG_REPO" \
|
||||
--keep-daily=7 \
|
||||
--keep-weekly=52 \
|
||||
--keep-monthly=-1
|
||||
|
||||
echo "$timestamp - backup completed successfully."
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
# create timer to run backups daily
|
||||
systemd.timers.backups = {
|
||||
description = "daily borg backup timer";
|
||||
wantedBy = [ "timers.target" ];
|
||||
timerConfig = {
|
||||
OnCalendar = "daily";
|
||||
Persistent = true;
|
||||
};
|
||||
};
|
||||
|
||||
# install borg binary
|
||||
environment.systemPackages = [ pkgs.borgbackup ];
|
||||
|
||||
# declare secret for repo password
|
||||
sops.secrets = {
|
||||
"borg_passwd" = {
|
||||
owner = "root";
|
||||
group = "root";
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
# add to modules
|
||||
# modules.system.backups.paths = lib.mkIf cfg.backups [ <path> ];
|
||||
@@ -1,10 +1,10 @@
|
||||
{ pkgs, config, lib, ... }:
|
||||
|
||||
let
|
||||
cfg = config.modules.system.docker;
|
||||
cfg = config.system.docker;
|
||||
in
|
||||
{
|
||||
options.modules.system.docker = {
|
||||
options.system.docker = {
|
||||
enable = lib.mkEnableOption "enables docker";
|
||||
};
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
{ pkgs, config, lib, ... }:
|
||||
|
||||
let
|
||||
cfg = config.modules.system.nvidia;
|
||||
cfg = config.system.nvidia;
|
||||
in
|
||||
{
|
||||
options.modules.system.nvidia = {
|
||||
options.system.nvidia = {
|
||||
enable = lib.mkEnableOption "enables nvidia";
|
||||
};
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
{ pkgs, config, lib, ... }:
|
||||
|
||||
let
|
||||
cfg = config.modules.system.podman;
|
||||
cfg = config.system.podman;
|
||||
in
|
||||
{
|
||||
options.modules.system.podman = {
|
||||
options.system.podman = {
|
||||
enable = lib.mkEnableOption "enables podman";
|
||||
};
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
{ pkgs, config, lib, inputs, ... }:
|
||||
|
||||
let
|
||||
cfg = config.modules.system.sops;
|
||||
cfg = config.system.sops;
|
||||
in
|
||||
{
|
||||
imports = [ inputs.sops-nix.nixosModules.sops ];
|
||||
|
||||
options.modules.system.sops = {
|
||||
options.system.sops = {
|
||||
enable = lib.mkEnableOption "enables sops";
|
||||
};
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
{ pkgs, config, lib, ... }:
|
||||
|
||||
let
|
||||
cfg = config.modules.system.ssh;
|
||||
cfg = config.system.ssh;
|
||||
in
|
||||
{
|
||||
options.modules.system.ssh = {
|
||||
options.system.ssh = {
|
||||
enable = lib.mkEnableOption "enables ssh";
|
||||
};
|
||||
|
||||
|
||||
@@ -1,27 +1,12 @@
|
||||
{ pkgs, config, lib, ... }:
|
||||
|
||||
let
|
||||
cfg = config.modules.system.syncthing;
|
||||
cfg = config.system.syncthing;
|
||||
in
|
||||
{
|
||||
options.modules.system.syncthing = {
|
||||
options.system.syncthing = {
|
||||
enable = lib.mkEnableOption "enables syncthing";
|
||||
|
||||
# mode = lib.mkOption {
|
||||
# type = lib.types.enum [ "server" "client" ];
|
||||
# default = "client";
|
||||
# description = "whether syncthing should run as a client (user) or server (system-wide).";
|
||||
# };
|
||||
#
|
||||
# data_dir = lib.mkOption {
|
||||
# type = lib.types.str;
|
||||
# default = if cfg.mode == "server"
|
||||
# then "/var/lib/syncthing"
|
||||
# else "/home/blake/.local/state/syncthing";
|
||||
# description = "optional override for syncthing data directory.";
|
||||
# };
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
|
||||
# systemd.tmpfiles.rules = lib.optionals (cfg.mode == "server") ["d /var/lib/syncthing 0775 blake blake -"];
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
cfg = config.modules.system.tailscale;
|
||||
cfg = config.system.tailscale;
|
||||
authkey_file = config.sops.secrets."tailscale_authkey".path;
|
||||
in {
|
||||
options.modules.system.tailscale = {
|
||||
options.system.tailscale = {
|
||||
enable = lib.mkEnableOption "enables tailscale";
|
||||
};
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
{ pkgs, config, lib, ... }:
|
||||
|
||||
let
|
||||
cfg = config.modules.system.vpn-confinement;
|
||||
cfg = config.system.vpn-confinement;
|
||||
in
|
||||
{
|
||||
options.modules.system.vpn-confinement = {
|
||||
options.system.vpn-confinement = {
|
||||
enable = lib.mkEnableOption "enables vpn-confinement";
|
||||
|
||||
# toggle for mullvad mexico w/ openvpn
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
{ pkgs, config, lib, ... }:
|
||||
|
||||
let
|
||||
cfg = config.modules.system.vpns;
|
||||
cfg = config.system.vpns;
|
||||
in
|
||||
{
|
||||
options.modules.system.vpns = {
|
||||
options.system.vpns = {
|
||||
enable = lib.mkEnableOption "enables vpns";
|
||||
|
||||
# toggle for pia mexico w/ openvpn
|
||||
|
||||
Reference in New Issue
Block a user