diff --git a/hosts/ocelot/default.nix b/hosts/ocelot/default.nix index ee53751..82186a7 100644 --- a/hosts/ocelot/default.nix +++ b/hosts/ocelot/default.nix @@ -4,6 +4,7 @@ ../../profiles/hcloud ]; fileSystems."/" = { device = "/dev/sda1"; fsType = "ext4"; }; + cherrykitten.backups.enable = true; networking = { nameservers = [ diff --git a/modules/nixos/backups/default.nix b/modules/nixos/backups/default.nix new file mode 100644 index 0000000..aaecfb3 --- /dev/null +++ b/modules/nixos/backups/default.nix @@ -0,0 +1,51 @@ +{ config, pkgs, lib, ... }: +let + cfg = config.cherrykitten.backups; + hostname = config.networking.hostName; +in +{ + options.cherrykitten.backups = { + enable = lib.mkEnableOption "Backups"; + }; + + config = lib.mkIf cfg.enable { + deployment.keys = { + "restic_env" = { + destDir = "/root/keys"; + keyCommand = [ "pass" "hosts/${hostname}/restic/env" ]; + }; + "restic_repository_file" = { + destDir = "/root/keys"; + keyCommand = [ "pass" "hosts/${hostname}/restic/repository" ]; + }; + "restic_password_file" = { + destDir = "/root/keys"; + keyCommand = [ "pass" "hosts/${hostname}/restic/password" ]; + }; + }; + services.restic.backups = { + default = { + user = "root"; + timerConfig = { + OnCalendar = "daily"; + Persistent = true; + }; + pruneOpts = [ + "--keep-daily 14" + "--keep-weekly 6" + "--keep-monthly 24" + ]; + paths = [ ] ++ lib.optional (config.services.postgresql.enable) "/var/lib/postgresql"; + initialize = true; + exclude = [ + "cache" + ".cache" + ".git" + ]; + environmentFile = "/root/keys/restic_env"; + repositoryFile = "/root/keys/restic_repository_file"; + passwordFile = "/root/keys/restic_password_file"; + }; + }; + }; +} diff --git a/modules/nixos/default.nix b/modules/nixos/default.nix new file mode 100644 index 0000000..62a39a1 --- /dev/null +++ b/modules/nixos/default.nix @@ -0,0 +1,3 @@ +{ ... }: { + imports = [ ./backups ]; +} diff --git a/profiles/base/default.nix b/profiles/base/default.nix index 29c7bab..53e3331 100644 --- a/profiles/base/default.nix +++ b/profiles/base/default.nix @@ -2,6 +2,7 @@ imports = [ ../../users/root ../../users/sammy + ../../modules/nixos inputs.home-manager.nixosModules.home-manager ];