1
0
Fork 0

Modules: replace Disko module with homegrown filesystems module

This commit is contained in:
Aires 2024-07-02 18:15:37 -04:00
parent 84885450a2
commit 5949038b15
6 changed files with 106 additions and 171 deletions

View file

@ -30,7 +30,7 @@ mount -o subvol=@ $root_drive /mnt
mkdir -p /mnt/{boot,home,var/log,nix,swap} mkdir -p /mnt/{boot,home,var/log,nix,swap}
mount $boot_drive /mnt/boot mount $boot_drive /mnt/boot
mount -o subvol=@home $root_drive /mnt/home mount -o subvol=@home $root_drive /mnt/home
mount -o subvol=@log $root_drive /var/log mount -o subvol=@log $root_drive /mnt/var/log
mount -o subvol=@nix $root_drive /mnt/nix mount -o subvol=@nix $root_drive /mnt/nix
mount -o subvol=@swap $root_drive /mnt/swap mount -o subvol=@swap $root_drive /mnt/swap

View file

@ -21,26 +21,6 @@
"type": "github" "type": "github"
} }
}, },
"disko": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1719864345,
"narHash": "sha256-e4Pw+30vFAxuvkSTaTypd9zYemB/QlWcH186dsGT+Ms=",
"owner": "nix-community",
"repo": "disko",
"rev": "544a80a69d6e2da04e4df7ec8210a858de8c7533",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "disko",
"type": "github"
}
},
"flake-compat": { "flake-compat": {
"flake": false, "flake": false,
"locked": { "locked": {
@ -359,7 +339,6 @@
}, },
"root": { "root": {
"inputs": { "inputs": {
"disko": "disko",
"home-manager": "home-manager", "home-manager": "home-manager",
"lanzaboote": "lanzaboote", "lanzaboote": "lanzaboote",
"lix-module": "lix-module", "lix-module": "lix-module",

View file

@ -37,18 +37,11 @@
url = "git+file:./nix-secrets"; url = "git+file:./nix-secrets";
flake = false; flake = false;
}; };
# Disko support https://github.com/nix-community/disko
disko = {
url = "github:nix-community/disko";
inputs.nixpkgs.follows = "nixpkgs";
};
}; };
outputs = outputs =
inputs@{ inputs@{
self, self,
disko,
home-manager, home-manager,
lanzaboote, lanzaboote,
lix-module, lix-module,
@ -70,7 +63,6 @@
defaultModules = [ defaultModules = [
./modules/autoimport.nix ./modules/autoimport.nix
(import nix-secrets) (import nix-secrets)
disko.nixosModules.disko
lix-module.nixosModules.default lix-module.nixosModules.default
lanzaboote.nixosModules.lanzaboote lanzaboote.nixosModules.lanzaboote
nix-flatpak.nixosModules.nix-flatpak nix-flatpak.nixosModules.nix-flatpak

View file

@ -7,12 +7,7 @@
}: }:
let let
luksPartition = "/dev/disk/by-uuid/dfb4fc8f-e82b-43a1-91c1-a77acb6337cb"; luksUUID = "9fdc521b-a037-4070-af47-f54da03675e4";
luksDevice = "9fdc521b-a037-4070-af47-f54da03675e4";
standardMountOpts = [
"compress=zstd"
"noatime"
];
in in
{ {
imports = [ (modulesPath + "/installer/scan/not-detected.nix") ]; imports = [ (modulesPath + "/installer/scan/not-detected.nix") ];
@ -26,8 +21,8 @@ in
"sd_mod" "sd_mod"
"sdhci_pci" "sdhci_pci"
]; ];
luks.devices."luks-${luksDevice}" = { luks.devices."luks-${luksUUID}" = {
device = "/dev/disk/by-uuid/${luksDevice}"; device = "/dev/disk/by-uuid/${luksUUID}";
crypttabExtraOpts = [ "tpm2-device=auto" ]; # Enable TPM auto-unlocking crypttabExtraOpts = [ "tpm2-device=auto" ]; # Enable TPM auto-unlocking
}; };
}; };
@ -35,40 +30,19 @@ in
extraModulePackages = [ ]; extraModulePackages = [ ];
}; };
fileSystems = { # Configure the main filesystem.
"/" = { aux.system.filesystem.btrfs = {
device = luksPartition; enable = true;
fsType = "btrfs"; devices = {
options = [ "subvol=@" ] ++ standardMountOpts; boot = "/dev/disk/by-uuid/FC20-D155";
btrfs = "/dev/disk/by-uuid/${luksUUID}";
}; };
"/home" = { swapFile = {
device = luksPartition; enable = true;
fsType = "btrfs"; size = 16384;
options = [ "subvol=@home" ] ++ standardMountOpts;
};
"/nix" = {
device = luksPartition;
fsType = "btrfs";
options = [ "subvol=@nix" ] ++ standardMountOpts;
};
"/swap" = {
device = luksPartition;
fsType = "btrfs";
options = [ "subvol=@swap" ];
};
"/boot" = {
device = "/dev/disk/by-uuid/FC20-D155";
fsType = "vfat";
}; };
}; };
swapDevices = [
{
device = "/swap/swapfile";
size = 16384;
}
];
# Enables DHCP on each ethernet and wireless interface. In case of scripted networking # Enables DHCP on each ethernet and wireless interface. In case of scripted networking
# (the default) this is the recommended approach. When using systemd-networkd it's # (the default) this is the recommended approach. When using systemd-networkd it's
# still possible to use this option, but it's recommended to use it in conjunction # still possible to use this option, but it's recommended to use it in conjunction

