Add disko variant for drive configuration
This commit is contained in:
parent
547ea3e7bb
commit
ae8fb25102
3 changed files with 228 additions and 77 deletions
|
|
@ -33,6 +33,7 @@
|
||||||
|
|
||||||
stylix.url = "github:danth/stylix";
|
stylix.url = "github:danth/stylix";
|
||||||
base16.url = "github:SenchoPens/base16.nix";
|
base16.url = "github:SenchoPens/base16.nix";
|
||||||
|
disko.url = "github:nix-community/disko/latest";
|
||||||
|
|
||||||
anyrun.url = "github:Kirottu/anyrun";
|
anyrun.url = "github:Kirottu/anyrun";
|
||||||
oxicalc.url = "github:DashieTM/OxiCalc";
|
oxicalc.url = "github:DashieTM/OxiCalc";
|
||||||
|
|
@ -80,7 +81,8 @@
|
||||||
};
|
};
|
||||||
overlays = [
|
overlays = [
|
||||||
inputs.nur.overlays.default
|
inputs.nur.overlays.default
|
||||||
inputs.chaoticNyx.overlays.default];
|
inputs.chaoticNyx.overlays.default
|
||||||
|
];
|
||||||
};
|
};
|
||||||
pkgs = import inputs.nixpkgs {
|
pkgs = import inputs.nixpkgs {
|
||||||
system = currentSystem;
|
system = currentSystem;
|
||||||
|
|
@ -94,7 +96,7 @@
|
||||||
overlays = [
|
overlays = [
|
||||||
inputs.nur.overlays.default
|
inputs.nur.overlays.default
|
||||||
inputs.chaoticNyx.overlays.default
|
inputs.chaoticNyx.overlays.default
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
in rec {
|
in rec {
|
||||||
dashNixLib = import ./lib {
|
dashNixLib = import ./lib {
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,7 @@
|
||||||
nixos = [
|
nixos = [
|
||||||
inputs.home-manager.nixosModules.home-manager
|
inputs.home-manager.nixosModules.home-manager
|
||||||
inputs.stylix.nixosModules.stylix
|
inputs.stylix.nixosModules.stylix
|
||||||
|
inputs.disko.nixosModules.disko
|
||||||
../base
|
../base
|
||||||
../home
|
../home
|
||||||
../modules
|
../modules
|
||||||
|
|
|
||||||
|
|
@ -3,87 +3,151 @@
|
||||||
config,
|
config,
|
||||||
options,
|
options,
|
||||||
...
|
...
|
||||||
}: let
|
}: {
|
||||||
driveModule = lib.types.submodule {
|
options.mods.drives = {
|
||||||
options = {
|
variant = lib.mkOption {
|
||||||
name = lib.mkOption {
|
default = "manual";
|
||||||
type = lib.types.str;
|
example = "disko";
|
||||||
|
type = with lib.types; (enum [
|
||||||
|
"manual"
|
||||||
|
"disko"
|
||||||
|
]);
|
||||||
|
description = ''
|
||||||
|
Disk configuration type, either "manual" for regular NixOS disk configuration,
|
||||||
|
or "disko" for using disko to automatically format your drives.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
useSwap = lib.mkOption {
|
||||||
|
default = true;
|
||||||
|
example = false;
|
||||||
|
type = lib.types.bool;
|
||||||
|
description = ''
|
||||||
|
Use swap in drive.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
homeAndRootFsTypes = lib.mkOption {
|
||||||
|
default = "ext4";
|
||||||
|
example = "btrfs";
|
||||||
|
type = with lib.types; (enum [
|
||||||
|
"btrfs"
|
||||||
|
"ext2"
|
||||||
|
"ext3"
|
||||||
|
"ext4"
|
||||||
|
"exfat"
|
||||||
|
"f2fs"
|
||||||
|
"fat8"
|
||||||
|
"fat16"
|
||||||
|
"fat32"
|
||||||
|
"ntfs"
|
||||||
|
"xfs"
|
||||||
|
"zfs"
|
||||||
|
]);
|
||||||
|
description = ''
|
||||||
|
Filesystem for the home and root partitions.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
defaultDrives = {
|
||||||
|
enable = lib.mkOption {
|
||||||
|
default = true;
|
||||||
|
example = false;
|
||||||
|
type = lib.types.bool;
|
||||||
description = ''
|
description = ''
|
||||||
The path of the drive.
|
Use default drive config.
|
||||||
Note that a / is already added at the beginning.
|
|
||||||
|
## Manual variant
|
||||||
|
This config expects 4 different partitions on a single drive:
|
||||||
|
- boot partition with "BOOT" label and vfat format (filesystem configurable)
|
||||||
|
- swap partition with "SWAP" label
|
||||||
|
- root partition with "ROOT" label and ext4 format (filesystem configurable)
|
||||||
|
- home partition with "HOME" label and ext4 format (filesystem configurable)
|
||||||
|
- gpt disk format
|
||||||
|
NOTE: Any different configuration must be done manually with this turned off.
|
||||||
|
|
||||||
|
## Disko variant
|
||||||
|
This config creates 4 different partitions on a single drive:
|
||||||
|
- boot partition with 1GB size and vfat format
|
||||||
|
- swap partition with 32GB (size configurable)
|
||||||
|
- root partition with 30% size and ext4 format (size and filesystem configurable)
|
||||||
|
- home partition with 70%~ size and ext4 format (size and filesystem configurable)
|
||||||
|
- gpt disk format
|
||||||
|
NOTE: Any different configuration must be done manually with this turned off.
|
||||||
'';
|
'';
|
||||||
default = "";
|
|
||||||
example = "drive2";
|
|
||||||
};
|
|
||||||
drive = lib.mkOption {
|
|
||||||
type = lib.types.attrsOf lib.types.anything;
|
|
||||||
description = "The attrs of the drive";
|
|
||||||
default = {};
|
|
||||||
example = {
|
|
||||||
device = "/dev/disk/by-label/DRIVE2";
|
|
||||||
fsType = "ext4";
|
|
||||||
options = [
|
|
||||||
"noatime"
|
|
||||||
"nodiratime"
|
|
||||||
"discard"
|
|
||||||
];
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
extraDrives = lib.mkOption {
|
||||||
in {
|
default = [
|
||||||
options.mods = {
|
];
|
||||||
drives = {
|
example = [
|
||||||
useSwap = {
|
{
|
||||||
enable = lib.mkOption {
|
name = "drive2";
|
||||||
default = true;
|
drive = {
|
||||||
example = false;
|
device = "/dev/disk/by-label/DRIVE2";
|
||||||
type = lib.types.bool;
|
fsType = "ext4";
|
||||||
description = ''
|
options = [
|
||||||
Use default drive config
|
"noatime"
|
||||||
'';
|
"nodiratime"
|
||||||
};
|
"discard"
|
||||||
};
|
];
|
||||||
defaultDrives = {
|
};
|
||||||
enable = lib.mkOption {
|
}
|
||||||
default = true;
|
];
|
||||||
example = false;
|
type = with lib.types; listOf (attrsOf anything);
|
||||||
type = lib.types.bool;
|
description = ''
|
||||||
description = ''
|
Extra drives to add.
|
||||||
Use default drive config
|
Please ensure to add variant compliant attrsets (manual/disko).
|
||||||
'';
|
(The example is for manual variant, here an example for disko):
|
||||||
};
|
```nix
|
||||||
};
|
drive2 = (lib.optionalAttrs config.mods.drives.defaultDrives.enable) {
|
||||||
extraDrives = lib.mkOption {
|
device = "/dev/nvme1n1"
|
||||||
default = [
|
type = "disk";
|
||||||
];
|
content = {
|
||||||
example = [
|
type = "gpt";
|
||||||
{
|
partitions = {
|
||||||
name = "drive2";
|
drive2 = {
|
||||||
drive = {
|
start = "0%";
|
||||||
device = "/dev/disk/by-label/DRIVE2";
|
end = "100%";
|
||||||
fsType = "ext4";
|
content = {
|
||||||
options = [
|
type = "filesystem";
|
||||||
"noatime"
|
format = "ext4";
|
||||||
"nodiratime"
|
mountpoint = "/drive2";
|
||||||
"discard"
|
mountOptions = [
|
||||||
];
|
"noatime"
|
||||||
|
"nodiratime"
|
||||||
|
"discard"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
};
|
||||||
];
|
```
|
||||||
# TODO: how to make this work
|
'';
|
||||||
# type = with lib.types; listOf (attrsOf driveModule);
|
};
|
||||||
type = with lib.types; listOf (attrsOf anything);
|
disko = {
|
||||||
description = ''
|
defaultDiskId = lib.mkOption {
|
||||||
Extra drives to add.
|
default = "TODO";
|
||||||
'';
|
example = "/dev/nvme0n1";
|
||||||
|
type = lib.types.string;
|
||||||
|
description = "The name, ID, UUID or similar for the default drive.";
|
||||||
|
};
|
||||||
|
rootAmount = lib.mkOption {
|
||||||
|
default = 70;
|
||||||
|
example = 60;
|
||||||
|
type = lib.types.number;
|
||||||
|
description = "The percentage of the disk for root. (Home will take up the rest) (Only for disko)";
|
||||||
|
};
|
||||||
|
swapAmount = lib.mkOption {
|
||||||
|
default = 32;
|
||||||
|
example = 64;
|
||||||
|
type = lib.types.number;
|
||||||
|
description = "The amount of swap to use. (Only for disko)";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = (
|
config = (
|
||||||
lib.optionalAttrs (options ? fileSystems) {
|
lib.optionalAttrs (options ? fileSystems) {
|
||||||
fileSystems =
|
fileSystems = lib.mkIf (config.mods.drives.variant == "manual") (
|
||||||
builtins.listToAttrs (
|
builtins.listToAttrs (
|
||||||
map (
|
map (
|
||||||
{
|
{
|
||||||
|
|
@ -99,7 +163,7 @@ in {
|
||||||
// (lib.optionalAttrs config.mods.drives.defaultDrives.enable) {
|
// (lib.optionalAttrs config.mods.drives.defaultDrives.enable) {
|
||||||
"/" = {
|
"/" = {
|
||||||
device = "/dev/disk/by-label/ROOT";
|
device = "/dev/disk/by-label/ROOT";
|
||||||
fsType = "btrfs";
|
fsType = config.mods.drives.homeAndRootFsTypes;
|
||||||
options = [
|
options = [
|
||||||
"noatime"
|
"noatime"
|
||||||
"nodiratime"
|
"nodiratime"
|
||||||
|
|
@ -120,18 +184,102 @@ in {
|
||||||
|
|
||||||
"/home" = {
|
"/home" = {
|
||||||
device = "/dev/disk/by-label/HOME";
|
device = "/dev/disk/by-label/HOME";
|
||||||
fsType = "btrfs";
|
fsType = config.mods.drives.homeAndRootFsTypes;
|
||||||
options = [
|
options = [
|
||||||
"noatime"
|
"noatime"
|
||||||
"nodiratime"
|
"nodiratime"
|
||||||
"discard"
|
"discard"
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
# TODO make this convert to choice of drives -> thanks to funny types this doesn't work...
|
);
|
||||||
swapDevices = lib.mkIf config.mods.drives.useSwap.enable [
|
|
||||||
|
swapDevices = lib.mkIf (config.mods.drives.useSwap && config.mods.drives.variant == "manual") [
|
||||||
{device = "/dev/disk/by-label/SWAP";}
|
{device = "/dev/disk/by-label/SWAP";}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
disko.devices = lib.mkIf (config.mods.drives.variant == "disko") {
|
||||||
|
disk =
|
||||||
|
{
|
||||||
|
main = (lib.optionalAttrs config.mods.drives.defaultDrives.enable) {
|
||||||
|
device = "${config.mods.drives.disko.defaultDiskId}";
|
||||||
|
type = "disk";
|
||||||
|
content = {
|
||||||
|
type = "gpt";
|
||||||
|
partitions = {
|
||||||
|
root = {
|
||||||
|
start = "${
|
||||||
|
if config.mods.drives.useSwap
|
||||||
|
then builtins.toString config.mods.drives.disko.swapAmount
|
||||||
|
else builtins.toString 1
|
||||||
|
}G";
|
||||||
|
end = "${builtins.toString config.mods.drives.disko.rootAmount}%";
|
||||||
|
content = {
|
||||||
|
type = "filesystem";
|
||||||
|
format = config.mods.drives.homeAndRootFsTypes;
|
||||||
|
mountpoint = "/";
|
||||||
|
mountOptions = [
|
||||||
|
"noatime"
|
||||||
|
"nodiratime"
|
||||||
|
"discard"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
plainSwap = {
|
||||||
|
start = "1G";
|
||||||
|
end = "33G";
|
||||||
|
content = {
|
||||||
|
type = "swap";
|
||||||
|
discardPolicy = "both";
|
||||||
|
resumeDevice = true;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
boot = {
|
||||||
|
start = "0G";
|
||||||
|
end = "1G";
|
||||||
|
content = {
|
||||||
|
type = "filesystem";
|
||||||
|
format = "vfat";
|
||||||
|
mountpoint = "/boot";
|
||||||
|
mountOptions = [
|
||||||
|
"rw"
|
||||||
|
"fmask=0022"
|
||||||
|
"dmask=0022"
|
||||||
|
"noatime"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
home = {
|
||||||
|
start = "${builtins.toString config.mods.drives.disko.rootAmount}%";
|
||||||
|
end = "100%";
|
||||||
|
content = {
|
||||||
|
type = "filesystem";
|
||||||
|
format = config.mods.drives.homeAndRootFsTypes;
|
||||||
|
mountpoint = "/home";
|
||||||
|
mountOptions = [
|
||||||
|
"noatime"
|
||||||
|
"nodiratime"
|
||||||
|
"discard"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
// builtins.listToAttrs (
|
||||||
|
map (
|
||||||
|
{
|
||||||
|
name,
|
||||||
|
drive,
|
||||||
|
}: {
|
||||||
|
name = "/" + name;
|
||||||
|
value = drive;
|
||||||
|
}
|
||||||
|
)
|
||||||
|
config.mods.drives.extraDrives
|
||||||
|
);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue