Merge pull request #162 from nix-community/examples-config

This commit is contained in:
Lassulus 2023-04-06 09:48:07 +02:00 committed by GitHub
commit 8891df7029
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
30 changed files with 1170 additions and 1200 deletions

View File

@ -1,3 +1,11 @@
2023-03-22 2624af6
disk config now needs to be inside a disko.devices attrset always
2023-03-22 0577409
the extraArgs option in the luks type was renamed to extraFormatArgs
2023-02-14 6d630b8
btrfs, btrfs_subvol filesystem and lvm_lv extraArgs are now lists

View File

@ -7,9 +7,9 @@ let
eval = cfg: lib.evalModules {
modules = lib.singleton {
# _file = toString input;
imports = lib.singleton { devices = cfg; };
imports = lib.singleton { disko.devices = cfg.disko.devices; };
options = {
devices = lib.mkOption {
disko.devices = lib.mkOption {
type = types.devices;
};
};
@ -18,30 +18,30 @@ let
in
{
types = types;
create = cfg: types.diskoLib.create (eval cfg).config.devices;
create = cfg: types.diskoLib.create (eval cfg).config.disko.devices;
createScript = cfg: pkgs: (types.diskoLib.writeCheckedBash { inherit pkgs checked; }) "disko-create" ''
export PATH=${lib.makeBinPath (types.diskoLib.packages (eval cfg).config.devices pkgs)}:$PATH
${types.diskoLib.create (eval cfg).config.devices}
export PATH=${lib.makeBinPath (types.diskoLib.packages (eval cfg).config.disko.devices pkgs)}:$PATH
${types.diskoLib.create (eval cfg).config.disko.devices}
'';
createScriptNoDeps = cfg: pkgs: (types.diskoLib.writeCheckedBash { inherit pkgs checked; noDeps = true; }) "disko-create" ''
${types.diskoLib.create (eval cfg).config.devices}
${types.diskoLib.create (eval cfg).config.disko.devices}
'';
mount = cfg: types.diskoLib.mount (eval cfg).config.devices;
mount = cfg: types.diskoLib.mount (eval cfg).config.disko.devices;
mountScript = cfg: pkgs: (types.diskoLib.writeCheckedBash { inherit pkgs checked; }) "disko-mount" ''
export PATH=${lib.makeBinPath (types.diskoLib.packages (eval cfg).config.devices pkgs)}:$PATH
${types.diskoLib.mount (eval cfg).config.devices}
export PATH=${lib.makeBinPath (types.diskoLib.packages (eval cfg).config.disko.devices pkgs)}:$PATH
${types.diskoLib.mount (eval cfg).config.disko.devices}
'';
mountScriptNoDeps = cfg: pkgs: (types.diskoLib.writeCheckedBash { inherit pkgs checked; noDeps = true; }) "disko-mount" ''
${types.diskoLib.mount (eval cfg).config.devices}
${types.diskoLib.mount (eval cfg).config.disko.devices}
'';
zapCreateMount = cfg: types.diskoLib.zapCreateMount (eval cfg).config.devices;
zapCreateMount = cfg: types.diskoLib.zapCreateMount (eval cfg).config.disko.devices;
zapCreateMountScript = cfg: pkgs: (types.diskoLib.writeCheckedBash { inherit pkgs checked; }) "disko-zap-create-mount" ''
export PATH=${lib.makeBinPath (types.diskoLib.packages (eval cfg).config.devices pkgs)}:$PATH
${types.diskoLib.zapCreateMount (eval cfg).config.devices}
export PATH=${lib.makeBinPath (types.diskoLib.packages (eval cfg).config.disko.devices pkgs)}:$PATH
${types.diskoLib.zapCreateMount (eval cfg).config.disko.devices}
'';
zapCreateMountScriptNoDeps = cfg: pkgs: (types.diskoLib.writeCheckedBash { inherit pkgs checked; noDeps = true; }) "disko-zap-create-mount" ''
${types.diskoLib.zapCreateMount (eval cfg).config.devices}
${types.diskoLib.zapCreateMount (eval cfg).config.disko.devices}
'';
config = cfg: { imports = types.diskoLib.config (eval cfg).config.devices; };
packages = cfg: types.diskoLib.packages (eval cfg).config.devices;
config = cfg: { imports = types.diskoLib.config (eval cfg).config.disko.devices; };
packages = cfg: types.diskoLib.packages (eval cfg).config.disko.devices;
}

View File

@ -106,10 +106,10 @@ imports =
[ # Include the results of the hardware scan.
./hardware-configuration.nix
"${builtins.fetchTarball "https://github.com/nix-community/disko/archive/master.tar.gz"}/module.nix"
];
disko.devices = pkgs.callPackage ./disko-config.nix {
(import ./disko-config.nix {
disks = [ "/dev/<disk-name>" ]; # replace this with your disk name i.e. /dev/nvme0n1
};
})
];
```
If you went for the hybrid-partition scheme, than choose grub as a bootloader.

View File

@ -1,4 +1,5 @@
{ disks ? [ "/dev/vdb" ], ... }: {
disko.devices = {
disk = {
vdb = {
device = builtins.elemAt disks 0;
@ -35,5 +36,6 @@
};
};
};
};
}

View File

@ -1,4 +1,5 @@
{ disks ? [ "/dev/vdb" "/dev/vdc" ], ... }: {
disko.devices = {
disk = {
one = {
type = "disk";
@ -114,4 +115,5 @@
};
};
};
};
}

View File

@ -1,4 +1,5 @@
{ disks ? [ "/dev/vdb" ], ... }: {
disko.devices = {
disk = {
vdb = {
type = "disk";
@ -48,5 +49,6 @@
};
};
};
};
}

View File

@ -1,4 +1,5 @@
{ disks ? [ "/dev/vdb" "/dev/vdc" "/dev/vdd" ], ... }: {
disko.devices = {
disk = {
disk0 = {
type = "disk";
@ -196,4 +197,5 @@
};
};
};
};
}

View File

@ -1,69 +0,0 @@
# usage: nix-instantiate --eval --json --strict example/config.nix | jq .
{
lvm_vg = {
pool = {
type = "lvm_vg";
lvs = {
root = {
type = "lvm_lv";
size = "10G";
content = {
type = "filesystem";
format = "ext4";
mountpoint = "/";
};
};
home = {
type = "lvm_lv";
size = "10G";
content = {
type = "filesystem";
format = "ext4";
mountpoint = "/home";
};
};
};
};
};
disk = {
sda = {
device = "/dev/sda";
content = {
type = "table";
format = "gpt";
partitions = [
{
name = "ESP";
type = "partition";
start = "1MiB";
end = "1024MiB";
fs-type = "fat32";
bootable = true;
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
};
}
{
name = "crypt_root";
type = "partition";
part-type = "primary";
start = "1024MiB";
end = "100%";
flags = [ "bios_grub" ];
content = {
type = "luks";
name = "crypted";
keyFile = "/tmp/secret.key";
content = {
type = "lvm_pv";
vg = "pool";
};
};
}
];
};
};
};
}

View File

@ -1,5 +1,6 @@
# Example to create a bios compatible gpt partition
{ disks ? [ "/dev/vdb" ], ... }: {
disko.devices = {
disk = {
vdb = {
device = builtins.elemAt disks 0;
@ -34,4 +35,5 @@
};
};
};
};
}

View File

@ -1,5 +1,5 @@
{ disks ? [ "/dev/sda" ], ... }:
{
{ disks ? [ "/dev/sda" ], ... }: {
disko.devices = {
disk.main = {
device = builtins.elemAt disks 0;
type = "disk";
@ -49,4 +49,5 @@
"mode=755"
];
};
};
}

View File

@ -1,5 +1,5 @@
{ disks ? [ "/dev/vda" ], ... }:
{
{ disks ? [ "/dev/vda" ], ... }: {
disko.devices = {
disk = {
main = {
type = "disk";
@ -42,5 +42,6 @@
};
};
};
};
}

View File

@ -1,4 +1,5 @@
{ disks ? [ "/dev/vdb" ], ... }: {
disko.devices = {
disk = {
vdb = {
type = "disk";
@ -74,4 +75,5 @@
};
};
};
};
}

View File

@ -1,4 +1,5 @@
{ disks ? [ "/dev/vdb" "/dev/vdc" ], ... }: {
disko.devices = {
disk = {
one = {
type = "disk";
@ -107,4 +108,5 @@
};
};
};
};
}

View File

@ -1,4 +1,5 @@
{ disks ? [ "/dev/vdb" "/dev/vdc" ], ... }: {
disko.devices = {
disk = {
vdb = {
type = "disk";
@ -80,4 +81,5 @@
};
};
};
};
}

View File

@ -1,4 +1,5 @@
{ disks ? [ "/dev/vdb" "/dev/vdc" ], ... }: {
disko.devices = {
disk = {
disk0 = {
device = builtins.elemAt disks 0;
@ -47,4 +48,5 @@
};
};
};
};
}

View File

@ -1,4 +1,5 @@
{ disks ? [ "/dev/vdb" "/dev/vdc" ], ... }: {
disko.devices = {
disk = {
disk0 = {
device = builtins.elemAt disks 0;
@ -24,4 +25,5 @@
};
};
};
};
}

View File

@ -1,4 +1,5 @@
{ disks ? [ "/dev/vdb" ], ... }: {
disko.devices = {
disk = {
vdb = {
device = builtins.elemAt disks 0;
@ -36,5 +37,6 @@
};
};
};
};
}

View File

@ -14,7 +14,7 @@ let
#}) {
# inherit lib;
#};
cfg = {
cfg.disko.devices = {
disk = {
sda = {
device = "/dev/sda";

View File

@ -1,4 +1,5 @@
{ disks ? [ "/dev/vdb" ], ... }: {
disko.devices = {
disk = {
vdb = {
device = builtins.elemAt disks 0;
@ -46,5 +47,6 @@
};
};
};
};
}

View File

@ -1,4 +1,5 @@
{ disks ? [ "/dev/vdb" ], ... }: {
disko.devices = {
disk = {
vdb = {
device = builtins.elemAt disks 0;
@ -44,5 +45,6 @@
];
};
};
};
}

View File

@ -1,5 +1,6 @@
# Example to create a bios compatible gpt partition
{ disks ? [ "/dev/vdb" ], lib, ... }: {
disko.devices = {
disk = lib.genAttrs [ (lib.head disks) ] (device: {
device = device;
type = "disk";
@ -32,4 +33,5 @@
];
};
});
};
}

View File

@ -1,4 +1,5 @@
{ disks ? [ "/dev/vdb" "/dev/vdc" ], ... }: {
disko.devices = {
disk = {
vdb = {
type = "disk";
@ -62,5 +63,6 @@
};
};
};
};
}

View File

@ -1,4 +1,5 @@
{ disks ? [ "/dev/vdb" "/dev/vdc" ], ... }: {
disko.devices = {
disk = {
x = {
type = "disk";
@ -106,5 +107,6 @@
};
};
};
};
}

View File

@ -18,10 +18,9 @@ makeDiskoTest {
machine.succeed("mountpoint /ext4onzfs");
machine.succeed("mountpoint /ext4_on_lvm");
'';
enableOCR = true;
bootCommands = ''
machine.wait_for_text("[Pp]assphrase for")
machine.send_chars("secretsecret\n")
machine.wait_for_console_text("vda")
machine.send_console("secretsecret\n")
'';
extraConfig = {
boot.kernelModules = [ "dm-raid" "dm-mirror" ];

View File

@ -17,10 +17,9 @@ makeDiskoTest {
machine.succeed("mountpoint /ext4onzfs");
machine.succeed("mountpoint /ext4_on_lvm");
'';
enableOCR = true;
bootCommands = ''
machine.wait_for_text("[Pp]assphrase for")
machine.send_chars("secretsecret\n")
machine.wait_for_console_text("vda")
machine.send_console("secretsecret\n")
'';
extraConfig = {
boot.kernelModules = [ "dm-raid" "dm-mirror" ];

View File

@ -22,8 +22,7 @@ let
(lib.attrNames (builtins.readDir ./.))
);
allTests = lib.genAttrs allTestFilenames (test: import (./. + "/${test}.nix") { inherit makeDiskoTest pkgs; }) //
evalTest "lvm-luks-example" ../example/config.nix // {
allTests = lib.genAttrs allTestFilenames (test: import (./. + "/${test}.nix") { inherit makeDiskoTest pkgs; }) // {
standalone = (pkgs.nixos [ ../example/stand-alone/configuration.nix ]).config.system.build.toplevel;
};
in

View File

@ -30,16 +30,16 @@
tsp-mount = (tsp-generator.mountScript (import disko-config { disks = builtins.tail disks; inherit lib; })) pkgs;
tsp-disko = (tsp-generator.zapCreateMountScript (import disko-config { disks = builtins.tail disks; inherit lib; })) pkgs;
tsp-config = tsp-generator.config (import disko-config { inherit disks; inherit lib; });
num-disks = builtins.length (lib.attrNames (import disko-config { inherit lib; }).disk);
num-disks = builtins.length (lib.attrNames (import disko-config { inherit lib; }).disko.devices.disk);
installed-system = { modulesPath, ... }: {
imports = [
(lib.optionalAttrs (testMode == "direct" || testMode == "cli") tsp-config)
(lib.optionalAttrs (testMode == "module") {
imports = [ ../module.nix ];
disko = {
enableConfig = true;
devices = import disko-config { inherit disks lib; };
};
disko.enableConfig = true;
imports = [
../module.nix
(import disko-config { inherit disks lib; })
];
})
(modulesPath + "/testing/test-instrumentation.nix")
(modulesPath + "/profiles/qemu-guest.nix")
@ -55,7 +55,7 @@
documentation.enable = false;
hardware.enableAllFirmware = lib.mkForce false;
networking.hostId = "8425e349"; # from profiles/base.nix, needed for zfs
boot.kernelParams = lib.mkAfter [ "console=tty0" ]; # needed to have serial interaction during boot
boot.kernelParams = lib.mkIf enableOCR [ "console=tty0" ]; # needed for OCR
boot.zfs.devNodes = "/dev/disk/by-uuid"; # needed because /dev/disk/by-id is empty in qemu-vms
boot.consoleLogLevel = lib.mkForce 100;
@ -77,11 +77,13 @@
nodes.machine = { config, pkgs, modulesPath, ... }: {
imports = [
(lib.optionalAttrs (testMode == "module") {
imports = [ ../module.nix ];
imports = [
../module.nix
];
disko = {
enableConfig = false;
checkScripts = true;
devices = import disko-config { disks = builtins.tail disks; inherit lib; };
devices = (import disko-config { disks = builtins.tail disks; inherit lib; }).disko.devices;
};
})
(lib.optionalAttrs (testMode == "cli") {

View File

@ -8,9 +8,8 @@ makeDiskoTest {
machine.succeed("cryptsetup isLuks /dev/vda2");
machine.succeed("mountpoint /home");
'';
enableOCR = true;
bootCommands = ''
machine.wait_for_text("[Pp]assphrase for")
machine.send_chars("secretsecret\n")
machine.wait_for_console_text("vda")
machine.send_console("secretsecret\n")
'';
}

View File

@ -18,10 +18,9 @@ makeDiskoTest {
machine.succeed("mountpoint /ext4onzfs");
machine.succeed("mountpoint /ext4_on_lvm");
'';
enableOCR = true;
bootCommands = ''
machine.wait_for_text("[Pp]assphrase for")
machine.send_chars("secretsecret\n")
machine.wait_for_console_text("vda")
machine.send_console("secretsecret\n")
'';
extraConfig = {
boot.kernelModules = [ "dm-raid" "dm-mirror" ];

View File

@ -13,7 +13,7 @@ makeDiskoTest {
'';
enableOCR = true;
bootCommands = ''
machine.wait_for_text("(?:passphrase|key) for")
machine.wait_for_text("passphrase for")
machine.send_chars("secretsecret\n")
'';
extraTestScript = ''