View file

@ -1,103 +0,0 @@
{ lib, config, ... }:
let
cfg = config.aux.system.disko;
standardMountOpts = [
"compress=zstd"
"noatime"
];
in
{
options = {
aux.system.disko = {
enable = lib.mkEnableOption (lib.mdDoc "Enables Disko for disk & partition management.");
primaryDiskID = lib.mkOption {
type = lib.types.str;
description = "The ID of the disk to manage using Disko. If possible, use the World Wide Name (WWN), e.g `/dev/disk/by-id/nvme-eui.*`";
default = "";
};
swapFile = {
enable = lib.mkEnableOption (lib.mdDoc "Enables the creation of swap files.");
size = lib.mkOption {
type = lib.types.str;
description = "The size of the swap file to create (defaults to 8G, or 8 gigabytes).";
default = "8G";
};
};
};
};
config = lib.mkIf cfg.enable {
# Check for blank values
assertions = [
{
assertion = (cfg.primaryDiskID != "");
message = "aux.system.disko.primaryDiskID is not set. Please enter a valid disk ID.";
}
];
# Disk management
disko.enableConfig = true;
disko.devices = {
disk = {
main = {
type = "disk";
device = "/dev/disk/by-id/${cfg.primaryDiskID}";
content = {
type = "gpt";
partitions = {
ESP = {
priority = 1;
name = "ESP";
label = "boot";
size = "1G";
type = "EF00";
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
};
};
luks = {
size = "100%";
label = "nixos";
content = {
type = "luks";
name = "cryptroot";
settings = {
allowDiscards = true;
crypttabExtraOpts = lib.mkIf config.aux.system.bootloader.tpm2.enable [ "tpm2-device=auto" ];
};
content = {
type = "btrfs";
extraArgs = [ "-f" ]; # Override existing partitions.
# Unless otherwise specified, the subvolume name equals the mount name.
subvolumes = {
"/root" = {
mountpoint = "/";
mountOptions = standardMountOpts;
};
"/home" = {
mountOptions = standardMountOpts;
};
"/nix" = {
mountOptions = standardMountOpts;
};
"/swap" = lib.mkIf cfg.swapFile.enable {
mountpoint = "/.swap";
swap.swapfile.size = cfg.swapFile.size;
};
"/log" = {
mountpoint = "/var/log";
mountOptions = standardMountOpts;
};
};
};
};
};
};
};
};
};
};
};
}

View file

@ -0,0 +1,93 @@
{ lib, config, ... }:
let
cfg = config.aux.system.filesystem.btrfs;
standardMountOpts = [
"compress=zstd"
"discard=async"
"noatime"
];
in
{
options = {
aux.system.filesystem.btrfs = {
enable = lib.mkEnableOption (lib.mdDoc "Enables standard BTRFS subvolumes and parameters.");
devices = {
boot = lib.mkOption {
type = lib.types.str;
description = "The ID of your boot partition. Use /dev/disk/by-uuid for best results.";
default = "";
};
btrfs = lib.mkOption {
type = lib.types.str;
description = "The ID of your BTRFS partition. Use /dev/disk/by-uuid for best results.";
default = "";
};
};
swapFile = {
enable = lib.mkEnableOption (lib.mdDoc "Enables the creation of a swap file.");
size = lib.mkOption {
type = lib.types.int;
description = "The size of the swap file to create in MB (defaults to 8192, or ~8 gigabytes).";
default = 8192;
};
};
};
};
config = lib.mkIf cfg.enable {
# Check for blank parameters
assertions = [
{
assertion = cfg.devices.btrfs != "";
message = "Please specify a BTRFS partition to use as a filesystem.";
}
{
assertion = cfg.devices.boot != "";
message = "Please specify a boot partition to use as a filesystem.";
}
];
fileSystems =
{
"/" = {
device = cfg.devices.btrfs;
fsType = "btrfs";
options = [ "subvol=@" ] ++ standardMountOpts;
};
"/boot" = {
device = cfg.devices.boot;
fsType = "vfat";
};
"/home" = {
device = cfg.devices.btrfs;
fsType = "btrfs";
options = [ "subvol=@home" ] ++ standardMountOpts;
};
"/var/log" = {
device = cfg.devices.btrfs;
fsType = "btrfs";
options = [ "subvol=@log" ] ++ standardMountOpts;
};
"/nix" = {
device = cfg.devices.btrfs;
fsType = "btrfs";
options = [ "subvol=@nix" ] ++ standardMountOpts;
};
}
// lib.optionalAttrs cfg.swapFile.enable {
"/swap" = {
device = cfg.devices.btrfs;
fsType = "btrfs";
options = [ "subvol=@swap" ];
};
};
swapDevices = lib.mkIf cfg.swapFile.enable [
{
device = "/swap/swapfile";
size = cfg.swapFile.size;
}
];
};
}