From 1c06ac032cbae5d178887ac3323c66b3ac0b10de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Wed, 9 Oct 2024 08:14:45 +0200 Subject: [PATCH 1/3] modernize formatters --- flake.lock | 18 +++++++-------- treefmt.nix | 65 ++++++++++++++++++----------------------------------- 2 files changed, 31 insertions(+), 52 deletions(-) diff --git a/flake.lock b/flake.lock index ca72049..2a988a0 100644 --- a/flake.lock +++ b/flake.lock @@ -7,11 +7,11 @@ ] }, "locked": { - "lastModified": 1709336216, - "narHash": "sha256-Dt/wOWeW6Sqm11Yh+2+t0dfEWxoMxGBvv3JpIocFl9E=", + "lastModified": 1727826117, + "narHash": "sha256-K5ZLCyfO/Zj9mPFldf3iwS6oZStJcU4tSpiXTMYaaL0=", "owner": "hercules-ci", "repo": "flake-parts", - "rev": "f7b3c975cf067e56e7cda6cb098ebe3fb4d74ca2", + "rev": "3d04084d54bedc3d6b8b736c70ef449225c361b1", "type": "github" }, "original": { @@ -22,11 +22,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1710637405, - "narHash": "sha256-w/woLwnFyhOeJWPjSWFtMNI2/RZTaAtHySIfm43Chos=", + "lastModified": 1728279793, + "narHash": "sha256-W3D5YpNrUVTFPVU4jiEiboaaUDShaiH5fRl9aJLqUnU=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "299d4668ba61600311553920d9fd9c102145b2cb", + "rev": "f85a2d005e83542784a755ca8da112f4f65c4aa4", "type": "github" }, "original": { @@ -50,11 +50,11 @@ ] }, "locked": { - "lastModified": 1710278050, - "narHash": "sha256-Oc6BP7soXqb8itlHI8UKkdf3V9GeJpa1S39SR5+HJys=", + "lastModified": 1727984844, + "narHash": "sha256-xpRqITAoD8rHlXQafYZOLvUXCF6cnZkPfoq67ThN0Hc=", "owner": "numtide", "repo": "treefmt-nix", - "rev": "35791f76524086ab4b785a33e4abbedfda64bd22", + "rev": "4446c7a6fc0775df028c5a3f6727945ba8400e64", "type": "github" }, "original": { diff --git a/treefmt.nix b/treefmt.nix index e3cee19..87f0b10 100644 --- a/treefmt.nix +++ b/treefmt.nix @@ -1,53 +1,32 @@ -{ lib, inputs, ... }: { +{ lib, inputs, ... }: +{ imports = [ inputs.treefmt-nix.flakeModule ]; - perSystem = { pkgs, ... }: { - treefmt = { - # Used to find the project root - projectRootFile = "flake.lock"; + perSystem = + { pkgs, ... }: + { + treefmt = { + # Used to find the project root + projectRootFile = "flake.lock"; - programs.deno.enable = true; - programs.mypy.enable = true; - programs.mypy.directories = { - "." = { - directory = "."; - extraPythonPackages = [ - pkgs.python3.pkgs.pytest - ]; - }; - }; - - settings.formatter = { - nix = { - command = "sh"; - options = [ - "-eucx" - '' - # First deadnix - ${lib.getExe pkgs.deadnix} --edit "$@" - # Then nixpkgs-fmt - ${lib.getExe pkgs.nixpkgs-fmt} "$@" - '' - "--" - ]; - includes = [ "*.nix" ]; - }; + programs.deno.enable = + pkgs.lib.meta.availableOn pkgs.stdenv.hostPlatform pkgs.deno && !pkgs.deno.meta.broken; + programs.ruff.format = true; + programs.ruff.check = true; + programs.mypy.enable = true; + programs.nixfmt.enable = pkgs.lib.meta.availableOn pkgs.stdenv.buildPlatform pkgs.nixfmt-rfc-style.compiler; + programs.deadnix.enable = true; - python = { - command = "sh"; - options = [ - "-eucx" - '' - ${lib.getExe pkgs.ruff} --fix "$@" - ${lib.getExe pkgs.ruff} format "$@" - '' - "--" # this argument is ignored by bash - ]; - includes = [ "*.py" ]; + programs.mypy.directories = { + "." = { + directory = "."; + extraPythonPackages = [ + pkgs.python3.pkgs.pytest + ]; + }; }; }; }; - }; } From 5f2c99e35a5776a716cc4037c311140b6ffb6396 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Wed, 9 Oct 2024 08:17:51 +0200 Subject: [PATCH 2/3] assets/nixpkgs/default.nix: make it a valid nix file --- tests/assets/nixpkgs/default.nix | 2 +- tests/conftest.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/assets/nixpkgs/default.nix b/tests/assets/nixpkgs/default.nix index fed0742..785557c 100644 --- a/tests/assets/nixpkgs/default.nix +++ b/tests/assets/nixpkgs/default.nix @@ -1,7 +1,7 @@ { config ? { }, system ? null } @ args: let pkgs = - import @NIXPKGS@ (args // { inherit config; + import "@NIXPKGS@" (args // { inherit config; }); in { pkg1 = pkgs.stdenv.mkDerivation { diff --git a/tests/conftest.py b/tests/conftest.py index 2dfdf7c..925c7c5 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -66,7 +66,7 @@ def setup_nixpkgs(target: Path) -> Path: default_nix = target.joinpath("default.nix") with open(default_nix) as r: - text = r.read().replace("@NIXPKGS@", real_nixpkgs()) + text = r.read().replace('"@NIXPKGS@"', real_nixpkgs()) with open(default_nix, "w") as w: w.write(text) From 99bce4682456d699401b3eff60229888a52de6f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Wed, 9 Oct 2024 08:18:00 +0200 Subject: [PATCH 3/3] reformat with nixfmt --- default.nix | 23 ++++++----- flake.nix | 59 ++++++++++++++++++----------- nixpkgs_review/nix/evalAttrs.nix | 18 ++++----- nixpkgs_review/nix/review-shell.nix | 20 +++++----- shell.nix | 4 +- tests/assets/nixpkgs/default.nix | 23 ++++++----- 6 files changed, 85 insertions(+), 62 deletions(-) diff --git a/default.nix b/default.nix index b19997d..4c423dc 100644 --- a/default.nix +++ b/default.nix @@ -1,12 +1,15 @@ -{ pkgs ? import { } -, withSandboxSupport ? false -, withAutocomplete ? true -, withNom ? false +{ + pkgs ? import { }, + withSandboxSupport ? false, + withAutocomplete ? true, + withNom ? false, }: with pkgs; let - withNom' = withNom && (builtins.tryEval (builtins.elem buildPlatform.system pkgs.ghc.meta.platforms)).value or false; + withNom' = + withNom + && (builtins.tryEval (builtins.elem buildPlatform.system pkgs.ghc.meta.platforms)).value or false; in python3.pkgs.buildPythonApplication { name = "nixpkgs-review"; @@ -24,8 +27,7 @@ python3.pkgs.buildPythonApplication { python3.pkgs.pytest pkgs.nixVersions.stable or nix_2_4 git - ] ++ lib.optional withSandboxSupport bubblewrap - ++ lib.optional withNom' nix-output-monitor; + ] ++ lib.optional withSandboxSupport bubblewrap ++ lib.optional withNom' nix-output-monitor; checkPhase = '' echo -e "\x1b[32m## run nixpkgs-review --help\x1b[0m" @@ -34,9 +36,10 @@ python3.pkgs.buildPythonApplication { ''; makeWrapperArgs = let - binPath = [ pkgs.nixVersions.stable or nix_2_4 git ] - ++ lib.optional withSandboxSupport bubblewrap - ++ lib.optional withNom' nix-output-monitor; + binPath = [ + pkgs.nixVersions.stable or nix_2_4 + git + ] ++ lib.optional withSandboxSupport bubblewrap ++ lib.optional withNom' nix-output-monitor; in [ "--prefix PATH : ${lib.makeBinPath binPath}" diff --git a/flake.nix b/flake.nix index 35fceaf..b25fcf1 100644 --- a/flake.nix +++ b/flake.nix @@ -10,27 +10,42 @@ treefmt-nix.inputs.nixpkgs.follows = "nixpkgs"; }; - outputs = inputs @ { flake-parts, ... }: - flake-parts.lib.mkFlake { inherit inputs; } ({ lib, ... }: { - imports = [ ./treefmt.nix ]; - systems = [ - "aarch64-linux" - "x86_64-linux" - "riscv64-linux" + outputs = + inputs@{ flake-parts, ... }: + flake-parts.lib.mkFlake { inherit inputs; } ( + { lib, ... }: + { + imports = [ ./treefmt.nix ]; + systems = [ + "aarch64-linux" + "x86_64-linux" + "riscv64-linux" - "x86_64-darwin" - "aarch64-darwin" - ]; - perSystem = { config, pkgs, self', ... }: { - packages = { - nixpkgs-review = pkgs.callPackage ./. { }; - default = config.packages.nixpkgs-review; - } // lib.optionalAttrs (pkgs.stdenv.isLinux) { - nixpkgs-review-sandbox = pkgs.callPackage ./. { withSandboxSupport = true; }; - }; - devShells = { - default = (self'.packages.nixpkgs-review-sandbox or self'.packages.nixpkgs-review).override { withNom = true; }; - }; - }; - }); + "x86_64-darwin" + "aarch64-darwin" + ]; + perSystem = + { + config, + pkgs, + self', + ... + }: + { + packages = + { + nixpkgs-review = pkgs.callPackage ./. { }; + default = config.packages.nixpkgs-review; + } + // lib.optionalAttrs (pkgs.stdenv.isLinux) { + nixpkgs-review-sandbox = pkgs.callPackage ./. { withSandboxSupport = true; }; + }; + devShells = { + default = (self'.packages.nixpkgs-review-sandbox or self'.packages.nixpkgs-review).override { + withNom = true; + }; + }; + }; + } + ); } diff --git a/nixpkgs_review/nix/evalAttrs.nix b/nixpkgs_review/nix/evalAttrs.nix index 01e5ff3..90eb64a 100644 --- a/nixpkgs_review/nix/evalAttrs.nix +++ b/nixpkgs_review/nix/evalAttrs.nix @@ -11,7 +11,8 @@ let inherit (pkgs) lib; attrs = fromJSON (readFile attr-json); - getProperties = name: + getProperties = + name: let attrPath = lib.splitString "." name; pkg = lib.attrByPath attrPath null pkgs; @@ -27,19 +28,18 @@ let }) ] else - lib.flip map pkg.outputs or [ "out" ] (output: + lib.flip map pkg.outputs or [ "out" ] ( + output: let # some packages are set to null if they aren't compatible with a platform or package set maybePath = tryEval "${lib.getOutput output pkg}"; broken = !exists || !maybePath.success; in - lib.nameValuePair - (if output == "out" then name else "${name}.${output}") - { - inherit exists broken; - path = if !broken then maybePath.value else null; - drvPath = if !broken then pkg.drvPath else null; - } + lib.nameValuePair (if output == "out" then name else "${name}.${output}") { + inherit exists broken; + path = if !broken then maybePath.value else null; + drvPath = if !broken then pkg.drvPath else null; + } ); in diff --git a/nixpkgs_review/nix/review-shell.nix b/nixpkgs_review/nix/review-shell.nix index d78007d..7b0c318 100644 --- a/nixpkgs_review/nix/review-shell.nix +++ b/nixpkgs_review/nix/review-shell.nix @@ -1,16 +1,16 @@ -{ local-system -, nixpkgs-config-path -, # Path to Nix file containing the Nixpkgs config - attrs-path -, # Path to Nix file containing a list of attributes to build - nixpkgs-path -, # Path to this review's nixpkgs +{ + local-system, + nixpkgs-config-path, + # Path to Nix file containing the Nixpkgs config + attrs-path, + # Path to Nix file containing a list of attributes to build + nixpkgs-path, + # Path to this review's nixpkgs local-pkgs ? import nixpkgs-path { system = local-system; config = import nixpkgs-config-path; - } -, lib ? local-pkgs.lib -, + }, + lib ? local-pkgs.lib, }: let diff --git a/shell.nix b/shell.nix index d6c6259..d61716d 100644 --- a/shell.nix +++ b/shell.nix @@ -1,4 +1,6 @@ -{ pkgs ? import { } }: +{ + pkgs ? import { }, +}: with pkgs; diff --git a/tests/assets/nixpkgs/default.nix b/tests/assets/nixpkgs/default.nix index 785557c..17c2b7b 100644 --- a/tests/assets/nixpkgs/default.nix +++ b/tests/assets/nixpkgs/default.nix @@ -1,16 +1,19 @@ -{ config ? { }, system ? null } @ args: +{ + config ? { }, + # deadnix: skip + system ? null, +}@args: let - pkgs = - import "@NIXPKGS@" (args // { inherit config; - }); - in { - pkg1 = pkgs.stdenv.mkDerivation { + pkgs = import "@NIXPKGS@" (args // { inherit config; }); +in +{ + pkg1 = pkgs.stdenv.mkDerivation { name = "pkg1"; dontUnpack = true; installPhase = '' install -D ${./pkg1.txt} $out/foo ''; - }; - # hack to not break evaluation with nixpkgs_review/nix/*.nix - inherit (pkgs) lib mkShell bashInteractive; - } + }; + # hack to not break evaluation with nixpkgs_review/nix/*.nix + inherit (pkgs) lib mkShell bashInteractive; +}