apply treefmt

This commit is contained in:
Jörg Thalheim authored and mergify[bot] committed 2023-08-11 08:45:46 +00:00
1 parent 049d1bd952
commit b32f0e2876
13 files changed
+67 -45

No files matched your search

+1 -1
View File
@@ -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
]; ];
+2 -2
View File
@@ -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" ];
+1 -1
View File
@@ -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";
+1 -1
View File
@@ -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 -1
View File
@@ -1,4 +1,4 @@
{ ... }: { {
disko.devices = { disko.devices = {
disk = { disk = {
vdb = { vdb = {
+16 -9
View File
@@ -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'
(res: def: types.${def.value.type}.merge loc [
# we add a dummy root parent node to render documentation # we add a dummy root parent node to render documentation
(lib.recursiveUpdate { value._module.args = extraArgs; } def) (lib.recursiveUpdate { value._module.args = extraArgs; } def)
]) { }; ])
{ };
nestedTypes = types; nestedTypes = types;
}; };
@@ -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 =
@@ -328,9 +330,11 @@ 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:
let
devices = { inherit (cfg.config) disk mdadm zpool lvm_vg nodev; }; devices = { inherit (cfg.config) disk mdadm zpool lvm_vg nodev; };
in { in
{
options = { options = {
disk = lib.mkOption { disk = lib.mkOption {
type = lib.types.attrsOf diskoLib.types.disk; type = lib.types.attrsOf diskoLib.types.disk;
@@ -445,7 +449,8 @@ let
description = '' description = ''
The script to create all devices defined by disko.devices The script to create all devices defined by disko.devices
''; '';
default = let default =
let
sortedDeviceList = diskoLib.sortDevicesByDependencies (cfg.config._meta.deviceDependencies or { }) devices; sortedDeviceList = diskoLib.sortDevicesByDependencies (cfg.config._meta.deviceDependencies or { }) devices;
in in
'' ''
@@ -464,13 +469,15 @@ let
description = '' description = ''
The script to mount all devices defined by disko.devices The script to mount all devices defined by disko.devices
''; '';
default = let default =
let
fsMounts = diskoLib.deepMergeMap (dev: dev._mount.fs or { }) (flatten (map attrValues (attrValues devices))); fsMounts = diskoLib.deepMergeMap (dev: dev._mount.fs or { }) (flatten (map attrValues (attrValues devices)));
sortedDeviceList = diskoLib.sortDevicesByDependencies (cfg.config._meta.deviceDependencies or { }) devices; sortedDeviceList = diskoLib.sortDevicesByDependencies (cfg.config._meta.deviceDependencies or { }) devices;
in '' in
''
set -efux set -efux
# first create the necessary devices # first create the necessary devices
${concatMapStrings (dev: ((attrByPath (dev ++ [ "_mount" ]) {} devices)).dev or "") sortedDeviceList} ${concatMapStrings (dev: (attrByPath (dev ++ [ "_mount" ]) {} devices).dev or "") sortedDeviceList}
# and then mount the filesystems in alphabetical order # and then mount the filesystems in alphabetical order
${concatStrings (attrValues fsMounts)} ${concatStrings (attrValues fsMounts)}
+7 -4
View File
@@ -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
{
buildInputs = dependencies;
inherit preVM QEMU_OPTS; inherit preVM QEMU_OPTS;
memSize = 1024; memSize = 1024;
} builder); }
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}
+21 -13
View File
@@ -12,30 +12,33 @@ let
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
(acc: n: v: {
devices = lib.tail acc.devices; devices = lib.tail acc.devices;
grub-devices = acc.grub-devices ++ (lib.optional (lib.any (part: (part.type or "") == "EF02") (lib.attrValues (v.content.partitions or {}))) (lib.head acc.devices)); grub-devices = acc.grub-devices ++ (lib.optional (lib.any (part: (part.type or "") == "EF02") (lib.attrValues (v.content.partitions or { }))) (lib.head acc.devices));
disks = acc.disks // { disks = acc.disks // {
"${n}" = v // { "${n}" = v // {
device = lib.head acc.devices; device = lib.head acc.devices;
content = v.content // { device = lib.head acc.devices; }; content = v.content // { device = lib.head acc.devices; };
}; };
}; };
}) { })
{
inherit devices; inherit devices;
grub-devices = []; grub-devices = [ ];
disks = {}; disks = { };
} cleanedTopLevel.disko.devices.disk; }
cleanedTopLevel.disko.devices.disk;
in 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,12 +63,14 @@ 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 =
if builtins.isPath disko-config then
import disko-config import disko-config
else else
disko-config; disko-config;
diskoConfigWithArgs = if builtins.isFunction importedDiskoConfig then diskoConfigWithArgs =
if builtins.isFunction importedDiskoConfig then
importedDiskoConfig { inherit lib; } importedDiskoConfig { inherit lib; }
else else
importedDiskoConfig; importedDiskoConfig;
@@ -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 != null)
) testConfigInstall.networking.hostId; )
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
+4 -2
View File
@@ -91,9 +91,11 @@
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 != null)
{
${subvol.mountpoint} = '' ${subvol.mountpoint} = ''
if ! findmnt ${config.device} "${rootMountPoint}${subvol.mountpoint}" > /dev/null 2>&1; then if ! findmnt ${config.device} "${rootMountPoint}${subvol.mountpoint}" > /dev/null 2>&1; then
mount ${config.device} "${rootMountPoint}${subvol.mountpoint}" \ mount ${config.device} "${rootMountPoint}${subvol.mountpoint}" \
+3 -3
View File
@@ -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 {
+2 -1
View File
@@ -24,7 +24,8 @@ 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
+4 -3
View File
@@ -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;
+4 -4
View File
@@ -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 [ ];
}; };
} }