summaryrefslogtreecommitdiff
path: root/sys/fs/layout.nix
diff options
context:
space:
mode:
Diffstat (limited to 'sys/fs/layout.nix')
-rw-r--r--sys/fs/layout.nix77
1 files changed, 77 insertions, 0 deletions
diff --git a/sys/fs/layout.nix b/sys/fs/layout.nix
new file mode 100644
index 0000000..999492d
--- /dev/null
+++ b/sys/fs/layout.nix
@@ -0,0 +1,77 @@
+{ lib, config, ... }:
+with lib; let
+ cfg = config.local;
+in {
+ options.local.fs.layout = with lib.types; {
+ sysHddBtrfs = mkOption {
+ default = null;
+
+ type = nullOr (submodule {
+ options = {
+ sys = {
+ device = mkOption {
+ type = str;
+ };
+
+ ssd = mkOption {
+ type = bool;
+ };
+
+ root = mkOption {
+ type = str;
+ };
+
+ toplevel = mkOption {
+ type = str;
+ };
+ };
+
+ hdd = {
+ device = mkOption {
+ type = str;
+ };
+
+ home = mkOption {
+ type = str;
+ };
+ };
+ };
+ });
+ };
+ };
+
+ config = {
+ 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);
+ };
+}