From 6208b31a73805d8dda951c1d83e7d96a08a43a81 Mon Sep 17 00:00:00 2001 From: lassulus Date: Sun, 21 Jul 2024 16:44:30 +0200 Subject: [PATCH] nix fmt --- README.md | 6 ++-- docs/quickstart.md | 3 +- lib/types/gpt.nix | 13 +++++---- lib/types/lvm_vg.nix | 4 +-- lib/types/zfs_fs.nix | 68 +++++++++++++++++++++++--------------------- 5 files changed, 49 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index 249d06d..128063e 100644 --- a/README.md +++ b/README.md @@ -41,9 +41,9 @@ recursive layouts. Disko doesn't require installation: it can be run directly from nix-community repository. The [Quickstart Guide](./docs/quickstart.md) documents how to run -Disko in its simplest form when installing NixOS. Alternatively, you can -also use the new [disko-install](./docs/disko-install.md) tool, which combines -the `disko` and `nixos-install` into one step. +Disko in its simplest form when installing NixOS. Alternatively, you can also +use the new [disko-install](./docs/disko-install.md) tool, which combines the +`disko` and `nixos-install` into one step. For information on other use cases, including upgrading from an older version of **disko**, using **disko** without NixOS and downloading the module, see the diff --git a/docs/quickstart.md b/docs/quickstart.md index b4db199..084c057 100644 --- a/docs/quickstart.md +++ b/docs/quickstart.md @@ -15,7 +15,8 @@ existing partitions. Dual booting with other operating systems is not supported. ### Step 1: Choose a Disk Configuration -Real-world templates are provided in this [repository](https://github.com/nix-community/disko-templates). +Real-world templates are provided in this +[repository](https://github.com/nix-community/disko-templates). More disk layouts for all filesystems can be also found in the [example](https://github.com/nix-community/disko/tree/master/example) directory diff --git a/lib/types/gpt.nix b/lib/types/gpt.nix index c9947a0..2042a20 100644 --- a/lib/types/gpt.nix +++ b/lib/types/gpt.nix @@ -45,14 +45,15 @@ in }; priority = lib.mkOption { type = lib.types.int; - default = if partition.config.size or "" == "100%" then - 9001 - else if partition.config.type == "EF02" then + default = + if partition.config.size or "" == "100%" then + 9001 + else if partition.config.type == "EF02" then # Boot partition should be created first, because some BIOS implementations require it. # Priority defaults to 100 here to support any potential use-case for placing partitions prior to EF02 - 100 - else - 1000; + 100 + else + 1000; defaultText = '' 1000: normal partitions 9001: partitions with 100% size diff --git a/lib/types/lvm_vg.nix b/lib/types/lvm_vg.nix index b64caf0..29360db 100644 --- a/lib/types/lvm_vg.nix +++ b/lib/types/lvm_vg.nix @@ -3,7 +3,7 @@ let # Load kernel modules to ensure device mapper types are available kernelModules = lib.filter (x: x != "") (map (lv: lib.optionalString (lv.lvm_type != null && lv.lvm_type != "thinlv") "dm-${lv.lvm_type}") - (lib.attrValues config.lvs)); + (lib.attrValues config.lvs)); in { options = { @@ -125,7 +125,7 @@ in _config = lib.mkOption { internal = true; readOnly = true; - default = [ { boot.initrd.kernelModules = kernelModules; } ] ++ + default = [{ boot.initrd.kernelModules = kernelModules; }] ++ map (lv: [ (lib.optional (lv.content != null) lv.content._config) diff --git a/lib/types/zfs_fs.nix b/lib/types/zfs_fs.nix index e05f91a..813d75a 100644 --- a/lib/types/zfs_fs.nix +++ b/lib/types/zfs_fs.nix @@ -59,40 +59,42 @@ # important to prevent accidental shadowing of mount points # since (create order != mount order) # -p creates parents automatically - default = let - createOptions = (lib.optionalAttrs (config.mountpoint != null) { mountpoint = config.mountpoint; }) // config.options; - # All options defined as PROP_ONETIME or PROP_ONETIME_DEFAULT in https://github.com/openzfs/zfs/blob/master/module/zcommon/zfs_prop.c - onetimeProperties = [ - "encryption" - "casesensitivity" - "utf8only" - "normalization" - "volblocksize" - "pbkdf2iters" - "pbkdf2salt" - "keyformat" - ]; - updateOptions = builtins.removeAttrs config.options onetimeProperties; - mountpoint = config.options.mountpoint or config.mountpoint; - in '' - if ! zfs get type ${config._name} >/dev/null 2>&1; then - zfs create -up ${config._name} \ - ${lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "-o ${n}=${v}") (createOptions))} - ${lib.optionalString (updateOptions != {}) '' - else - zfs set ${lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "${n}=${v}") updateOptions)} ${config._name} - ${lib.optionalString (mountpoint != null) '' - # zfs will try unmount the dataset to change the mountpoint - # but this might fail if the dataset is in use - if ! zfs set mountpoint=${mountpoint} ${config._name}; then - echo "Failed to set mountpoint to '${mountpoint}' for ${config._name}." >&2 - echo "You may need to run when the pool is not mounted i.e. in a recovery system:" >&2 - echo " zfs set mountpoint=${mountpoint} ${config._name}" >&2 - fi + default = + let + createOptions = (lib.optionalAttrs (config.mountpoint != null) { mountpoint = config.mountpoint; }) // config.options; + # All options defined as PROP_ONETIME or PROP_ONETIME_DEFAULT in https://github.com/openzfs/zfs/blob/master/module/zcommon/zfs_prop.c + onetimeProperties = [ + "encryption" + "casesensitivity" + "utf8only" + "normalization" + "volblocksize" + "pbkdf2iters" + "pbkdf2salt" + "keyformat" + ]; + updateOptions = builtins.removeAttrs config.options onetimeProperties; + mountpoint = config.options.mountpoint or config.mountpoint; + in + '' + if ! zfs get type ${config._name} >/dev/null 2>&1; then + zfs create -up ${config._name} \ + ${lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "-o ${n}=${v}") (createOptions))} + ${lib.optionalString (updateOptions != {}) '' + else + zfs set ${lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "${n}=${v}") updateOptions)} ${config._name} + ${lib.optionalString (mountpoint != null) '' + # zfs will try unmount the dataset to change the mountpoint + # but this might fail if the dataset is in use + if ! zfs set mountpoint=${mountpoint} ${config._name}; then + echo "Failed to set mountpoint to '${mountpoint}' for ${config._name}." >&2 + echo "You may need to run when the pool is not mounted i.e. in a recovery system:" >&2 + echo " zfs set mountpoint=${mountpoint} ${config._name}" >&2 + fi + ''} ''} - ''} - fi - ''; + fi + ''; } // { readOnly = false; }; _mount = diskoLib.mkMountOption {