Skip to content

Commit

Permalink
chore: Add treefmt
Browse files Browse the repository at this point in the history
  • Loading branch information
adisbladis committed Oct 25, 2023
1 parent 6a45de6 commit a366136
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 29 deletions.
26 changes: 0 additions & 26 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,6 @@ jobs:
- name: Check format
run: nix-shell --packages jq diffutils --run "diff --unified overrides/build-systems.json <(jq --from-file overrides/sort-build-systems.jq --raw-output --sort-keys < overrides/build-systems.json)"

nixpkgs-fmt:
runs-on: ubuntu-latest
steps:
- uses: cachix/install-nix-action@v23
with:
nix_path: nixpkgs=channel:nixos-unstable
- uses: actions/checkout@v4
- name: Check format
run: nix run 'nixpkgs#nixpkgs-fmt' -- --check .

black-fmt:
runs-on: ubuntu-latest
steps:
- uses: cachix/install-nix-action@v23
with:
nix_path: nixpkgs=channel:nixos-unstable
- uses: actions/checkout@v4
- uses: cachix/cachix-action@v12
with:
name: poetry2nix
signingKey: "VhaWuN3IyJVpWg+aZvTocVB+W8ziZKKRGLKR53Pkld3YRZxYOUfXZf0fvqF+LkqVW0eA60trVd5vsqNONpX9Hw=="
- name: Check format
run: nix develop -c black --check .

nix-matrix:
runs-on: ubuntu-latest
outputs:
Expand Down Expand Up @@ -74,8 +50,6 @@ jobs:
collect:
runs-on: ubuntu-latest
needs:
- nixpkgs-fmt
- black-fmt
- nix-build
- sort-build-systems
steps:
Expand Down
31 changes: 31 additions & 0 deletions dev/treefmt.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{ pkgs, ... }: {
# Used to find the project root
projectRootFile = "flake.lock";

settings.formatter = {
nix = {
command = "sh";
options = [
"-eucx"
''
${pkgs.lib.getExe pkgs.nixpkgs-fmt} "$@"
''
"--"
];
includes = [ "*.nix" ];
excludes = [ ];
};

python = {
command = "sh";
options = [
"-eucx"
''
${pkgs.lib.getExe pkgs.python3.pkgs.black} "$@"
''
"--" # this argument is ignored by bash
];
includes = [ "*.py" ];
};
};
}
38 changes: 37 additions & 1 deletion flake.lock

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

16 changes: 14 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,21 @@
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:NixOS/nixpkgs/master";

treefmt-nix.url = "github:numtide/treefmt-nix";
treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";

nix-github-actions = {
url = "github:nix-community/nix-github-actions";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs = { self, nixpkgs, flake-utils, nix-github-actions }:
outputs = { self, nixpkgs, flake-utils, nix-github-actions, treefmt-nix, systems }:
let
eachSystem = f: nixpkgs.lib.genAttrs (import systems) (system: f nixpkgs.legacyPackages.${system});
treefmtEval = eachSystem (pkgs: treefmt-nix.lib.evalModule pkgs ./dev/treefmt.nix);
in

{
overlay = import ./overlay.nix;

Expand All @@ -32,7 +40,9 @@
let
pkgs = mkPkgs "x86_64-linux";
in
import ./tests { inherit pkgs; };
import ./tests { inherit pkgs; } // {
formatting = treefmtEval.x86_64-linux.config.build.check self;
};

x86_64-darwin =
let
Expand Down Expand Up @@ -84,6 +94,8 @@
poetry2nix = import ./default.nix { inherit pkgs; };
in
rec {
formatter = treefmtEval.${system}.config.build.wrapper;

packages = {
poetry2nix = poetry2nix.cli;
default = poetry2nix.cli;
Expand Down

0 comments on commit a366136

Please sign in to comment.