Skip to content

Commit

Permalink
Add treefmt check
Browse files Browse the repository at this point in the history
  • Loading branch information
9999years committed May 28, 2024
1 parent 49d9b86 commit bddd56a
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 33 deletions.
25 changes: 19 additions & 6 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,23 @@
"ghc98"
];
in {
_pkgs = eachSystem (localSystem: makePkgs {inherit localSystem;});

localPkgs = eachSystem (
localSystem:
self._pkgs.${localSystem}.callPackage ./nix/makePackages.nix {inherit inputs;}
);

packages = eachSystem (
localSystem: let
pkgs = makePkgs {inherit localSystem;};
inherit (pkgs) lib;
localPackages = pkgs.callPackage ./nix/makePackages.nix {inherit inputs;};
ghciwatch = localPackages.ghciwatch.override {
inherit (nixpkgs) lib;
localPkgs = self.localPkgs.${localSystem};
pkgs = self._pkgs.${localSystem};
ghciwatch = localPkgs.ghciwatch.override {
inherit ghcVersions;
};
in
(lib.filterAttrs (name: value: lib.isDerivation value) localPackages)
(lib.filterAttrs (name: value: lib.isDerivation value) localPkgs)
// {
inherit ghciwatch;
default = ghciwatch;
Expand Down Expand Up @@ -120,7 +127,13 @@
})
);

checks = eachSystem (system: self.packages.${system}.default.checks);
checks = eachSystem (
system:
builtins.removeAttrs
self.localPkgs.${system}.allChecks
# CI and `nix flake check` complain that these are not derivations.
["override" "overrideDerivation"]
);

devShells = eachSystem (system: {
default = self.packages.${system}.default.devShell;
Expand Down
6 changes: 6 additions & 0 deletions nix/packages/allChecks.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
ghciwatch,
checksFrom,
checks,
}:
(checksFrom ghciwatch) // checks
25 changes: 25 additions & 0 deletions nix/packages/checks/haskell-project.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
mkCheck,
ghciwatch,
}:
mkCheck {
name = "haskell-project";
sourceRoot = "source/tests/data/simple";
nativeBuildInputs = ghciwatch.haskellInputs;
inherit (ghciwatch) GHC_VERSIONS;

checkPhase = ''
# Need an empty `.cabal/config` or `cabal` errors trying to use the network.
mkdir "$TMPDIR/.cabal"
touch "$TMPDIR/.cabal/config"
export HOME="$TMPDIR"
for VERSION in $GHC_VERSIONS; do
make test GHC="ghc-$VERSION"
done
'';

meta.description = ''
Check that the Haskell project used for integration tests compiles.
'';
}
22 changes: 22 additions & 0 deletions nix/packages/checks/treefmt.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
mkCheck,
treefmt,
alejandra,
craneLib,
}:
mkCheck {
name = "treefmt";
nativeBuildInputs = [
treefmt
alejandra
craneLib.rustfmt
];

checkPhase = ''
treefmt --fail-on-change
'';

meta.description = ''
Check that treefmt runs without changes.
'';
}
17 changes: 17 additions & 0 deletions nix/packages/checksFrom.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{lib}: let
name = drv: drv.pname or drv.name;
in
drv:
lib.mapAttrs'
(_name: check: let
drvName = name drv;
checkName = name check;
# If we have `ghciwatch.checks.ghciwatch-fmt` we want `ghciwatch-fmt`,
# not `ghciwatch-ghciwatch-fmt`.
newName =
if lib.hasPrefix drvName checkName
then checkName
else "${drvName}-${checkName}";
in
lib.nameValuePair newName check)
drv.checks
30 changes: 3 additions & 27 deletions nix/packages/ghciwatch.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
then [ghc]
else builtins.map (ghcVersion: haskell.compiler.${ghcVersion}) ghcVersions;

ghcBuildInputs =
haskellInputs =
[
haskellPackages.cabal-install
hpack
Expand Down Expand Up @@ -136,7 +136,7 @@
'';

passthru = {
inherit GHC_VERSIONS checks devShell user-manual user-manual-tar-xz;
inherit GHC_VERSIONS haskellInputs checks devShell user-manual user-manual-tar-xz;
};
};

Expand Down Expand Up @@ -225,7 +225,7 @@
testArgs =
commonArgs
// {
nativeBuildInputs = (commonArgs.nativeBuildInputs or []) ++ ghcBuildInputs;
nativeBuildInputs = (commonArgs.nativeBuildInputs or []) ++ haskellInputs;
NEXTEST_PROFILE = "ci";
NEXTEST_HIDE_PROGRESS_BAR = "true";

Expand Down Expand Up @@ -263,30 +263,6 @@
cargo-nextest
];
});

# Check that the Haskell project used for integration tests is OK.
haskell-project-for-integration-tests = stdenv.mkDerivation {
name = "haskell-project-for-integration-tests";
src = ../../tests/data/simple;
phases = ["unpackPhase" "buildPhase" "installPhase"];
nativeBuildInputs = ghcBuildInputs;
inherit GHC_VERSIONS;

buildPhase = ''
# Need an empty `.cabal/config` or `cabal` errors trying to use the network.
mkdir .cabal
touch .cabal/config
export HOME=$(pwd)
for VERSION in $GHC_VERSIONS; do
make test GHC="ghc-$VERSION"
done
'';

installPhase = ''
touch $out
'';
};
};

devShell = craneLib.devShell {
Expand Down
25 changes: 25 additions & 0 deletions nix/packages/mkCheck.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
stdenv,
inputs,
}: {
name,
checkPhase,
...
} @ args: let
cleanedArgs = builtins.removeAttrs args ["name" "checkPhase"];
in
stdenv.mkDerivation ({
name = "${name}-check";

src = inputs.self;

phases = ["unpackPhase" "checkPhase" "installPhase"];

inherit checkPhase;
doCheck = true;

installPhase = ''
touch $out
'';
}
// cleanedArgs)

0 comments on commit bddd56a

Please sign in to comment.