Write me a NixOS Disko Configuration for a BtrFS File System on a GPT Partition with a…
- User
Write me a NixOS Disko Configuration for a BtrFS File System on a GPT Partition with a 1GB ESP and several subvolumes as you see fit.
- Assistant
Write me a NixOS Disko Configuration for a BtrFS File System on a GPT Partition with a 1GB ESP and several subvolumes as you see fit.
Sure! Below is a NixOS Disko configuration for setting up a Btrfs filesystem on a GPT-partitioned disk with a 1GB EFI System Partition (ESP) and several Btrfs subvolumes. This configuration uses the Disko module to declaratively define the disk partitions and filesystems.
{
# Import the Disko module
imports = [
(builtins.fetchTarball "https://github.com/nix-community/disko/archive/main.tar.gz")
];
config = {
disko = {
# Define the disk to partition
disks = {
"/dev/sda" = {
# Wipe the existing partition table
wipeTable = true;
# Set the partition table type to GPT
tableType = "gpt";
# Define the partitions
partitions = {
# EFI System Partition
esp = {
# Partition type GUID for EFI System Partition
type = "efi";
# Start and size of the partition
start = "1MiB";
size = "1GiB";
# Filesystem details
filesystem = {
format = true;
fsType = "vfat";
mountPoint = "/boot/efi";
label = "ESP";
};
};
# Root partition with Btrfs filesystem
root = {
type = "primary";
# Start at the end of ESP and use the remaining space
start = "1GiB";
end = "100%";
# Filesystem details
filesystem = {
format = true;
fsType = "btrfs";
mountPoint = "/";
# Btrfs-specific options
label = "ROOT";
# Define the Btrfs subvolumes to create
subvolumes = [
"@"
"@home"
"@nix"
"@var"
"@log"
];
};
};
};
};
};
};
# Additional NixOS configurations can be added here
};
}
Imports: We import the Disko module directly from its GitHub repository to use its functionalities within the configuration.
Disk Definition:
/dev/sda as the target disk to partition.wipeTable = true ensures that any existing partition table is wiped before creating the new one.tableType = "gpt" sets the partition table type to GPT.Partition Definitions:
esp partition starting at 1MiB and of size 1GiB."efi" to indicate it's an EFI System Partition.vfat (FAT32), with format = true ensuring it gets formatted./boot/efi, and we label it as "ESP".root partition starts at 1GiB and occupies the rest of the disk (end = "100%").btrfs, with format = true./."ROOT".@, @home, @nix, @var, and @log. These subvolumes are commonly used to separate different parts of the filesystem hierarchy, aiding in snapshot management and system organization.Subvolumes:
subvolumes list under the filesystem definition ensures that these Btrfs subvolumes are created during the formatting process.Mounting Subvolumes:
While the Disko module handles the creation of subvolumes, you should ensure that your NixOS configuration mounts these subvolumes appropriately. This typically involves adding entries in your fileSystems configuration.
For example:
{
fileSystems."/" = {
device = "/dev/disk/by-label/ROOT";
fsType = "btrfs";
options = [ "subvol=@" ];
};
fileSystems."/home" = {
device = "/dev/disk/by-label/ROOT";
fsType = "btrfs";
options = [ "subvol=@home" ];
};
fileSystems."/nix" = {
device = "/dev/disk/by-label/ROOT";
fsType = "btrfs";
options = [ "subvol=@nix" ];
};
fileSystems."/var" = {
device = "/dev/disk/by-label/ROOT";
fsType = "btrfs";
options = [ "subvol=@var" ];
};
fileSystems."/var/log" = {
device = "/dev/disk/by-label/ROOT";
fsType = "btrfs";
options = [ "subvol=@log" ];
};
}
This ensures that each subvolume is mounted at the correct mount point during system boot.
Labels and Device Paths:
"ESP" and "ROOT") allows for stable references to the partitions, even if device paths change.fileSystems configuration, you can reference partitions using /dev/disk/by-label/ paths.Formatting:
format = true option ensures that the partitions are formatted with the specified filesystem type during setup.This configuration provides a solid starting point for setting up a NixOS system with a Btrfs filesystem and appropriate subvolumes. Remember to adjust device paths (/dev/sda) as needed based on your actual hardware configuration. Additionally, ensure that the fileSystems configuration in your main NixOS configuration file properly mounts the subvolumes created by Disko.
Feel free to customize the subvolumes or add additional ones based on your specific requirements.
Not yet included in a published release.