diff options
Diffstat (limited to '')
| -rw-r--r-- | sys/btrfs/default.nix | 6 | ||||
| -rw-r--r-- | sys/btrfs/mounts.nix | 39 | ||||
| -rw-r--r-- | sys/btrfs/snapper.nix (renamed from sys/fs/btrfs.nix) | 59 |
3 files changed, 53 insertions, 51 deletions
diff --git a/sys/btrfs/default.nix b/sys/btrfs/default.nix new file mode 100644 index 0000000..ee76537 --- /dev/null +++ b/sys/btrfs/default.nix @@ -0,0 +1,6 @@ +{ + imports = [ + ./mounts.nix + ./snapper.nix + ]; +} diff --git a/sys/btrfs/mounts.nix b/sys/btrfs/mounts.nix new file mode 100644 index 0000000..133f08f --- /dev/null +++ b/sys/btrfs/mounts.nix @@ -0,0 +1,39 @@ +{ lib, config, pkgs, ... }: +with lib; let + cfg = config.local.btrfs; +in +{ + options.local.btrfs = { + mounts = mkOption { + default = { }; + + type = with lib.types; attrsOf (submodule { + options = { + ssd = mkOption { + type = bool; + }; + + device = mkOption { + type = str; + }; + + subvol = mkOption { + type = str; + }; + }; + }); + }; + }; + + config = mkIf (cfg.mounts != { }) { + fileSystems = + let + btrfsMount = { device, subvol, ssd }: { + inherit device; + fsType = "btrfs"; + options = [ "noatime" "compress=zstd" "subvol=${subvol}" ] ++ optional ssd "ssd"; + }; + in + mapAttrs (_: btrfsMount) cfg.mounts; + }; +} diff --git a/sys/fs/btrfs.nix b/sys/btrfs/snapper.nix index f240b0d..27d2779 100644 --- a/sys/fs/btrfs.nix +++ b/sys/btrfs/snapper.nix @@ -1,60 +1,17 @@ -{ lib, config, pkgs, ... }: +{ config, lib, pkgs, ... }: with lib; let - cfg = config.local; + cfg = config.local.btrfs; in { - options.local = with lib.types; { - snapperSubvols = mkOption { - type = attrsOf str; + options.local.btrfs = { + snapper = mkOption { + type = with lib.types; attrsOf str; default = { }; }; - - fs.btrfs = mkOption { - default = [ ]; - - type = attrsOf (submodule { - options = { - device = mkOption { - type = str; - }; - - subvol = mkOption { - type = str; - }; - - ssd = mkOption { - type = bool; - }; - - snapper = mkOption { - type = nullOr str; - default = null; - }; - }; - }); - }; }; - config = { - environment.systemPackages = optional (cfg.snapperSubvols != { }) pkgs.local.btclone; - - fileSystems = - let - inherit (cfg) fs; - btrfs = { device, subvol, ssd, ... }: { - inherit device; - fsType = "btrfs"; - options = [ "noatime" "compress=zstd" "subvol=${subvol}" ] ++ optional ssd "ssd"; - }; - in - mapAttrs (_: btrfs) cfg.fs.btrfs; - - local.snapperSubvols = - let - snapperEntry = path: opts: { name = opts.snapper; value = path; }; - validEntry = _: opts: opts.snapper != null; - in - mapAttrs' snapperEntry (filterAttrs validEntry cfg.fs.btrfs); + config = mkIf (cfg.snapper != { }) { + environment.systemPackages = [ pkgs.local.btclone ]; services.snapper.configs = let @@ -111,6 +68,6 @@ in EMPTY_PRE_POST_MIN_AGE = "1800"; }; in - mapAttrs snapperConfig cfg.snapperSubvols; + mapAttrs snapperConfig cfg.snapper; }; } |
