diff --git a/flake.lock b/flake.lock index 40c8408..de1330e 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,47 @@ { "nodes": { + "agenix": { + "inputs": { + "darwin": "darwin", + "home-manager": "home-manager", + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1684153753, + "narHash": "sha256-PVbWt3qrjYAK+T5KplFcO+h7aZWfEj1UtyoKlvcDxh0=", + "owner": "ryantm", + "repo": "agenix", + "rev": "db5637d10f797bb251b94ef9040b237f4702cde3", + "type": "github" + }, + "original": { + "owner": "ryantm", + "repo": "agenix", + "type": "github" + } + }, + "darwin": { + "inputs": { + "nixpkgs": [ + "agenix", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1673295039, + "narHash": "sha256-AsdYgE8/GPwcelGgrntlijMg4t3hLFJFCRF3tL5WVjA=", + "owner": "lnl7", + "repo": "nix-darwin", + "rev": "87b9d090ad39b25b2400029c64825fc2a8868943", + "type": "github" + }, + "original": { + "owner": "lnl7", + "ref": "master", + "repo": "nix-darwin", + "type": "github" + } + }, "flake-utils": { "locked": { "lastModified": 1667395993, @@ -17,7 +59,28 @@ }, "home-manager": { "inputs": { - "nixpkgs": "nixpkgs" + "nixpkgs": [ + "agenix", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1682203081, + "narHash": "sha256-kRL4ejWDhi0zph/FpebFYhzqlOBrk0Pl3dzGEKSAlEw=", + "owner": "nix-community", + "repo": "home-manager", + "rev": "32d3e39c491e2f91152c84f8ad8b003420eab0a1", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "home-manager", + "type": "github" + } + }, + "home-manager_2": { + "inputs": { + "nixpkgs": "nixpkgs_2" }, "locked": { "lastModified": 1684596126, @@ -50,6 +113,22 @@ } }, "nixpkgs": { + "locked": { + "lastModified": 1677676435, + "narHash": "sha256-6FxdcmQr5JeZqsQvfinIMr0XcTyTuR7EXX0H3ANShpQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "a08d6979dd7c82c4cef0dcc6ac45ab16051c1169", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { "locked": { "lastModified": 1683286087, "narHash": "sha256-xseOd7W7xwF5GOF2RW8qhjmVGrKoBz+caBlreaNzoeI=", @@ -65,7 +144,7 @@ "type": "github" } }, - "nixpkgs_2": { + "nixpkgs_3": { "locked": { "lastModified": 1684570954, "narHash": "sha256-FX5y4Sm87RWwfu9PI71XFvuRpZLowh00FQpIJ1WfXqE=", @@ -122,8 +201,9 @@ }, "root": { "inputs": { - "home-manager": "home-manager", - "nixpkgs": "nixpkgs_2", + "agenix": "agenix", + "home-manager": "home-manager_2", + "nixpkgs": "nixpkgs_3", "pwnix": "pwnix" } } diff --git a/flake.nix b/flake.nix index 89f6327..1e19955 100644 --- a/flake.nix +++ b/flake.nix @@ -7,9 +7,10 @@ inputs.nixpkgs.follows = "nixpkgs"; url = git+https://im.badat.dev/bad/pwnix.git; }; + agenix.url = github:ryantm/agenix; }; - outputs = args@{ home-manager, nixpkgs, ... }: with nixpkgs; { + outputs = args@{ home-manager, nixpkgs, agenix, ... }: with nixpkgs; { # Configurations for NixOS machines. nixosConfigurations = @@ -32,8 +33,10 @@ system = "x86_64-linux"; modules = [ (mkUserConfig ./system/strawberry) + agenix.nixosModules.default ./system/strawberry/core.nix ./shared/core + ./shared/secrets.nix ]; specialArgs = args; }; diff --git a/secret/backblaze.age b/secret/backblaze.age new file mode 100644 index 0000000..a97ce5b Binary files /dev/null and b/secret/backblaze.age differ diff --git a/secrets.nix b/secrets.nix new file mode 100644 index 0000000..731359f --- /dev/null +++ b/secrets.nix @@ -0,0 +1,11 @@ +let strawberry = [ + (builtins.readFile ./system/strawberry/keys/riley.pub) + (builtins.readFile ./system/strawberry/keys/root.pub) + ]; + dev-lt-63 = [ + (builtins.readFile ./system/dev-lt-63/keys/riley.pub) + ]; +in { + # Secrets for backup cloud storage provider + "secret/backblaze.age".publicKeys = strawberry ++ dev-lt-63; +} \ No newline at end of file diff --git a/shared/core/backups.nix b/shared/core/backups.nix new file mode 100644 index 0000000..fe413c3 --- /dev/null +++ b/shared/core/backups.nix @@ -0,0 +1,36 @@ +{ pkgs, lib, config, ... }: + +let cfg = config.custom.backups; +in with lib; { + + options.custom.backups = { + enable = mkEnableOption "Automatic backups to Backblaze"; + bucket = mkOption { + type = types.str; + default = "ezri-${config.networking.hostName}-backups"; + }; + }; + + config = lib.mkIf (cfg.enable) { + services.duplicity = { + enable = true; + secretFile = config.age.secrets."backblaze".path; + frequency = null; # We set this later + root = "/home"; + fullIfOlderThan = "1M"; + exclude = [ + "/home/**/.config" + "/home/**/.cache" + "/home/**/.cargo" + # NixOS configuration, we keep that elsewhere. + "/home/**/os" + ]; + targetUrl = "b2://005c7170636d5ef0000000001@${cfg.bucket}"; + }; + systemd.services.duplicity.wants = ["network.target"]; + systemd.timers.duplicity.timerConfig."OnBootSec" = "20m"; + systemd.timers.duplicity.timerConfig."OnCalendar" = "daily"; + systemd.timers.duplicity.timerConfig."Persistent" = true; + }; + +} diff --git a/shared/core/default.nix b/shared/core/default.nix index 9709b26..8c33cba 100644 --- a/shared/core/default.nix +++ b/shared/core/default.nix @@ -3,6 +3,7 @@ { imports = [ + ./backups.nix ./gui.nix ./nix.nix ./ssh.nix diff --git a/shared/secrets.nix b/shared/secrets.nix new file mode 100644 index 0000000..9d10595 --- /dev/null +++ b/shared/secrets.nix @@ -0,0 +1,5 @@ +{ + age.secrets = { + "backblaze".file = ../secret/backblaze.age; + }; +} \ No newline at end of file diff --git a/system/dev-lt-63/keys/riley.pub b/system/dev-lt-63/keys/riley.pub new file mode 100644 index 0000000..f2aaa66 --- /dev/null +++ b/system/dev-lt-63/keys/riley.pub @@ -0,0 +1 @@ +ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIDroUHLf56zlYLiMoD1JV5XXZNwY9tftobDttC6hnfiM riley@dev-lt-63 diff --git a/system/strawberry/core.nix b/system/strawberry/core.nix index 7b1a5cd..46ccc7a 100644 --- a/system/strawberry/core.nix +++ b/system/strawberry/core.nix @@ -2,6 +2,7 @@ custom = { gui.enable = true; + backups.enable = true; }; system.stateVersion = "21.11"; diff --git a/system/strawberry/keys/riley.pub b/system/strawberry/keys/riley.pub new file mode 100644 index 0000000..cf58c21 --- /dev/null +++ b/system/strawberry/keys/riley.pub @@ -0,0 +1 @@ +ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINV6ECtM7dCAWwGX20Is9dbk9B2SHEGZN8bMzwoq5A3W riley@strawberry \ No newline at end of file diff --git a/system/strawberry/keys/root.pub b/system/strawberry/keys/root.pub new file mode 100644 index 0000000..e0881d5 --- /dev/null +++ b/system/strawberry/keys/root.pub @@ -0,0 +1 @@ +ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILniE+LdfdV9V9+Zj5gJXqKEv1CzQaEySy1u5OdbKa8d root@strawberry