mirror of
https://github.com/nix-community/disko.git
synced 2026-12-01 13:33: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
+179
-172
@@ -23,10 +23,12 @@ let
|
||||
name = "subType";
|
||||
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}";
|
||||
merge = loc: foldl' (res: def: types.${def.value.type}.merge loc [
|
||||
# we add a dummy root parent node to render documentation
|
||||
(lib.recursiveUpdate { value._module.args = extraArgs; } def)
|
||||
]) { };
|
||||
merge = loc: foldl'
|
||||
(res: def: types.${def.value.type}.merge loc [
|
||||
# we add a dummy root parent node to render documentation
|
||||
(lib.recursiveUpdate { value._module.args = extraArgs; } def)
|
||||
])
|
||||
{ };
|
||||
nestedTypes = types;
|
||||
};
|
||||
|
||||
@@ -108,7 +110,7 @@ let
|
||||
else
|
||||
iter (index + 1) (tail list);
|
||||
in
|
||||
iter 1 list;
|
||||
iter 1 list;
|
||||
|
||||
|
||||
/* indent takes a multiline string and indents it by 2 spaces starting on the second line
|
||||
@@ -119,7 +121,7 @@ let
|
||||
indent "test\nbla"
|
||||
=> "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 */
|
||||
jsonType =
|
||||
@@ -280,10 +282,10 @@ let
|
||||
zapCreateMount :: lib.types.devices -> str
|
||||
*/
|
||||
zapCreateMount = toplevel:
|
||||
''
|
||||
set -efux
|
||||
${toplevel._disko}
|
||||
'';
|
||||
''
|
||||
set -efux
|
||||
${toplevel._disko}
|
||||
'';
|
||||
/* Takes a disko device specification and returns a nixos configuration
|
||||
|
||||
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 = lib.types.submodule (cfg: let
|
||||
devices = { inherit (cfg.config) disk mdadm zpool lvm_vg nodev; };
|
||||
in {
|
||||
options = {
|
||||
disk = lib.mkOption {
|
||||
type = lib.types.attrsOf diskoLib.types.disk;
|
||||
default = { };
|
||||
description = "Block device";
|
||||
};
|
||||
mdadm = lib.mkOption {
|
||||
type = lib.types.attrsOf diskoLib.types.mdadm;
|
||||
default = { };
|
||||
description = "mdadm device";
|
||||
};
|
||||
zpool = lib.mkOption {
|
||||
type = lib.types.attrsOf diskoLib.types.zpool;
|
||||
default = { };
|
||||
description = "ZFS pool device";
|
||||
};
|
||||
lvm_vg = lib.mkOption {
|
||||
type = lib.types.attrsOf diskoLib.types.lvm_vg;
|
||||
default = { };
|
||||
description = "LVM VG device";
|
||||
};
|
||||
nodev = lib.mkOption {
|
||||
type = lib.types.attrsOf diskoLib.types.nodev;
|
||||
default = { };
|
||||
description = "A non-block device";
|
||||
};
|
||||
_meta = lib.mkOption {
|
||||
internal = true;
|
||||
description = ''
|
||||
meta informationen generated by disko
|
||||
currently used for building a dependency list so we know in which order to create the devices
|
||||
'';
|
||||
default = diskoLib.deepMergeMap (dev: dev._meta) (flatten (map attrValues (attrValues 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}
|
||||
toplevel = lib.types.submodule (cfg:
|
||||
let
|
||||
devices = { inherit (cfg.config) disk mdadm zpool lvm_vg nodev; };
|
||||
in
|
||||
{
|
||||
options = {
|
||||
disk = lib.mkOption {
|
||||
type = lib.types.attrsOf diskoLib.types.disk;
|
||||
default = { };
|
||||
description = "Block device";
|
||||
};
|
||||
mdadm = lib.mkOption {
|
||||
type = lib.types.attrsOf diskoLib.types.mdadm;
|
||||
default = { };
|
||||
description = "mdadm device";
|
||||
};
|
||||
zpool = lib.mkOption {
|
||||
type = lib.types.attrsOf diskoLib.types.zpool;
|
||||
default = { };
|
||||
description = "ZFS pool device";
|
||||
};
|
||||
lvm_vg = lib.mkOption {
|
||||
type = lib.types.attrsOf diskoLib.types.lvm_vg;
|
||||
default = { };
|
||||
description = "LVM VG device";
|
||||
};
|
||||
nodev = lib.mkOption {
|
||||
type = lib.types.attrsOf diskoLib.types.nodev;
|
||||
default = { };
|
||||
description = "A non-block device";
|
||||
};
|
||||
_meta = lib.mkOption {
|
||||
internal = true;
|
||||
description = ''
|
||||
meta informationen generated by disko
|
||||
currently used for building a dependency list so we know in which order to create the devices
|
||||
'';
|
||||
|
||||
formatScript = (diskoLib.writeCheckedBash { inherit pkgs checked; }) "disko-format" ''
|
||||
export PATH=${lib.makeBinPath (cfg.config._packages pkgs)}:$PATH
|
||||
${cfg.config._create}
|
||||
default = diskoLib.deepMergeMap (dev: dev._meta) (flatten (map attrValues (attrValues devices)));
|
||||
};
|
||||
_packages = lib.mkOption {
|
||||
internal = true;
|
||||
description = ''
|
||||
packages required by the disko configuration
|
||||
'';
|
||||
|
||||
mountScript = (diskoLib.writeCheckedBash { inherit pkgs checked; }) "disko-mount" ''
|
||||
export PATH=${lib.makeBinPath (cfg.config._packages pkgs)}:$PATH
|
||||
${cfg.config._mount}
|
||||
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}
|
||||
'';
|
||||
|
||||
diskoScript = (diskoLib.writeCheckedBash { inherit pkgs checked; }) "disko" ''
|
||||
export PATH=${lib.makeBinPath ((cfg.config._packages pkgs) ++ [ pkgs.bash ])}:$PATH
|
||||
${cfg.config._disko}
|
||||
formatScript = (diskoLib.writeCheckedBash { inherit pkgs checked; }) "disko-format" ''
|
||||
export PATH=${lib.makeBinPath (cfg.config._packages pkgs)}:$PATH
|
||||
${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
|
||||
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}
|
||||
# shellcheck disable=SC2043
|
||||
for dev in ${toString (lib.catAttrs "device" (lib.attrValues devices.disk))}; do
|
||||
${../disk-deactivate}/disk-deactivate "$dev" | bash -x
|
||||
done
|
||||
'';
|
||||
};
|
||||
};
|
||||
_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}" || :
|
||||
_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
|
||||
|
||||
# shellcheck disable=SC2043
|
||||
for dev in ${toString (lib.catAttrs "device" (lib.attrValues devices.disk))}; do
|
||||
${../disk-deactivate}/disk-deactivate "$dev" | bash -x
|
||||
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)
|
||||
trap 'rm -rf "$disko_devices_dir"' EXIT
|
||||
mkdir -p "$disko_devices_dir"
|
||||
|
||||
disko_devices_dir=$(mktemp -d)
|
||||
trap 'rm -rf "$disko_devices_dir"' EXIT
|
||||
mkdir -p "$disko_devices_dir"
|
||||
${concatMapStrings (dev: (attrByPath (dev ++ [ "_create" ]) {} devices)) sortedDeviceList}
|
||||
'';
|
||||
};
|
||||
_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
|
||||
types = lib.listToAttrs (
|
||||
|
||||
Reference in new issue
Block a user