summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorSilas Schöffel <sils@sils.li>2024-10-29 22:02:29 +0100
committerSilas Schöffel <sils@sils.li>2024-10-29 22:03:50 +0100
commit126153306d623c8bcb78bd2a8a1fe0094402694d (patch)
treef384b3403794f327fce35f31889d404d0558c3e4
parentuse local theme file (diff)
downloadnix-config-126153306d623c8bcb78bd2a8a1fe0094402694d.tar.gz
nix-config-126153306d623c8bcb78bd2a8a1fe0094402694d.zip
add disko
-rw-r--r--flake.nix4
-rw-r--r--flake/nixosConfigurations/default.nix2
-rw-r--r--modules/nixos/sils/default.nix1
-rw-r--r--modules/nixos/sils/disks.nix132
-rwxr-xr-xscripts/mount.sh5
5 files changed, 144 insertions, 0 deletions
diff --git a/flake.nix b/flake.nix
index 1f49f16..4ae4315 100644
--- a/flake.nix
+++ b/flake.nix
@@ -158,6 +158,10 @@
       url = "github:arkenfox/user.js";
       flake = false;
     };
+    disko = {
+      url = "github:nix-community/disko";
+      inputs.nixpkgs.follows = "nixpkgs";
+    };
   };
   outputs = {
     flake-parts,
diff --git a/flake/nixosConfigurations/default.nix b/flake/nixosConfigurations/default.nix
index ca3c035..cf78608 100644
--- a/flake/nixosConfigurations/default.nix
+++ b/flake/nixosConfigurations/default.nix
@@ -6,6 +6,7 @@
   stylix,
   sops-nix,
   agenix,
+  disko,
   ...
 } @ attrs: let
   defaultModules = [
@@ -15,6 +16,7 @@
     stylix.nixosModules.stylix
     sops-nix.nixosModules.sops
     agenix.nixosModules.default
+    disko.nixosModules.disko
     {
       home-manager = {
         backupFileExtension = "backup";
diff --git a/modules/nixos/sils/default.nix b/modules/nixos/sils/default.nix
index 65d2a19..7655e29 100644
--- a/modules/nixos/sils/default.nix
+++ b/modules/nixos/sils/default.nix
@@ -3,6 +3,7 @@
     ./apparmor.nix
     ./basesystem.nix
     ./bluetooth.nix
+    ./disks.nix
     ./environment.nix
     ./firejail.nix
     ./font.nix
diff --git a/modules/nixos/sils/disks.nix b/modules/nixos/sils/disks.nix
new file mode 100644
index 0000000..bf0e2b0
--- /dev/null
+++ b/modules/nixos/sils/disks.nix
@@ -0,0 +1,132 @@
+{
+  config,
+  lib,
+  pkgs,
+  ...
+}: let
+  cfg = config.sils.disks;
+  defaultMountOptions = [
+    "noatime" # should have some performance upsides, and I don't use it anyways
+    "lazytime" # make time changes in memory
+  ];
+in {
+  options.sils.disks = {
+    enable = lib.mkEnableOption "disk setup with disko";
+
+    disk = lib.mkOption {
+      type = lib.types.path;
+      example = lib.literalExpression "/dev/disk/by-uuid/0442cb6d-f13a-4635-b487-fa76189774c5";
+      description = "The disk used for installing the OS.";
+    };
+
+    #swap = {
+    #  uuid = lib.mkOption {
+    #    type = lib.types.str;
+    #    example = lib.literalExpression "d1d20ae7-3d8a-44da-86da-677dbbb10c89";
+    #    description = "The uuid of the swapfile";
+    #  };
+    #  resumeOffset = lib.mkOption {
+    #    type = lib.types.str;
+    #    example = lib.literalExpression "134324224";
+    #    description = "The resume offset of the swapfile";
+    #  };
+    #};
+  };
+
+  config = lib.mkIf cfg.enable {
+    disko.devices = {
+      disk = {
+        main = {
+          device = cfg.disk;
+          content = {
+            type = "gpt";
+            partitions = {
+              root = {
+                size = "100%";
+                name = "root";
+                content = {
+                  type = "luks";
+                  name = "cryptroot";
+                  extraOpenArgs = ["--allow-discards"];
+                  content = {
+                    type = "btrfs";
+                    extraArgs = ["-f" "--label nixos"]; # Override existing partitions
+                    subvolumes = {
+                      "root" = {
+                        mountpoint = "/";
+                        mountOptions = defaultMountOptions;
+                      };
+                      "nix" = {
+                        mountpoint = "/nix";
+                        mountOptions = defaultMountOptions;
+                      };
+                      "persistent-storage" = {
+                        mountpoint = "/srv";
+                        mountOptions = defaultMountOptions;
+                      };
+                      "persistent-storage@snapshots" = {
+                        mountpoint = "/srv/snapshots";
+                        mountOptions = defaultMountOptions;
+                      };
+                      "swap" = {
+                        mountpoint = "/swap";
+                        mountOptions = defaultMountOptions;
+                      };
+                      "home" = {
+                        mountpoint = "/home";
+                        mountOptions = defaultMountOptions;
+                      };
+                    };
+                  };
+                };
+              };
+              MBR = {
+                type = "EF02";
+                size = "1M";
+                priority = 1;
+              };
+              boot = {
+                type = "EF00";
+                size = "4096M";
+                name = "boot";
+                content = {
+                  type = "filesystem";
+                  format = "vfat";
+                  mountpoint = "/boot";
+                  mountOptions = ["umask=0077"];
+                };
+              };
+            };
+          };
+        };
+      };
+      nodev = {
+        "/tmp" = {
+          fsType = "tmpfs";
+          mountOptions = ["defaults" "size=30G" "mode=755"];
+        };
+      };
+    };
+    fileSystems = {
+      "/srv" = {
+        neededForBoot = true;
+      };
+      "/swap" = {
+        neededForBoot = true;
+      };
+    };
+    swapDevices = [
+      #{
+      #        device = "/swap/swapfile";
+      #        priority = 1; # lower than zramSwap, just in case
+      #        # size = 2048; # TODO: can nixos create a btrfs swapfile correctly?
+      #}
+    ];
+    boot = {
+      kernelParams = [
+        #"resume_offset=${cfg.swap.resumeOffset}"
+      ];
+      #resumeDevice = "/dev/disk/by-uuid/${cfg.swap.uuid}";
+    };
+  };
+}
diff --git a/scripts/mount.sh b/scripts/mount.sh
new file mode 100755
index 0000000..4cd72d9
--- /dev/null
+++ b/scripts/mount.sh
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+set +x 
+
+sudo nix --extra-experimental-features "flakes nix-command" run github:nix-community/disko/latest -- --mode mount --flake $1