summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
Diffstat (limited to 'sys')
-rw-r--r--sys/default.nix149
1 files changed, 97 insertions, 52 deletions
diff --git a/sys/default.nix b/sys/default.nix
index c67c15f..e02516d 100644
--- a/sys/default.nix
+++ b/sys/default.nix
@@ -14,10 +14,6 @@ in {
type = bool;
};
- btrfs = mkOption {
- type = bool;
- };
-
loader = mkOption {
type = enum [ "grub" "systemd-boot" ];
};
@@ -112,37 +108,78 @@ in {
};
};
- sys = mkOption {
- type = submodule {
+ btrfs = mkOption {
+ default = [];
+
+ type = attrsOf (submodule {
options = {
device = mkOption {
type = str;
};
- ssd = mkOption {
- type = bool;
+ subvol = mkOption {
+ type = str;
};
- root = mkOption {
- type = str;
+ ssd = mkOption {
+ type = bool;
};
- toplevel = mkOption {
- type = str;
+ snapper = mkOption {
+ type = nullOr str;
+ default = null;
};
};
- };
+ });
};
- hdd = mkOption {
+ layout = mkOption {
+ default = {};
+
type = submodule {
options = {
- device = mkOption {
- type = str;
- };
-
- home = mkOption {
- type = str;
+ sysHddBtrfs = mkOption {
+ default = null;
+
+ type = nullOr (submodule {
+ options = {
+ sys = mkOption {
+ type = submodule {
+ options = {
+ device = mkOption {
+ type = str;
+ };
+
+ ssd = mkOption {
+ type = bool;
+ };
+
+ root = mkOption {
+ type = str;
+ };
+
+ toplevel = mkOption {
+ type = str;
+ };
+ };
+ };
+ };
+
+ hdd = mkOption {
+ type = submodule {
+ options = {
+ device = mkOption {
+ type = str;
+ };
+
+ home = mkOption {
+ type = str;
+ };
+ };
+ };
+ };
+ };
+ });
};
};
};
@@ -250,38 +287,12 @@ in {
fileSystems = let
inherit (cfg) fs;
- btrfs = { device, subvol, isSys }: mkIf cfg.btrfs {
+ btrfs = { device, subvol, ssd, ... }: {
inherit device;
fsType = "btrfs";
- options = let
- ssd = optional (isSys && fs.sys.ssd) "ssd";
- in [ "noatime" "compress=zstd" "subvol=${subvol}" ] ++ ssd;
+ options = [ "noatime" "compress=zstd" "subvol=${subvol}" ] ++ optional ssd "ssd";
};
- in {
- "/" = btrfs {
- inherit (fs.sys) device;
- subvol = fs.sys.root;
- isSys = true;
- };
-
- "/toplevel" = btrfs {
- inherit (fs.sys) device;
- subvol = fs.sys.toplevel;
- isSys = true;
- };
-
- "/hdd" = btrfs {
- inherit (fs.hdd) device;
- subvol = "/";
- isSys = false;
- };
-
- "/home" = btrfs {
- inherit (fs.hdd) device;
- subvol = fs.hdd.home;
- isSys = false;
- };
-
+ in mapAttrs (_: btrfs) cfg.fs.btrfs // {
"/boot" = {
inherit (cfg.fs.boot) device;
fsType = "vfat";
@@ -289,6 +300,39 @@ in {
};
};
+ local.fs.btrfs = let
+ sysHddBtrfs = layout: {
+ "/" = {
+ inherit (layout.sys) device ssd;
+ subvol = layout.sys.root;
+ };
+
+ "/toplevel" = {
+ inherit (layout.sys) device ssd;
+ subvol = layout.sys.toplevel;
+ };
+
+ "/hdd" = {
+ inherit (layout.hdd) device;
+ subvol = "/";
+ ssd = false;
+ };
+
+ "/home" = {
+ inherit (layout.hdd) device;
+ subvol = layout.hdd.home;
+ ssd = false;
+ snapper = "home";
+ };
+ };
+
+ inherit (cfg.fs) layout;
+
+ layoutMaps = [ sysHddBtrfs ];
+ layoutOpts = [ layout.sysHddBtrfs ];
+ valid = filter ({ snd, ... }: snd != null) (zipLists layoutMaps layoutOpts);
+ in optionalAttrs (valid != []) ((head valid).fst (head valid).snd);
+
time.timeZone = "America/Costa_Rica";
networking = {
@@ -360,9 +404,10 @@ in {
];
};
- local.snapperSubvols = mkIf cfg.btrfs {
- home = "/home";
- };
+ local.snapperSubvols = let
+ snapperEntry = path: opts: { name = opts.snapper; value = path; };
+ validEntry = _: opts: opts.snapper != null;
+ in mapAttrs' snapperEntry (filterAttrs validEntry cfg.fs.btrfs);
services.snapper.configs = let
snapperConfig = _: subvolume: {