mirror of
https://github.com/nix-community/disko.git
synced 2026-12-02 14:03:28 +01:00
apply treefmt
This commit is contained in:
1 parent
049d1bd952
commit
b32f0e2876
15 files changed
+279
-257
No files matched your search
+1
-1
@@ -33,7 +33,7 @@
|
|||||||
type = "luks";
|
type = "luks";
|
||||||
name = "crypted1";
|
name = "crypted1";
|
||||||
settings.keyFile = "/tmp/secret.key";
|
settings.keyFile = "/tmp/secret.key";
|
||||||
additionalKeyFiles = ["/tmp/additionalSecret.key"];
|
additionalKeyFiles = [ "/tmp/additionalSecret.key" ];
|
||||||
extraFormatArgs = [
|
extraFormatArgs = [
|
||||||
"--iter-time 1" # unsecure but fast for tests
|
"--iter-time 1" # unsecure but fast for tests
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
label = "EFI";
|
label = "EFI";
|
||||||
name = "ESP";
|
name = "ESP";
|
||||||
size = "512M";
|
size = "512M";
|
||||||
type = "EF00" ;
|
type = "EF00";
|
||||||
content = {
|
content = {
|
||||||
type = "filesystem";
|
type = "filesystem";
|
||||||
format = "vfat";
|
format = "vfat";
|
||||||
@@ -31,7 +31,7 @@
|
|||||||
# for example use `echo -n "password" > /tmp/secret.key`
|
# for example use `echo -n "password" > /tmp/secret.key`
|
||||||
#keyFile = "/tmp/secret.key"; # Interactive
|
#keyFile = "/tmp/secret.key"; # Interactive
|
||||||
settings.keyFile = "/tmp/secret.key";
|
settings.keyFile = "/tmp/secret.key";
|
||||||
additionalKeyFiles = ["/tmp/additionalSecret.key"];
|
additionalKeyFiles = [ "/tmp/additionalSecret.key" ];
|
||||||
content = {
|
content = {
|
||||||
type = "btrfs";
|
type = "btrfs";
|
||||||
extraArgs = [ "-f" ];
|
extraArgs = [ "-f" ];
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
# if you want to use the key for interactive login be sure there is no trailing newline
|
# if you want to use the key for interactive login be sure there is no trailing newline
|
||||||
# for example use `echo -n "password" > /tmp/secret.key`
|
# for example use `echo -n "password" > /tmp/secret.key`
|
||||||
settings.keyFile = "/tmp/secret.key";
|
settings.keyFile = "/tmp/secret.key";
|
||||||
additionalKeyFiles = ["/tmp/additionalSecret.key"];
|
additionalKeyFiles = [ "/tmp/additionalSecret.key" ];
|
||||||
content = {
|
content = {
|
||||||
type = "lvm_pv";
|
type = "lvm_pv";
|
||||||
vg = "pool";
|
vg = "pool";
|
||||||
|
|||||||
@@ -46,7 +46,7 @@
|
|||||||
type = "luks";
|
type = "luks";
|
||||||
name = "crypted";
|
name = "crypted";
|
||||||
settings.keyFile = "/tmp/secret.key";
|
settings.keyFile = "/tmp/secret.key";
|
||||||
content= {
|
content = {
|
||||||
type = "filesystem";
|
type = "filesystem";
|
||||||
format = "ext4";
|
format = "ext4";
|
||||||
mountpoint = "/";
|
mountpoint = "/";
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
{ ... }: {
|
{
|
||||||
disko.devices = {
|
disko.devices = {
|
||||||
disk = {
|
disk = {
|
||||||
vdb = {
|
vdb = {
|
||||||
|
|||||||
+1
-1
@@ -29,7 +29,7 @@
|
|||||||
content = {
|
content = {
|
||||||
type = "swap";
|
type = "swap";
|
||||||
randomEncryption = true;
|
randomEncryption = true;
|
||||||
resumeDevice = true; # resume from hiberation from this device
|
resumeDevice = true; # resume from hiberation from this device
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
+179
-172
@@ -23,10 +23,12 @@ let
|
|||||||
name = "subType";
|
name = "subType";
|
||||||
description = "one of ${concatStringsSep "," (attrNames types)}";
|
description = "one of ${concatStringsSep "," (attrNames types)}";
|
||||||
check = x: if x ? type then types.${x.type}.check x else throw "No type option set in:\n${generators.toPretty {} x}";
|
check = x: if x ? type then types.${x.type}.check x else throw "No type option set in:\n${generators.toPretty {} x}";
|
||||||
merge = loc: foldl' (res: def: types.${def.value.type}.merge loc [
|
merge = loc: foldl'
|
||||||
# we add a dummy root parent node to render documentation
|
(res: def: types.${def.value.type}.merge loc [
|
||||||
(lib.recursiveUpdate { value._module.args = extraArgs; } def)
|
# we add a dummy root parent node to render documentation
|
||||||
]) { };
|
(lib.recursiveUpdate { value._module.args = extraArgs; } def)
|
||||||
|
])
|
||||||
|
{ };
|
||||||
nestedTypes = types;
|
nestedTypes = types;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -108,7 +110,7 @@ let
|
|||||||
else
|
else
|
||||||
iter (index + 1) (tail list);
|
iter (index + 1) (tail list);
|
||||||
in
|
in
|
||||||
iter 1 list;
|
iter 1 list;
|
||||||
|
|
||||||
|
|
||||||
/* indent takes a multiline string and indents it by 2 spaces starting on the second line
|
/* indent takes a multiline string and indents it by 2 spaces starting on the second line
|
||||||
@@ -119,7 +121,7 @@ let
|
|||||||
indent "test\nbla"
|
indent "test\nbla"
|
||||||
=> "test\n bla"
|
=> "test\n bla"
|
||||||
*/
|
*/
|
||||||
indent = replaceStrings ["\n"] ["\n "];
|
indent = replaceStrings [ "\n" ] [ "\n " ];
|
||||||
|
|
||||||
/* A nix option type representing a json datastructure, vendored from nixpkgs to avoid dependency on pkgs */
|
/* A nix option type representing a json datastructure, vendored from nixpkgs to avoid dependency on pkgs */
|
||||||
jsonType =
|
jsonType =
|
||||||
@@ -280,10 +282,10 @@ let
|
|||||||
zapCreateMount :: lib.types.devices -> str
|
zapCreateMount :: lib.types.devices -> str
|
||||||
*/
|
*/
|
||||||
zapCreateMount = toplevel:
|
zapCreateMount = toplevel:
|
||||||
''
|
''
|
||||||
set -efux
|
set -efux
|
||||||
${toplevel._disko}
|
${toplevel._disko}
|
||||||
'';
|
'';
|
||||||
/* Takes a disko device specification and returns a nixos configuration
|
/* Takes a disko device specification and returns a nixos configuration
|
||||||
|
|
||||||
config :: lib.types.devices -> nixosConfig
|
config :: lib.types.devices -> nixosConfig
|
||||||
@@ -328,180 +330,185 @@ let
|
|||||||
|
|
||||||
/* topLevel type of the disko config, takes attrsets of disks, mdadms, zpools, nodevs, and lvm vgs.
|
/* topLevel type of the disko config, takes attrsets of disks, mdadms, zpools, nodevs, and lvm vgs.
|
||||||
*/
|
*/
|
||||||
toplevel = lib.types.submodule (cfg: let
|
toplevel = lib.types.submodule (cfg:
|
||||||
devices = { inherit (cfg.config) disk mdadm zpool lvm_vg nodev; };
|
let
|
||||||
in {
|
devices = { inherit (cfg.config) disk mdadm zpool lvm_vg nodev; };
|
||||||
options = {
|
in
|
||||||
disk = lib.mkOption {
|
{
|
||||||
type = lib.types.attrsOf diskoLib.types.disk;
|
options = {
|
||||||
default = { };
|
disk = lib.mkOption {
|
||||||
description = "Block device";
|
type = lib.types.attrsOf diskoLib.types.disk;
|
||||||
};
|
default = { };
|
||||||
mdadm = lib.mkOption {
|
description = "Block device";
|
||||||
type = lib.types.attrsOf diskoLib.types.mdadm;
|
};
|
||||||
default = { };
|
mdadm = lib.mkOption {
|
||||||
description = "mdadm device";
|
type = lib.types.attrsOf diskoLib.types.mdadm;
|
||||||
};
|
default = { };
|
||||||
zpool = lib.mkOption {
|
description = "mdadm device";
|
||||||
type = lib.types.attrsOf diskoLib.types.zpool;
|
};
|
||||||
default = { };
|
zpool = lib.mkOption {
|
||||||
description = "ZFS pool device";
|
type = lib.types.attrsOf diskoLib.types.zpool;
|
||||||
};
|
default = { };
|
||||||
lvm_vg = lib.mkOption {
|
description = "ZFS pool device";
|
||||||
type = lib.types.attrsOf diskoLib.types.lvm_vg;
|
};
|
||||||
default = { };
|
lvm_vg = lib.mkOption {
|
||||||
description = "LVM VG device";
|
type = lib.types.attrsOf diskoLib.types.lvm_vg;
|
||||||
};
|
default = { };
|
||||||
nodev = lib.mkOption {
|
description = "LVM VG device";
|
||||||
type = lib.types.attrsOf diskoLib.types.nodev;
|
};
|
||||||
default = { };
|
nodev = lib.mkOption {
|
||||||
description = "A non-block device";
|
type = lib.types.attrsOf diskoLib.types.nodev;
|
||||||
};
|
default = { };
|
||||||
_meta = lib.mkOption {
|
description = "A non-block device";
|
||||||
internal = true;
|
};
|
||||||
description = ''
|
_meta = lib.mkOption {
|
||||||
meta informationen generated by disko
|
internal = true;
|
||||||
currently used for building a dependency list so we know in which order to create the devices
|
description = ''
|
||||||
'';
|
meta informationen generated by disko
|
||||||
default = diskoLib.deepMergeMap (dev: dev._meta) (flatten (map attrValues (attrValues devices)));
|
currently used for building a dependency list so we know in which order to create the devices
|
||||||
};
|
|
||||||
_packages = lib.mkOption {
|
|
||||||
internal = true;
|
|
||||||
description = ''
|
|
||||||
packages required by the disko configuration
|
|
||||||
'';
|
|
||||||
default = pkgs: unique (flatten (map (dev: dev._pkgs pkgs) (flatten (map attrValues (attrValues devices)))));
|
|
||||||
};
|
|
||||||
_scripts = lib.mkOption {
|
|
||||||
internal = true;
|
|
||||||
description = ''
|
|
||||||
The scripts generated by disko
|
|
||||||
'';
|
|
||||||
default = { pkgs, checked ? false }: {
|
|
||||||
destroyScript = (diskoLib.writeCheckedBash { inherit pkgs checked; }) "disko-destroy" ''
|
|
||||||
export PATH=${lib.makeBinPath (with pkgs; [
|
|
||||||
util-linux
|
|
||||||
e2fsprogs
|
|
||||||
mdadm
|
|
||||||
zfs
|
|
||||||
lvm2
|
|
||||||
bash
|
|
||||||
jq
|
|
||||||
])}:$PATH
|
|
||||||
${cfg.config._destroy}
|
|
||||||
'';
|
'';
|
||||||
|
default = diskoLib.deepMergeMap (dev: dev._meta) (flatten (map attrValues (attrValues devices)));
|
||||||
formatScript = (diskoLib.writeCheckedBash { inherit pkgs checked; }) "disko-format" ''
|
};
|
||||||
export PATH=${lib.makeBinPath (cfg.config._packages pkgs)}:$PATH
|
_packages = lib.mkOption {
|
||||||
${cfg.config._create}
|
internal = true;
|
||||||
|
description = ''
|
||||||
|
packages required by the disko configuration
|
||||||
'';
|
'';
|
||||||
|
default = pkgs: unique (flatten (map (dev: dev._pkgs pkgs) (flatten (map attrValues (attrValues devices)))));
|
||||||
mountScript = (diskoLib.writeCheckedBash { inherit pkgs checked; }) "disko-mount" ''
|
};
|
||||||
export PATH=${lib.makeBinPath (cfg.config._packages pkgs)}:$PATH
|
_scripts = lib.mkOption {
|
||||||
${cfg.config._mount}
|
internal = true;
|
||||||
|
description = ''
|
||||||
|
The scripts generated by disko
|
||||||
'';
|
'';
|
||||||
|
default = { pkgs, checked ? false }: {
|
||||||
|
destroyScript = (diskoLib.writeCheckedBash { inherit pkgs checked; }) "disko-destroy" ''
|
||||||
|
export PATH=${lib.makeBinPath (with pkgs; [
|
||||||
|
util-linux
|
||||||
|
e2fsprogs
|
||||||
|
mdadm
|
||||||
|
zfs
|
||||||
|
lvm2
|
||||||
|
bash
|
||||||
|
jq
|
||||||
|
])}:$PATH
|
||||||
|
${cfg.config._destroy}
|
||||||
|
'';
|
||||||
|
|
||||||
diskoScript = (diskoLib.writeCheckedBash { inherit pkgs checked; }) "disko" ''
|
formatScript = (diskoLib.writeCheckedBash { inherit pkgs checked; }) "disko-format" ''
|
||||||
export PATH=${lib.makeBinPath ((cfg.config._packages pkgs) ++ [ pkgs.bash ])}:$PATH
|
export PATH=${lib.makeBinPath (cfg.config._packages pkgs)}:$PATH
|
||||||
${cfg.config._disko}
|
${cfg.config._create}
|
||||||
|
'';
|
||||||
|
|
||||||
|
mountScript = (diskoLib.writeCheckedBash { inherit pkgs checked; }) "disko-mount" ''
|
||||||
|
export PATH=${lib.makeBinPath (cfg.config._packages pkgs)}:$PATH
|
||||||
|
${cfg.config._mount}
|
||||||
|
'';
|
||||||
|
|
||||||
|
diskoScript = (diskoLib.writeCheckedBash { inherit pkgs checked; }) "disko" ''
|
||||||
|
export PATH=${lib.makeBinPath ((cfg.config._packages pkgs) ++ [ pkgs.bash ])}:$PATH
|
||||||
|
${cfg.config._disko}
|
||||||
|
'';
|
||||||
|
|
||||||
|
# These are useful to skip copying executables uploading a script to an in-memory installer
|
||||||
|
destroyScriptNoDeps = (diskoLib.writeCheckedBash { inherit pkgs checked; noDeps = true; }) "disko-destroy" ''
|
||||||
|
${cfg.config._destroy}
|
||||||
|
'';
|
||||||
|
|
||||||
|
formatScriptNoDeps = (diskoLib.writeCheckedBash { inherit pkgs checked; noDeps = true; }) "disko-format" ''
|
||||||
|
${cfg.config._create}
|
||||||
|
'';
|
||||||
|
|
||||||
|
mountScriptNoDeps = (diskoLib.writeCheckedBash { inherit pkgs checked; noDeps = true; }) "disko-mount" ''
|
||||||
|
${cfg.config._mount}
|
||||||
|
'';
|
||||||
|
|
||||||
|
diskoScriptNoDeps = (diskoLib.writeCheckedBash { inherit pkgs checked; noDeps = true; }) "disko" ''
|
||||||
|
${cfg.config._disko}
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
_destroy = lib.mkOption {
|
||||||
|
internal = true;
|
||||||
|
type = lib.types.str;
|
||||||
|
description = ''
|
||||||
|
The script to unmount (& destroy) all devices defined by disko.devices
|
||||||
'';
|
'';
|
||||||
|
default = ''
|
||||||
|
umount -Rv "${rootMountPoint}" || :
|
||||||
|
|
||||||
# These are useful to skip copying executables uploading a script to an in-memory installer
|
# shellcheck disable=SC2043
|
||||||
destroyScriptNoDeps = (diskoLib.writeCheckedBash { inherit pkgs checked; noDeps = true; }) "disko-destroy" ''
|
for dev in ${toString (lib.catAttrs "device" (lib.attrValues devices.disk))}; do
|
||||||
${cfg.config._destroy}
|
${../disk-deactivate}/disk-deactivate "$dev" | bash -x
|
||||||
'';
|
done
|
||||||
|
|
||||||
formatScriptNoDeps = (diskoLib.writeCheckedBash { inherit pkgs checked; noDeps = true; }) "disko-format" ''
|
|
||||||
${cfg.config._create}
|
|
||||||
'';
|
|
||||||
|
|
||||||
mountScriptNoDeps = (diskoLib.writeCheckedBash { inherit pkgs checked; noDeps = true; }) "disko-mount" ''
|
|
||||||
${cfg.config._mount}
|
|
||||||
'';
|
|
||||||
|
|
||||||
diskoScriptNoDeps = (diskoLib.writeCheckedBash { inherit pkgs checked; noDeps = true; }) "disko" ''
|
|
||||||
${cfg.config._disko}
|
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
_create = lib.mkOption {
|
||||||
_destroy = lib.mkOption {
|
internal = true;
|
||||||
internal = true;
|
type = lib.types.str;
|
||||||
type = lib.types.str;
|
description = ''
|
||||||
description = ''
|
The script to create all devices defined by disko.devices
|
||||||
The script to unmount (& destroy) all devices defined by disko.devices
|
'';
|
||||||
'';
|
default =
|
||||||
default = ''
|
let
|
||||||
umount -Rv "${rootMountPoint}" || :
|
sortedDeviceList = diskoLib.sortDevicesByDependencies (cfg.config._meta.deviceDependencies or { }) devices;
|
||||||
|
in
|
||||||
|
''
|
||||||
|
set -efux
|
||||||
|
|
||||||
# shellcheck disable=SC2043
|
disko_devices_dir=$(mktemp -d)
|
||||||
for dev in ${toString (lib.catAttrs "device" (lib.attrValues devices.disk))}; do
|
trap 'rm -rf "$disko_devices_dir"' EXIT
|
||||||
${../disk-deactivate}/disk-deactivate "$dev" | bash -x
|
mkdir -p "$disko_devices_dir"
|
||||||
done
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
_create = lib.mkOption {
|
|
||||||
internal = true;
|
|
||||||
type = lib.types.str;
|
|
||||||
description = ''
|
|
||||||
The script to create all devices defined by disko.devices
|
|
||||||
'';
|
|
||||||
default = let
|
|
||||||
sortedDeviceList = diskoLib.sortDevicesByDependencies (cfg.config._meta.deviceDependencies or { }) devices;
|
|
||||||
in
|
|
||||||
''
|
|
||||||
set -efux
|
|
||||||
|
|
||||||
disko_devices_dir=$(mktemp -d)
|
${concatMapStrings (dev: (attrByPath (dev ++ [ "_create" ]) {} devices)) sortedDeviceList}
|
||||||
trap 'rm -rf "$disko_devices_dir"' EXIT
|
'';
|
||||||
mkdir -p "$disko_devices_dir"
|
};
|
||||||
|
_mount = lib.mkOption {
|
||||||
|
internal = true;
|
||||||
|
type = lib.types.str;
|
||||||
|
description = ''
|
||||||
|
The script to mount all devices defined by disko.devices
|
||||||
|
'';
|
||||||
|
default =
|
||||||
|
let
|
||||||
|
fsMounts = diskoLib.deepMergeMap (dev: dev._mount.fs or { }) (flatten (map attrValues (attrValues devices)));
|
||||||
|
sortedDeviceList = diskoLib.sortDevicesByDependencies (cfg.config._meta.deviceDependencies or { }) devices;
|
||||||
|
in
|
||||||
|
''
|
||||||
|
set -efux
|
||||||
|
# first create the necessary devices
|
||||||
|
${concatMapStrings (dev: (attrByPath (dev ++ [ "_mount" ]) {} devices).dev or "") sortedDeviceList}
|
||||||
|
|
||||||
${concatMapStrings (dev: (attrByPath (dev ++ [ "_create" ]) {} devices)) sortedDeviceList}
|
# and then mount the filesystems in alphabetical order
|
||||||
'';
|
${concatStrings (attrValues fsMounts)}
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
_disko = lib.mkOption {
|
||||||
|
internal = true;
|
||||||
|
type = lib.types.str;
|
||||||
|
description = ''
|
||||||
|
The script to umount, create and mount all devices defined by disko.devices
|
||||||
|
'';
|
||||||
|
default = ''
|
||||||
|
${cfg.config._destroy}
|
||||||
|
${cfg.config._create}
|
||||||
|
${cfg.config._mount}
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
_config = lib.mkOption {
|
||||||
|
internal = true;
|
||||||
|
description = ''
|
||||||
|
The NixOS config generated by disko
|
||||||
|
'';
|
||||||
|
default =
|
||||||
|
let
|
||||||
|
configKeys = flatten (map attrNames (flatten (map (dev: dev._config) (flatten (map attrValues (attrValues devices))))));
|
||||||
|
collectedConfigs = flatten (map (dev: dev._config) (flatten (map attrValues (attrValues devices))));
|
||||||
|
in
|
||||||
|
lib.genAttrs configKeys (key: lib.mkMerge (lib.catAttrs key collectedConfigs));
|
||||||
|
};
|
||||||
};
|
};
|
||||||
_mount = lib.mkOption {
|
});
|
||||||
internal = true;
|
|
||||||
type = lib.types.str;
|
|
||||||
description = ''
|
|
||||||
The script to mount all devices defined by disko.devices
|
|
||||||
'';
|
|
||||||
default = let
|
|
||||||
fsMounts = diskoLib.deepMergeMap (dev: dev._mount.fs or { }) (flatten (map attrValues (attrValues devices)));
|
|
||||||
sortedDeviceList = diskoLib.sortDevicesByDependencies (cfg.config._meta.deviceDependencies or { }) devices;
|
|
||||||
in ''
|
|
||||||
set -efux
|
|
||||||
# first create the necessary devices
|
|
||||||
${concatMapStrings (dev: ((attrByPath (dev ++ [ "_mount" ]) {} devices)).dev or "") sortedDeviceList}
|
|
||||||
|
|
||||||
# and then mount the filesystems in alphabetical order
|
|
||||||
${concatStrings (attrValues fsMounts)}
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
_disko = lib.mkOption {
|
|
||||||
internal = true;
|
|
||||||
type = lib.types.str;
|
|
||||||
description = ''
|
|
||||||
The script to umount, create and mount all devices defined by disko.devices
|
|
||||||
'';
|
|
||||||
default = ''
|
|
||||||
${cfg.config._destroy}
|
|
||||||
${cfg.config._create}
|
|
||||||
${cfg.config._mount}
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
_config = lib.mkOption {
|
|
||||||
internal = true;
|
|
||||||
description = ''
|
|
||||||
The NixOS config generated by disko
|
|
||||||
'';
|
|
||||||
default =
|
|
||||||
let
|
|
||||||
configKeys = flatten (map attrNames (flatten (map (dev: dev._config) (flatten (map attrValues (attrValues devices))))));
|
|
||||||
collectedConfigs = flatten (map (dev: dev._config) (flatten (map attrValues (attrValues devices))));
|
|
||||||
in
|
|
||||||
lib.genAttrs configKeys (key: lib.mkMerge (lib.catAttrs key collectedConfigs));
|
|
||||||
};
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
# import all tge types from the types directory
|
# import all tge types from the types directory
|
||||||
types = lib.listToAttrs (
|
types = lib.listToAttrs (
|
||||||
|
|||||||
@@ -55,12 +55,15 @@ let
|
|||||||
${systemToInstall.config.system.build.nixos-install}/bin/nixos-install --system ${systemToInstall.config.system.build.toplevel} --keep-going --no-channel-copy -v --no-root-password --option binary-caches ""
|
${systemToInstall.config.system.build.nixos-install}/bin/nixos-install --system ${systemToInstall.config.system.build.toplevel} --keep-going --no-channel-copy -v --no-root-password --option binary-caches ""
|
||||||
'';
|
'';
|
||||||
QEMU_OPTS = lib.concatMapStringsSep " " (disk: "-drive file=${disk.name}.raw,if=virtio,cache=unsafe,werror=report") (lib.attrValues nixosConfig.config.disko.devices.disk);
|
QEMU_OPTS = lib.concatMapStringsSep " " (disk: "-drive file=${disk.name}.raw,if=virtio,cache=unsafe,werror=report") (lib.attrValues nixosConfig.config.disko.devices.disk);
|
||||||
in {
|
in
|
||||||
pure = pkgs.vmTools.runInLinuxVM (pkgs.runCommand name {
|
{
|
||||||
buildInputs =dependencies;
|
pure = pkgs.vmTools.runInLinuxVM (pkgs.runCommand name
|
||||||
inherit preVM QEMU_OPTS;
|
{
|
||||||
memSize = 1024;
|
buildInputs = dependencies;
|
||||||
} builder);
|
inherit preVM QEMU_OPTS;
|
||||||
|
memSize = 1024;
|
||||||
|
}
|
||||||
|
builder);
|
||||||
impure = diskoLib.writeCheckedBash { inherit checked pkgs; } name ''
|
impure = diskoLib.writeCheckedBash { inherit checked pkgs; } name ''
|
||||||
set -efu
|
set -efu
|
||||||
export PATH=${lib.makeBinPath dependencies}
|
export PATH=${lib.makeBinPath dependencies}
|
||||||
|
|||||||
+39
-31
@@ -9,33 +9,36 @@ let
|
|||||||
# this takes a nixos config and changes the disk devices so we can run them inside the qemu test runner
|
# this takes a nixos config and changes the disk devices so we can run them inside the qemu test runner
|
||||||
# basically changes all the disk.*.devices to something like /dev/vda or /dev/vdb etc.
|
# basically changes all the disk.*.devices to something like /dev/vda or /dev/vdb etc.
|
||||||
prepareDiskoConfig = cfg: devices:
|
prepareDiskoConfig = cfg: devices:
|
||||||
let
|
let
|
||||||
cleanedTopLevel = lib.filterAttrsRecursive (n: _: !lib.hasPrefix "_" n) cfg;
|
cleanedTopLevel = lib.filterAttrsRecursive (n: _: !lib.hasPrefix "_" n) cfg;
|
||||||
|
|
||||||
preparedDisks = lib.foldlAttrs (acc: n: v: {
|
preparedDisks = lib.foldlAttrs
|
||||||
devices = lib.tail acc.devices;
|
(acc: n: v: {
|
||||||
grub-devices = acc.grub-devices ++ (lib.optional (lib.any (part: (part.type or "") == "EF02") (lib.attrValues (v.content.partitions or {}))) (lib.head acc.devices));
|
devices = lib.tail acc.devices;
|
||||||
disks = acc.disks // {
|
grub-devices = acc.grub-devices ++ (lib.optional (lib.any (part: (part.type or "") == "EF02") (lib.attrValues (v.content.partitions or { }))) (lib.head acc.devices));
|
||||||
"${n}" = v // {
|
disks = acc.disks // {
|
||||||
device = lib.head acc.devices;
|
"${n}" = v // {
|
||||||
content = v.content // { device = lib.head acc.devices; };
|
device = lib.head acc.devices;
|
||||||
};
|
content = v.content // { device = lib.head acc.devices; };
|
||||||
};
|
};
|
||||||
}) {
|
};
|
||||||
inherit devices;
|
})
|
||||||
grub-devices = [];
|
{
|
||||||
disks = {};
|
inherit devices;
|
||||||
} cleanedTopLevel.disko.devices.disk;
|
grub-devices = [ ];
|
||||||
in
|
disks = { };
|
||||||
|
}
|
||||||
|
cleanedTopLevel.disko.devices.disk;
|
||||||
|
in
|
||||||
cleanedTopLevel // {
|
cleanedTopLevel // {
|
||||||
boot.loader.grub.devices = if (preparedDisks.grub-devices != []) then preparedDisks.grub-devices else [ "nodev" ];
|
boot.loader.grub.devices = if (preparedDisks.grub-devices != [ ]) then preparedDisks.grub-devices else [ "nodev" ];
|
||||||
disko.devices = cleanedTopLevel.disko.devices // {
|
disko.devices = cleanedTopLevel.disko.devices // {
|
||||||
disk = preparedDisks.disks;
|
disk = preparedDisks.disks;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
# list of devices generated inside qemu
|
# list of devices generated inside qemu
|
||||||
devices = [ "/dev/vda" "/dev/vdb" "/dev/vdc" "/dev/vdd" "/dev/vde" "/dev/vdf"];
|
devices = [ "/dev/vda" "/dev/vdb" "/dev/vdc" "/dev/vdd" "/dev/vde" "/dev/vdf" ];
|
||||||
|
|
||||||
# This is the test generator for a disko test
|
# This is the test generator for a disko test
|
||||||
makeDiskoTest =
|
makeDiskoTest =
|
||||||
@@ -60,15 +63,17 @@ let
|
|||||||
};
|
};
|
||||||
# for installation we skip /dev/vda because it is the test runner disk
|
# for installation we skip /dev/vda because it is the test runner disk
|
||||||
|
|
||||||
importedDiskoConfig = if builtins.isPath disko-config then
|
importedDiskoConfig =
|
||||||
import disko-config
|
if builtins.isPath disko-config then
|
||||||
else
|
import disko-config
|
||||||
disko-config;
|
else
|
||||||
|
disko-config;
|
||||||
|
|
||||||
diskoConfigWithArgs = if builtins.isFunction importedDiskoConfig then
|
diskoConfigWithArgs =
|
||||||
importedDiskoConfig { inherit lib; }
|
if builtins.isFunction importedDiskoConfig then
|
||||||
else
|
importedDiskoConfig { inherit lib; }
|
||||||
importedDiskoConfig;
|
else
|
||||||
|
importedDiskoConfig;
|
||||||
testConfigInstall = testLib.prepareDiskoConfig diskoConfigWithArgs (lib.tail testLib.devices);
|
testConfigInstall = testLib.prepareDiskoConfig diskoConfigWithArgs (lib.tail testLib.devices);
|
||||||
# we need to shift the disks by one because the first disk is the /dev/vda of the test runner
|
# we need to shift the disks by one because the first disk is the /dev/vda of the test runner
|
||||||
# so /dev/vdb becomes /dev/vda etc.
|
# so /dev/vdb becomes /dev/vda etc.
|
||||||
@@ -184,9 +189,11 @@ let
|
|||||||
connect-timeout = 1;
|
connect-timeout = 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
networking.hostId = lib.mkIf (
|
networking.hostId = lib.mkIf
|
||||||
(testConfigInstall ? networking.hostId) && (testConfigInstall.networking.hostId != null)
|
(
|
||||||
) testConfigInstall.networking.hostId;
|
(testConfigInstall ? networking.hostId) && (testConfigInstall.networking.hostId != null)
|
||||||
|
)
|
||||||
|
testConfigInstall.networking.hostId;
|
||||||
|
|
||||||
virtualisation.emptyDiskImages = builtins.genList (_: 4096) num-disks;
|
virtualisation.emptyDiskImages = builtins.genList (_: 4096) num-disks;
|
||||||
|
|
||||||
@@ -256,5 +263,6 @@ let
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
in testLib
|
in
|
||||||
|
testLib
|
||||||
|
|
||||||
+13
-11
@@ -91,17 +91,19 @@
|
|||||||
let
|
let
|
||||||
subvolMounts = lib.concatMapAttrs
|
subvolMounts = lib.concatMapAttrs
|
||||||
(_: subvol:
|
(_: subvol:
|
||||||
lib.warnIf (subvol.mountOptions != (options.subvolumes.type.getSubOptions []).mountOptions.default && subvol.mountpoint == null)
|
lib.warnIf (subvol.mountOptions != (options.subvolumes.type.getSubOptions [ ]).mountOptions.default && subvol.mountpoint == null)
|
||||||
"Subvolume ${subvol.name} has mountOptions but no mountpoint. See upgrade guide (2023-07-09 121df48)."
|
"Subvolume ${subvol.name} has mountOptions but no mountpoint. See upgrade guide (2023-07-09 121df48)."
|
||||||
lib.optionalAttrs (subvol.mountpoint != null) {
|
lib.optionalAttrs
|
||||||
${subvol.mountpoint} = ''
|
(subvol.mountpoint != null)
|
||||||
if ! findmnt ${config.device} "${rootMountPoint}${subvol.mountpoint}" > /dev/null 2>&1; then
|
{
|
||||||
mount ${config.device} "${rootMountPoint}${subvol.mountpoint}" \
|
${subvol.mountpoint} = ''
|
||||||
${lib.concatMapStringsSep " " (opt: "-o ${opt}") (subvol.mountOptions ++ [ "subvol=${subvol.name}" ])} \
|
if ! findmnt ${config.device} "${rootMountPoint}${subvol.mountpoint}" > /dev/null 2>&1; then
|
||||||
-o X-mount.mkdir
|
mount ${config.device} "${rootMountPoint}${subvol.mountpoint}" \
|
||||||
fi
|
${lib.concatMapStringsSep " " (opt: "-o ${opt}") (subvol.mountOptions ++ [ "subvol=${subvol.name}" ])} \
|
||||||
'';
|
-o X-mount.mkdir
|
||||||
}
|
fi
|
||||||
|
'';
|
||||||
|
}
|
||||||
)
|
)
|
||||||
config.subvolumes;
|
config.subvolumes;
|
||||||
in
|
in
|
||||||
|
|||||||
+3
-3
@@ -3,7 +3,7 @@
|
|||||||
options = {
|
options = {
|
||||||
name = lib.mkOption {
|
name = lib.mkOption {
|
||||||
type = lib.types.str;
|
type = lib.types.str;
|
||||||
default = lib.replaceStrings ["/"] ["_"] config._module.args.name;
|
default = lib.replaceStrings [ "/" ] [ "_" ] config._module.args.name;
|
||||||
description = "Device name";
|
description = "Device name";
|
||||||
};
|
};
|
||||||
type = lib.mkOption {
|
type = lib.mkOption {
|
||||||
@@ -39,13 +39,13 @@
|
|||||||
};
|
};
|
||||||
_mount = diskoLib.mkMountOption {
|
_mount = diskoLib.mkMountOption {
|
||||||
inherit config options;
|
inherit config options;
|
||||||
default = lib.optionalAttrs (config.content != null) (config.content._mount);
|
default = lib.optionalAttrs (config.content != null) config.content._mount;
|
||||||
};
|
};
|
||||||
_config = lib.mkOption {
|
_config = lib.mkOption {
|
||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
default =
|
default =
|
||||||
lib.optional (config.content != null) (config.content._config);
|
lib.optional (config.content != null) config.content._config;
|
||||||
description = "NixOS configuration";
|
description = "NixOS configuration";
|
||||||
};
|
};
|
||||||
_pkgs = lib.mkOption {
|
_pkgs = lib.mkOption {
|
||||||
|
|||||||
+12
-11
@@ -24,11 +24,12 @@ in
|
|||||||
};
|
};
|
||||||
device = lib.mkOption {
|
device = lib.mkOption {
|
||||||
type = lib.types.str;
|
type = lib.types.str;
|
||||||
default = if config._parent.type == "mdadm" then
|
default =
|
||||||
|
if config._parent.type == "mdadm" then
|
||||||
# workaround because mdadm partlabel do not appear in /dev/disk/by-partlabel
|
# workaround because mdadm partlabel do not appear in /dev/disk/by-partlabel
|
||||||
"/dev/disk/by-id/md-name-any:${config._parent.name}-part${toString partition.config._index}"
|
"/dev/disk/by-id/md-name-any:${config._parent.name}-part${toString partition.config._index}"
|
||||||
else
|
else
|
||||||
"/dev/disk/by-partlabel/${partition.config.label}";
|
"/dev/disk/by-partlabel/${partition.config.label}";
|
||||||
description = "Device to use for the partition";
|
description = "Device to use for the partition";
|
||||||
};
|
};
|
||||||
priority = lib.mkOption {
|
priority = lib.mkOption {
|
||||||
@@ -130,13 +131,13 @@ in
|
|||||||
internal = true;
|
internal = true;
|
||||||
readOnly = true;
|
readOnly = true;
|
||||||
default = (map
|
default = (map
|
||||||
(partition:
|
(partition:
|
||||||
lib.optional (partition.content != null) partition.content._config
|
lib.optional (partition.content != null) partition.content._config
|
||||||
)
|
)
|
||||||
(lib.attrValues config.partitions))
|
(lib.attrValues config.partitions))
|
||||||
++ (lib.optional (lib.any (part: part.type == "EF02") (lib.attrValues config.partitions)) {
|
++ (lib.optional (lib.any (part: part.type == "EF02") (lib.attrValues config.partitions)) {
|
||||||
boot.loader.grub.devices = [ config.device ];
|
boot.loader.grub.devices = [ config.device ];
|
||||||
});
|
});
|
||||||
description = "NixOS configuration";
|
description = "NixOS configuration";
|
||||||
};
|
};
|
||||||
_pkgs = lib.mkOption {
|
_pkgs = lib.mkOption {
|
||||||
|
|||||||
+10
-9
@@ -1,6 +1,7 @@
|
|||||||
{ config, options, lib, diskoLib, parent, device, ... }:
|
{ config, options, lib, diskoLib, parent, device, ... }:
|
||||||
let
|
let
|
||||||
keyFile = if lib.hasAttr "keyFile" config.settings
|
keyFile =
|
||||||
|
if lib.hasAttr "keyFile" config.settings
|
||||||
then config.settings.keyFile
|
then config.settings.keyFile
|
||||||
else if config.keyFile != null
|
else if config.keyFile != null
|
||||||
then lib.warn "The option `keyFile` is deprecated. See the `settings` option." config.keyFile
|
then lib.warn "The option `keyFile` is deprecated. See the `settings` option." config.keyFile
|
||||||
@@ -46,9 +47,9 @@ in
|
|||||||
};
|
};
|
||||||
additionalKeyFiles = lib.mkOption {
|
additionalKeyFiles = lib.mkOption {
|
||||||
type = lib.types.listOf diskoLib.optionTypes.absolute-pathname;
|
type = lib.types.listOf diskoLib.optionTypes.absolute-pathname;
|
||||||
default = [];
|
default = [ ];
|
||||||
description = "Path to additional key files for encryption";
|
description = "Path to additional key files for encryption";
|
||||||
example = ["/tmp/disk2.key"];
|
example = [ "/tmp/disk2.key" ];
|
||||||
};
|
};
|
||||||
initrdUnlock = lib.mkOption {
|
initrdUnlock = lib.mkOption {
|
||||||
type = lib.types.bool;
|
type = lib.types.bool;
|
||||||
@@ -114,12 +115,12 @@ in
|
|||||||
default = [ ]
|
default = [ ]
|
||||||
# If initrdUnlock is true, then add a device entry to the initrd.luks.devices config.
|
# If initrdUnlock is true, then add a device entry to the initrd.luks.devices config.
|
||||||
++ (lib.optional config.initrdUnlock [
|
++ (lib.optional config.initrdUnlock [
|
||||||
{
|
{
|
||||||
boot.initrd.luks.devices.${config.name} = {
|
boot.initrd.luks.devices.${config.name} = {
|
||||||
inherit (config) device;
|
inherit (config) device;
|
||||||
} // config.settings;
|
} // config.settings;
|
||||||
}
|
}
|
||||||
]) ++ (lib.optional (config.content != null) config.content._config);
|
]) ++ (lib.optional (config.content != null) config.content._config);
|
||||||
description = "NixOS configuration";
|
description = "NixOS configuration";
|
||||||
};
|
};
|
||||||
_pkgs = lib.mkOption {
|
_pkgs = lib.mkOption {
|
||||||
|
|||||||
+4
-4
@@ -57,7 +57,7 @@ in
|
|||||||
installTest = diskoLib.testLib.makeDiskoTest {
|
installTest = diskoLib.testLib.makeDiskoTest {
|
||||||
inherit extendModules pkgs;
|
inherit extendModules pkgs;
|
||||||
name = "${config.networking.hostName}-disko";
|
name = "${config.networking.hostName}-disko";
|
||||||
disko-config = builtins.removeAttrs config ["_module"];
|
disko-config = builtins.removeAttrs config [ "_module" ];
|
||||||
testMode = "direct";
|
testMode = "direct";
|
||||||
efi = cfg.tests.efi;
|
efi = cfg.tests.efi;
|
||||||
};
|
};
|
||||||
@@ -66,8 +66,8 @@ in
|
|||||||
|
|
||||||
# we need to specify the keys here, so we don't get an infinite recursion error
|
# we need to specify the keys here, so we don't get an infinite recursion error
|
||||||
# Remember to add config keys here if they are added to types
|
# Remember to add config keys here if they are added to types
|
||||||
fileSystems = lib.mkIf cfg.enableConfig cfg.devices._config.fileSystems or {};
|
fileSystems = lib.mkIf cfg.enableConfig cfg.devices._config.fileSystems or { };
|
||||||
boot = lib.mkIf cfg.enableConfig cfg.devices._config.boot or {};
|
boot = lib.mkIf cfg.enableConfig cfg.devices._config.boot or { };
|
||||||
swapDevices = lib.mkIf cfg.enableConfig cfg.devices._config.swapDevices or [];
|
swapDevices = lib.mkIf cfg.enableConfig cfg.devices._config.swapDevices or [ ];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -6,8 +6,8 @@ diskoLib.testLib.makeDiskoTest {
|
|||||||
name = "luks-btrfs-subvolumes";
|
name = "luks-btrfs-subvolumes";
|
||||||
disko-config = ../example/luks-btrfs-subvolumes.nix;
|
disko-config = ../example/luks-btrfs-subvolumes.nix;
|
||||||
extraTestScript = ''
|
extraTestScript = ''
|
||||||
machine.succeed("cryptsetup isLuks /dev/vda2");
|
machine.succeed("cryptsetup isLuks /dev/vda2");
|
||||||
machine.succeed("btrfs subvolume list / | grep -qs 'path nix$'");
|
machine.succeed("btrfs subvolume list / | grep -qs 'path nix$'");
|
||||||
machine.succeed("btrfs subvolume list / | grep -qs 'path home$'");
|
machine.succeed("btrfs subvolume list / | grep -qs 'path home$'");
|
||||||
'';
|
'';
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user