about summary refs log blame commit diff stats
path: root/modules/by-name/di/disko/module.nix
blob: b4fc3c84ed7564852d9f8b2e2f2e3ea586f080cd (plain) (tree)
1
2
3
4
5
6



         
                           











                                                                           
                                
























































                                                                                     
{
  config,
  lib,
  ...
}: let
  cfg = config.vhack.disko;

  defaultMountOptions = ["compress-force=zstd:15" "noatime"];
in {
  options.vhack.disko = {
    enable = lib.mkEnableOption "disk configuration via disko";

    disk = lib.mkOption {
      type = lib.types.path;
      example = "/dev/disk/by-id/ata-WDC_WD10SDRW-11A0XS0_WD-WXP2A901KJN5";
      description = "Path to the main disk";
    };
  };

  config = lib.mkIf cfg.enable {
    disko.devices = {
      disk.main = {
        type = "disk";
        device = cfg.disk;

        content = {
          type = "gpt";
          partitions = {
            boot = {
              size = "1M";
              type = "EF02"; # for grub MBR
            };
            root = {
              size = "100%";
              content = {
                type = "btrfs";
                extraArgs = ["-f" "--label nixos"]; # f: Override existing partitions

                subvolumes = {
                  "/nix" = {
                    mountpoint = "/nix";
                    mountOptions = defaultMountOptions;
                  };
                  "/srv" = {
                    mountpoint = "/srv";
                    mountOptions = defaultMountOptions;
                  };
                  "/srv/.snapshots" = {
                    mountpoint = "/srv/.snapshots";
                    mountOptions = defaultMountOptions;
                  };
                  "/boot" = {
                    mountpoint = "/boot";
                    mountOptions = defaultMountOptions;
                  };
                };
              };
            };
          };
        };
      };

      nodev."/" = {
        fsType = "tmpfs";
        mountOptions = ["defaults" "size=6G" "mode=755"];
      };
    };

    fileSystems = {
      "/srv" = {
        neededForBoot = true;
      };
      "/boot" = {
        neededForBoot = true;
      };
    };
  };
}