Skip to content

Commit

Permalink
switch to flake-parts and treefmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Mic92 committed Nov 2, 2023
1 parent 48b10fb commit cd09ced
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 21 deletions.
52 changes: 31 additions & 21 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,26 +1,36 @@
{
description = "nixpkgs-review";

inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs";

outputs = { self, nixpkgs }:
let
linuxPlatforms = [ "x86_64-linux" "aarch64-linux" "i686-linux" "armv7l-linux" "riscv64-linux" ];
forAllSystems = nixpkgs.lib.genAttrs (linuxPlatforms ++ [ "x86_64-darwin" "aarch64-darwin" ]);
in
nixpkgs.lib.recursiveUpdate
({
packages = forAllSystems (system: {
nixpkgs-review = nixpkgs.legacyPackages.${system}.callPackage ./. { };
default = self.packages.${system}.nixpkgs-review;
});
devShells = forAllSystems (system: {
default = (self.packages.${system}.nixpkgs-review-sandbox or self.packages.${system}.nixpkgs-review).override { withNom = true; };
});
})
({
packages = nixpkgs.lib.genAttrs linuxPlatforms (system: {
nixpkgs-review-sandbox = nixpkgs.legacyPackages.${system}.callPackage ./. { withSandboxSupport = true; };
});
});
treefmt-nix.url = "github:numtide/treefmt-nix";
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"

"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; };
};
};
});
}
53 changes: 53 additions & 0 deletions treefmt.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{ lib, inputs, ... }: {
imports = [
inputs.treefmt-nix.flakeModule
];

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" ];
};

python = {
command = "sh";
options = [
"-eucx"
''
${lib.getExe pkgs.ruff} --fix "$@"
${lib.getExe pkgs.ruff} format "$@"
''
"--" # this argument is ignored by bash
];
includes = [ "*.py" ];
};
};
};
};
}

0 comments on commit cd09ced

Please sign in to comment.