Skip to content

Commit

Permalink
Merge pull request #424 from Mic92/joerg-ci
Browse files Browse the repository at this point in the history
modernize formatters
  • Loading branch information
Mic92 authored Oct 9, 2024
2 parents 3a6c6ef + 99bce46 commit fdf86eb
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 115 deletions.
23 changes: 13 additions & 10 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
{ pkgs ? import <nixpkgs> { }
, withSandboxSupport ? false
, withAutocomplete ? true
, withNom ? false
{
pkgs ? import <nixpkgs> { },
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";
Expand All @@ -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"
Expand All @@ -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}"
Expand Down
18 changes: 9 additions & 9 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 37 additions & 22 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
};
};
}
);
}
18 changes: 9 additions & 9 deletions nixpkgs_review/nix/evalAttrs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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

Expand Down
20 changes: 10 additions & 10 deletions nixpkgs_review/nix/review-shell.nix
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 3 additions & 1 deletion shell.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{ pkgs ? import <nixpkgs> { } }:
{
pkgs ? import <nixpkgs> { },
}:

with pkgs;

Expand Down
23 changes: 13 additions & 10 deletions tests/assets/nixpkgs/default.nix
Original file line number Diff line number Diff line change
@@ -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;
}
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
65 changes: 22 additions & 43 deletions treefmt.nix
Original file line number Diff line number Diff line change
@@ -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
];
};
};
};
};
};
}

0 comments on commit fdf86eb

Please sign in to comment.