mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-23 06:01:15 +00:00
nixos/zfs: Keep zero-sized auto snapshots by default
Otherwise, in certain cases, snapshots of infrequently-modified filesystems can be kept for a much longer time than the user would normally expect, and cause a large amount of extra disk space to be consumed. Also added flag to snapshot filesystems in parallel by default. I've also added a configuration option for zfs-auto-snapshot flags, so that the user can override them. For example, the user may want to append --utc to the list of default options, so that the snapshot names don't cause name conflicts or apparent time reversals due to daylight savings or timezone changes.
This commit is contained in:
parent
9b41cf0281
commit
b0a51de6c1
|
@ -12,6 +12,7 @@ let
|
|||
cfgSpl = config.boot.spl;
|
||||
cfgZfs = config.boot.zfs;
|
||||
cfgSnapshots = config.services.zfs.autoSnapshot;
|
||||
cfgSnapFlags = cfgSnapshots.flags;
|
||||
|
||||
inInitrd = any (fs: fs == "zfs") config.boot.initrd.supportedFilesystems;
|
||||
inSystem = any (fs: fs == "zfs") config.boot.supportedFilesystems;
|
||||
|
@ -137,6 +138,25 @@ in
|
|||
'';
|
||||
};
|
||||
|
||||
flags = mkOption {
|
||||
default = "-k -p";
|
||||
example = "-k -p --utc";
|
||||
type = types.str;
|
||||
description = ''
|
||||
Flags to pass to the zfs-auto-snapshot command.
|
||||
|
||||
Run <literal>zfs-auto-snapshot</literal> (without any arguments) to
|
||||
see available flags.
|
||||
|
||||
If it's not too inconvenient for snapshots to have timestamps in UTC,
|
||||
it is suggested that you append <literal>--utc</literal> to the list
|
||||
of default options (see example).
|
||||
|
||||
Otherwise, snapshot names can cause name conflicts or apparent time
|
||||
reversals due to daylight savings, timezone or other date/time changes.
|
||||
'';
|
||||
};
|
||||
|
||||
frequent = mkOption {
|
||||
default = 4;
|
||||
type = types.int;
|
||||
|
@ -232,7 +252,9 @@ in
|
|||
environment.etc."zfs/zed.d".source = "${zfsUserPkg}/etc/zfs/zed.d/*";
|
||||
|
||||
system.fsPackages = [ zfsUserPkg ]; # XXX: needed? zfs doesn't have (need) a fsck
|
||||
environment.systemPackages = [ zfsUserPkg ];
|
||||
environment.systemPackages = [ zfsUserPkg ]
|
||||
++ optional enableAutoSnapshots autosnapPkg; # so the user can run the command to see flags
|
||||
|
||||
services.udev.packages = [ zfsUserPkg ]; # to hook zvol naming, etc.
|
||||
systemd.packages = [ zfsUserPkg ];
|
||||
|
||||
|
@ -289,7 +311,7 @@ in
|
|||
after = [ "zfs-import.target" ];
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
ExecStart = "${zfsAutoSnap} frequent ${toString cfgSnapshots.frequent}";
|
||||
ExecStart = "${zfsAutoSnap} ${cfgSnapFlags} frequent ${toString cfgSnapshots.frequent}";
|
||||
};
|
||||
restartIfChanged = false;
|
||||
startAt = "*:15,30,45";
|
||||
|
@ -300,7 +322,7 @@ in
|
|||
after = [ "zfs-import.target" ];
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
ExecStart = "${zfsAutoSnap} hourly ${toString cfgSnapshots.hourly}";
|
||||
ExecStart = "${zfsAutoSnap} ${cfgSnapFlags} hourly ${toString cfgSnapshots.hourly}";
|
||||
};
|
||||
restartIfChanged = false;
|
||||
startAt = "hourly";
|
||||
|
@ -311,7 +333,7 @@ in
|
|||
after = [ "zfs-import.target" ];
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
ExecStart = "${zfsAutoSnap} daily ${toString cfgSnapshots.daily}";
|
||||
ExecStart = "${zfsAutoSnap} ${cfgSnapFlags} daily ${toString cfgSnapshots.daily}";
|
||||
};
|
||||
restartIfChanged = false;
|
||||
startAt = "daily";
|
||||
|
@ -322,7 +344,7 @@ in
|
|||
after = [ "zfs-import.target" ];
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
ExecStart = "${zfsAutoSnap} weekly ${toString cfgSnapshots.weekly}";
|
||||
ExecStart = "${zfsAutoSnap} ${cfgSnapFlags} weekly ${toString cfgSnapshots.weekly}";
|
||||
};
|
||||
restartIfChanged = false;
|
||||
startAt = "weekly";
|
||||
|
@ -333,7 +355,7 @@ in
|
|||
after = [ "zfs-import.target" ];
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
ExecStart = "${zfsAutoSnap} monthly ${toString cfgSnapshots.monthly}";
|
||||
ExecStart = "${zfsAutoSnap} ${cfgSnapFlags} monthly ${toString cfgSnapshots.monthly}";
|
||||
};
|
||||
restartIfChanged = false;
|
||||
startAt = "monthly";
|
||||
|
|
Loading…
Reference in a new issue