From 4ba81813190c86288f58b82e55868ce4d5f55789 Mon Sep 17 00:00:00 2001 From: Chris Scutcher Date: Tue, 7 Feb 2023 15:37:12 +0000 Subject: [PATCH 1/3] style: Disable `inherit` pattern check in statix As discussed in [this comment](https://github.com/nix-community/disko/pull/143#discussion_r1097912402), as a blanket rule converting everything possible to `inherit` like statements can hurt readability. Add config file for statix to disable these checks and fixes, then rerun the autofix with these options. --- default.nix | 2 +- doc.nix | 2 +- example/with-lib.nix | 2 +- module.nix | 2 +- statix.toml | 4 ++++ tests/default.nix | 4 ++-- tests/lib.nix | 2 +- types/default.nix | 2 +- types/lvm_vg.nix | 2 +- types/nodev.nix | 4 ++-- types/swap.nix | 2 +- 11 files changed, 16 insertions(+), 12 deletions(-) create mode 100644 statix.toml diff --git a/default.nix b/default.nix index c02a220..33473bf 100644 --- a/default.nix +++ b/default.nix @@ -16,7 +16,7 @@ let }; in { - inherit types; + types = types; create = cfg: types.diskoLib.create (eval cfg).config.devices; createScript = cfg: pkgs: pkgs.writeScript "disko-create" '' #!/usr/bin/env bash diff --git a/doc.nix b/doc.nix index 63ad9e2..67b17bd 100644 --- a/doc.nix +++ b/doc.nix @@ -19,7 +19,7 @@ let ]; }; options = nixosOptionsDoc { - inherit (eval) options; + options = eval.options; }; md = (runCommand "disko-options.md" { } '' cat >$out < { }) }@args: let - inherit (pkgs) lib; - inherit ((pkgs.callPackage ./lib.nix { inherit makeTest eval-config; })) makeDiskoTest; + lib = pkgs.lib; + makeDiskoTest = (pkgs.callPackage ./lib.nix { inherit makeTest eval-config; }).makeDiskoTest; evalTest = name: configFile: let disko-config = import configFile; diff --git a/tests/lib.nix b/tests/lib.nix index b4d3f37..1ab8934 100644 --- a/tests/lib.nix +++ b/tests/lib.nix @@ -17,7 +17,7 @@ , testBoot ? true # if we actually want to test booting or just create/mount }: let - inherit (pkgs) lib; + lib = pkgs.lib; makeTest' = args: makeTest args { inherit pkgs; diff --git a/types/default.nix b/types/default.nix index 403b861..9614505 100644 --- a/types/default.nix +++ b/types/default.nix @@ -187,7 +187,7 @@ rec { internal = true; readOnly = true; type = lib.types.functionTo diskoLib.jsonType; - inherit (attrs) default; + default = attrs.default; description = "Mount script"; }; diff --git a/types/lvm_vg.nix b/types/lvm_vg.nix index 9b52936..ba313e1 100644 --- a/types/lvm_vg.nix +++ b/types/lvm_vg.nix @@ -42,7 +42,7 @@ vgchange -a y ${lib.concatMapStrings (x: x.dev or "") (lib.attrValues lvMounts)} ''; - inherit (lvMounts) fs; + fs = lvMounts.fs; }; }; _config = lib.mkOption { diff --git a/types/nodev.nix b/types/nodev.nix index 9b5fcea..2700ab7 100644 --- a/types/nodev.nix +++ b/types/nodev.nix @@ -54,8 +54,8 @@ readOnly = true; default = [{ fileSystems.${config.mountpoint} = { - inherit (config) device; - inherit (config) fsType; + device = config.device; + fsType = config.fsType; options = config.mountOptions; }; }]; diff --git a/types/swap.nix b/types/swap.nix index 90c3e22..60a7aff 100644 --- a/types/swap.nix +++ b/types/swap.nix @@ -40,7 +40,7 @@ default = dev: [{ swapDevices = [{ device = dev; - inherit (config) randomEncryption; + randomEncryption = config.randomEncryption; }]; }]; description = "NixOS configuration"; From a393654c3b007244d34797dd9235f1e726ffe321 Mon Sep 17 00:00:00 2001 From: Chris Scutcher Date: Tue, 7 Feb 2023 15:51:33 +0000 Subject: [PATCH 2/3] style: Define formatter in flake to allow `nix fmt` Noticed this was an option to codify the agreed style/pattern auto-normalise discussed in [#143] [#143]: https://github.com/nix-community/disko/pull/143 --- flake.nix | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/flake.nix b/flake.nix index a82ee58..6749318 100644 --- a/flake.nix +++ b/flake.nix @@ -57,5 +57,22 @@ ''; in nixosTests // { inherit shellcheck; }); + formatter = forAllSystems (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + in + pkgs.writeShellApplication { + name = "normalise_nix"; + runtimeInputs = with pkgs; [ + nixpkgs-fmt + statix + ]; + text = '' + set -o xtrace + nixpkgs-fmt "$@" + statix fix "$@" + ''; + } + ); }; } From ff5127ea0af829b545cd5460f04e8e4f2b2fd225 Mon Sep 17 00:00:00 2001 From: Chris Scutcher Date: Tue, 7 Feb 2023 15:56:08 +0000 Subject: [PATCH 3/3] style: Re-apply style normalisation Originally this was manually applied with; ```sh nixpkgs-fmt **.nix && statix fix ``` but I overlooked the fact that `**.nix` would only expand to files in the root (I should have used `**/*.nix`). Previous commit adds `nix fmt` support which passes `.` to `nixpkgs-fmt` (if no other path is explicitly specified when running `nix fmt`). This commit includes the changes made by running `nix fmt`. --- example/boot-raid1.nix | 4 ++-- example/btrfs-subvolumes.nix | 6 +++--- example/config.nix | 2 +- example/gpt-bios-compat.nix | 2 +- example/hybrid.nix | 2 +- example/mdadm.nix | 4 ++-- example/stand-alone/configuration.nix | 13 +++++++------ example/with-lib.nix | 2 +- tests/bcachefs.nix | 14 ++++++++------ tests/default.nix | 20 +++++++++++--------- tests/lib.nix | 2 +- types/default.nix | 4 ++-- 12 files changed, 40 insertions(+), 35 deletions(-) diff --git a/example/boot-raid1.nix b/example/boot-raid1.nix index dfd2e6c..e0f26ae 100644 --- a/example/boot-raid1.nix +++ b/example/boot-raid1.nix @@ -13,7 +13,7 @@ start = "0"; end = "1M"; part-type = "primary"; - flags = ["bios_grub"]; + flags = [ "bios_grub" ]; } { type = "partition"; @@ -53,7 +53,7 @@ start = "0"; end = "1M"; part-type = "primary"; - flags = ["bios_grub"]; + flags = [ "bios_grub" ]; } { type = "partition"; diff --git a/example/btrfs-subvolumes.nix b/example/btrfs-subvolumes.nix index 25994df..a6d8088 100644 --- a/example/btrfs-subvolumes.nix +++ b/example/btrfs-subvolumes.nix @@ -35,12 +35,12 @@ }; # Mountpoints inferred from subvolume name "/home" = { - mountOptions = ["compress=zstd"]; + mountOptions = [ "compress=zstd" ]; }; "/nix" = { - mountOptions = ["compress=zstd" "noatime"]; + mountOptions = [ "compress=zstd" "noatime" ]; }; - "/test" = {}; + "/test" = { }; }; }; } diff --git a/example/config.nix b/example/config.nix index cb013cd..6117506 100644 --- a/example/config.nix +++ b/example/config.nix @@ -51,7 +51,7 @@ part-type = "primary"; start = "1024MiB"; end = "100%"; - flags = ["bios_grub"]; + flags = [ "bios_grub" ]; content = { type = "luks"; name = "crypted"; diff --git a/example/gpt-bios-compat.nix b/example/gpt-bios-compat.nix index 7275e26..6d2ae68 100644 --- a/example/gpt-bios-compat.nix +++ b/example/gpt-bios-compat.nix @@ -14,7 +14,7 @@ start = "0"; end = "1M"; part-type = "primary"; - flags = ["bios_grub"]; + flags = [ "bios_grub" ]; } { name = "root"; diff --git a/example/hybrid.nix b/example/hybrid.nix index ff11661..341cec1 100644 --- a/example/hybrid.nix +++ b/example/hybrid.nix @@ -13,7 +13,7 @@ type = "partition"; start = "0"; end = "1M"; - flags = ["bios_grub"]; + flags = [ "bios_grub" ]; } { type = "partition"; diff --git a/example/mdadm.nix b/example/mdadm.nix index 132ead5..f5a1d2e 100644 --- a/example/mdadm.nix +++ b/example/mdadm.nix @@ -13,7 +13,7 @@ start = "0"; end = "1M"; part-type = "primary"; - flags = ["bios_grub"]; + flags = [ "bios_grub" ]; } { type = "partition"; @@ -41,7 +41,7 @@ start = "0"; end = "1M"; part-type = "primary"; - flags = ["bios_grub"]; + flags = [ "bios_grub" ]; } { type = "partition"; diff --git a/example/stand-alone/configuration.nix b/example/stand-alone/configuration.nix index c53bdf9..9a1f298 100644 --- a/example/stand-alone/configuration.nix +++ b/example/stand-alone/configuration.nix @@ -1,8 +1,8 @@ -{ - pkgs, - lib, - ... -}: let +{ pkgs +, lib +, ... +}: +let # We just import from the repository for testing here: disko = import ../../. { inherit lib; @@ -41,7 +41,8 @@ }; }; }; -in { +in +{ imports = [ (disko.config cfg) ]; diff --git a/example/with-lib.nix b/example/with-lib.nix index ce0b93d..78bb50d 100644 --- a/example/with-lib.nix +++ b/example/with-lib.nix @@ -13,7 +13,7 @@ start = "0"; end = "1M"; part-type = "primary"; - flags = ["bios_grub"]; + flags = [ "bios_grub" ]; } { name = "root"; diff --git a/tests/bcachefs.nix b/tests/bcachefs.nix index d78d870..a54f966 100644 --- a/tests/bcachefs.nix +++ b/tests/bcachefs.nix @@ -2,7 +2,7 @@ , makeDiskoTest ? (pkgs.callPackage ./lib.nix { }).makeDiskoTest }: let - linux-bcachefs = pkgs.callPackage ../linux-testing-bcachefs.nix {}; + linux-bcachefs = pkgs.callPackage ../linux-testing-bcachefs.nix { }; in makeDiskoTest { disko-config = ../example/bcachefs.nix; @@ -14,11 +14,13 @@ makeDiskoTest { extraConfig = { boot.supportedFilesystems = [ "bcachefs" ]; # disable zfs so we can support latest kernel - nixpkgs.overlays = [(final: super: { - zfs = super.zfs.overrideAttrs(_: { - meta.platforms = []; - }); - })]; + nixpkgs.overlays = [ + (final: super: { + zfs = super.zfs.overrideAttrs (_: { + meta.platforms = [ ]; + }); + }) + ]; boot.kernelPackages = pkgs.lib.mkForce (pkgs.recurseIntoAttrs (pkgs.linuxPackagesFor linux-bcachefs)); }; } diff --git a/tests/default.nix b/tests/default.nix index 3706206..1efc16c 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -6,12 +6,14 @@ let lib = pkgs.lib; makeDiskoTest = (pkgs.callPackage ./lib.nix { inherit makeTest eval-config; }).makeDiskoTest; - evalTest = name: configFile: let - disko-config = import configFile; - in { - "${name}-tsp-create" = pkgs.writeScript "create" ((pkgs.callPackage ../. { }).create disko-config); - "${name}-tsp-mount" = pkgs.writeScript "mount" ((pkgs.callPackage ../. { }).mount disko-config); - }; + evalTest = name: configFile: + let + disko-config = import configFile; + in + { + "${name}-tsp-create" = pkgs.writeScript "create" ((pkgs.callPackage ../. { }).create disko-config); + "${name}-tsp-mount" = pkgs.writeScript "mount" ((pkgs.callPackage ../. { }).mount disko-config); + }; allTestFilenames = builtins.map (lib.removeSuffix ".nix") ( @@ -21,8 +23,8 @@ let ); allTests = lib.genAttrs allTestFilenames (test: import (./. + "/${test}.nix") { inherit makeDiskoTest pkgs; }) // - evalTest "lvm-luks-example" ../example/config.nix // { - standalone = (pkgs.nixos [ ../example/stand-alone/configuration.nix ]).config.system.build.toplevel; - }; + evalTest "lvm-luks-example" ../example/config.nix // { + standalone = (pkgs.nixos [ ../example/stand-alone/configuration.nix ]).config.system.build.toplevel; + }; in allTests diff --git a/tests/lib.nix b/tests/lib.nix index 1ab8934..43b6607 100644 --- a/tests/lib.nix +++ b/tests/lib.nix @@ -100,7 +100,7 @@ documentation.enable = false; nix.settings = { - substituters = lib.mkForce []; + substituters = lib.mkForce [ ]; hashed-mirrors = null; connect-timeout = 1; }; diff --git a/types/default.nix b/types/default.nix index 9614505..82f3324 100644 --- a/types/default.nix +++ b/types/default.nix @@ -325,7 +325,7 @@ rec { }; subTypes = lib.mapAttrs (_: diskoLib.mkSubType) { - nodev = ./nodev.nix; + nodev = ./nodev.nix; btrfs = ./btrfs.nix; btrfs_subvol = ./btrfs_subvol.nix; filesystem = ./filesystem.nix; @@ -341,6 +341,6 @@ rec { mdadm = ./mdadm.nix; mdraid = ./mdraid.nix; luks = ./luks.nix; - disk = ./disk.nix; + disk = ./disk.nix; }; }