Disko: Difference between revisions
imported>Onny mNo edit summary |
imported>Onny Add configuration section |
||
Line 67: | Line 67: | ||
# mount | grep /mnt | # mount | grep /mnt | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== Configuration == | |||
In case the NixOS base system was installed on a partition layout bootstrapped with Disko, the disk config itself can be integrated into the system. First copy the the file, for example <code>disko-config.nix</code> into your system configuration directory | |||
<syntaxhighlight lang="console"> | |||
# cp disko-config.nix /etc/nixos/ | |||
</syntaxhighlight> | |||
Enable the Disko module on a flake-enabled system. Add the required input and reference it and your <code>disko-config.nix</code> in the modules section. For alternative installation methods consult the Disko [https://github.com/nix-community/disko/blob/master/docs/quickstart.md quickstart guide]. | |||
{{file|/etc/nixos/flake.nix|nix|<nowiki> | |||
{ | |||
inputs = { | |||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05"; | |||
disko.url = "github:nix-community/disko"; | |||
disko.inputs.nixpkgs.follows = "nixpkgs"; | |||
}; | |||
outputs = {self, nixpkgs, disko, ...}@inputs: { | |||
nixosConfigurations.mysystem = inputs.nixpkgs.lib.nixosSystem { | |||
system = "x86_64-linux"; | |||
specialArgs.inputs = inputs; | |||
modules = [ | |||
disko.nixosModules.disko | |||
./disko-config.nix | |||
{ | |||
_module.args.disks = [ "/dev/vda" ]; | |||
} | |||
./configuration.nix | |||
]; | |||
}; | |||
}; | |||
} | |||
</nowiki>}} | |||
Ensure that there are no automatically generated entries of <code>fileSystems</code> options in <code>/etc/nixos/hardware-configuration.nix</code>. Disko will automatically generate them for you. Rebuild your system to apply the Disko configuration. | |||
[[Category:Filesystem]] | [[Category:Filesystem]] |
Revision as of 07:44, 31 May 2023
Disko is a utility and NixOS module for declarative disk partitioning.
Usage
The following example creates a new GPT partition table for the disk /dev/vda
including two partitions for EFI boot and a bcachefs root filesystem.
disko-config.nix
{ disks ? [ "/dev/vda" ], ... }: {
disko.devices = {
disk = {
vdb = {
device = builtins.elemAt disks 0;
type = "disk";
content = {
type = "table";
format = "gpt";
partitions = [
{
name = "ESP";
start = "1MiB";
end = "500MiB";
bootable = true;
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
};
}
{
name = "root";
start = "500MiB";
end = "100%";
part-type = "primary";
content = {
type = "filesystem";
format = "bcachefs";
mountpoint = "/";
};
}
];
};
};
};
};
}
The following command will apply the disk layout specified in the configuration and mount them afterwards. Warning: This will erase all data on the disk.
# sudo nix run github:nix-community/disko -- --mode zap_create_mount ./disko-config.nix
Alternativley use a disk layout configuration of a remote repository containing a flake.nix
file as an entry point. The --arg
parameter specifies the target disk /dev/sda
.
# sudo nix run github:nix-community/disko -- --mode zap_create_mount --flake github:Lassulus/flakes-testing#fnord --arg disks '[ "/dev/sda" ]'
The commands above requires Flake features available on your system.
To verify both partitions got mounted correctly, run
# mount | grep /mnt
Configuration
In case the NixOS base system was installed on a partition layout bootstrapped with Disko, the disk config itself can be integrated into the system. First copy the the file, for example disko-config.nix
into your system configuration directory
# cp disko-config.nix /etc/nixos/
Enable the Disko module on a flake-enabled system. Add the required input and reference it and your disko-config.nix
in the modules section. For alternative installation methods consult the Disko quickstart guide.
/etc/nixos/flake.nix
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05";
disko.url = "github:nix-community/disko";
disko.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = {self, nixpkgs, disko, ...}@inputs: {
nixosConfigurations.mysystem = inputs.nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
specialArgs.inputs = inputs;
modules = [
disko.nixosModules.disko
./disko-config.nix
{
_module.args.disks = [ "/dev/vda" ];
}
./configuration.nix
];
};
};
}
Ensure that there are no automatically generated entries of fileSystems
options in /etc/nixos/hardware-configuration.nix
. Disko will automatically generate them for you. Rebuild your system to apply the Disko configuration.