Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add treefmt CI check #268

Merged
merged 1 commit into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Loading