feat: zfs auto snapshotting

This commit is contained in:
Patrick Großmann 2023-12-03 18:37:57 +01:00
parent dd60b94a59
commit 8f55b769fe
Signed by: patrick
GPG key ID: 451F95EFB8BECD0F
8 changed files with 106 additions and 24 deletions

View file

@ -57,6 +57,63 @@
}; };
}; };
services.zrepl = {
enable = true;
settings = {
global = {
logging = [
{
type = "syslog";
level = "info";
format = "human";
}
];
# TODO Monitoring
};
jobs = [
#{
# type = "push";
# name = "push-to-remote";
#}
{
type = "snap";
name = "mach-schnipp-schusss";
filesystems = {
"panzer/local/state<" = true;
"panzer/safe<" = true;
"rpool/local/state<" = true;
"rpool/safe<" = true;
};
snapshotting = {
type = "periodic";
prefix = "zrepl-";
interval = "10m";
timestamp_format = "iso-8601";
};
pruning = {
keep = [
{
type = "regex";
regex = "^zrepl-.*$";
negate = true;
}
{
type = "grid";
grid = lib.concatStringsSep " | " [
"1x1d(keep=all)"
"142x1h(keep=2)"
"90x1d(keep=2)"
"500x7d"
];
regex = "^zrepl-.*$";
}
];
};
}
];
};
};
fileSystems."/state".neededForBoot = true; fileSystems."/state".neededForBoot = true;
fileSystems."/panzer/state".neededForBoot = true; fileSystems."/panzer/state".neededForBoot = true;
fileSystems."/panzer/persist".neededForBoot = true; fileSystems."/panzer/persist".neededForBoot = true;

View file

@ -6,7 +6,7 @@
"01-lan1" = { "01-lan1" = {
address = ["192.168.178.32/24"]; address = ["192.168.178.32/24"];
gateway = ["192.168.178.1"]; gateway = ["192.168.178.1"];
matchConfig.MACAddress = config.secrets.secrets.local.networking.lan01.mac; matchConfig.MACAddress = config.secrets.secrets.local.networking.interfaces.lan01.mac;
dns = ["192.168.178.2"]; dns = ["192.168.178.2"];
networkConfig = { networkConfig = {
IPv6PrivacyExtensions = "yes"; IPv6PrivacyExtensions = "yes";

View file

@ -1,18 +1,13 @@
age-encryption.org/v1 age-encryption.org/v1
-> X25519 yvfsxGyyzm6ltKrzJCvt4fiNKq28qKc1NhJAfsBoKHk -> X25519 peN8LddAbhPxA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êÍÊÞŸ*cQ¿†È‚óÁÇùèÀ“3ûö;_<><06>ÓzŠù3.¨zn%ZÌ<5A>2 ôÐnMñ1JDe.¦Òâ{5öÎ<C3B6>7|¶‰»GvXY)xî7Rß8Ÿ“š3PýP‰ærã—.c­£fÒCF@ÊCISÐÃŒJ~U׆Ú!ÜøÅô<C385>$¹H—áMÜYO²•¨LPܱþ,t‡ê •K ìGÊfŸõ½©ÝCÍ9ºšÙ¸C „îÂiB6Í*šjf
ûïc­™Ä=¤ÀVðsS†s{@I=Kˆ4È}_{…\Álž´@„h&F$” ;(®ŠB
¾šŸ.ÄÌDvZÁ¾?;¾Ê]Oïkƒ~L­ó¨NxÕÅûK…·FpØ)0eº<>k;¶õÒu
<0E>>ãÁ ÄéO,92B<*fá
KšAàvñ@8_òu~ö<>ÿŽâ¹L)÷·†^µÌ¥ÉvººtY«Ù:5*<16> ã{^X­´<6F>òè¥
2èÐZ ,B+zkæS$“ƒ˜^4Nª®É(Txáøe<1D>°{#Õ8Ä ·p6`­âr& RÀÔðT pSFz"ˆÁÈfŠñ)È£ÍÀo=¯SÉx^³“; ôâ¨R

View file

@ -5,16 +5,17 @@ _inputs: _self: super: {
containers.mkConfig = name: config: containers.mkConfig = name: config:
super.lib.mkMerge [ super.lib.mkMerge [
{ {
bindmounts = { bindMounts = {
"state" = { "state" = {
mountpoint = "/state"; mountPoint = "/state";
hostPath = "/state/containers/${name}"; hostPath = "/state/containers/${name}";
}; };
"persist" = { "persist" = {
mountpoint = "/persist"; mountPoint = "/persist";
hostPath = config.zfs.mountpoint; hostPath = "/containers/${name}";
}; };
}; };
zfs.mountpoint = super.lib.mkDefault "/containers/${name}";
#config = {...}: { #config = {...}: {
#}; #};
} }

View file

@ -1,4 +1,5 @@
inputs: [ inputs: [
(import ./disko.nix inputs) (import ./disko.nix inputs)
(import ./containers.nix inputs) (import ./containers.nix inputs)
(import ./misc.nix inputs)
] ]

29
lib/misc.nix Normal file
View file

@ -0,0 +1,29 @@
_inputs: _self: super: let
inherit
(super.lib)
unique
foldl'
filter
;
# Counts how often each element occurrs in xs.
# Elements must be strings.
countOccurrences =
foldl'
(acc: x: acc // {${x} = (acc.${x} or 0) + 1;})
{};
# Returns all elements in xs that occur at least twice
duplicates = xs: let
occurrences = countOccurrences xs;
in
unique (filter (x: occurrences.${x} > 1) xs);
in {
lib =
super.lib
// {
inherit
countOccurrences
duplicates
;
};
}

View file

@ -40,7 +40,6 @@ in {
mountpoint = mkOption { mountpoint = mkOption {
type = types.str; type = types.str;
default = "/containers/${name}";
description = mdDoc "The host's mountpoint for the containers dataset"; description = mdDoc "The host's mountpoint for the containers dataset";
}; };
}; };

View file

@ -4,7 +4,7 @@
... ...
}: { }: {
imports = [./containers.nix]; imports = [./containers.nix];
containers.nextcloud = lib.container.mkConfig "nextcloud" { containers.nextcloud = lib.containers.mkConfig "nextcloud" {
autoStart = true; autoStart = true;
zfs = { zfs = {
enable = true; enable = true;