jail.nix/tests/flake.nix
Alex David ec9f9f98d8 Improve test apps
* Allow running test apps in repo root (e.g. `nix run ./tests#runTests`)
* Pass argv to cabal to allow filtering tests with `-m`
* Use `cabal run spec` rather than `cabal test`
2025-10-19 12:15:48 -07:00

64 lines
1.9 KiB
Nix

{
# This is a separate flake file from the one at the root because we don't
# want to depend on nixpkgs
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05";
outputs =
{ nixpkgs, ... }:
let
pkgs = import nixpkgs { system = "x86_64-linux"; };
lib = pkgs.lib;
haskellPackages = pkgs.haskell.packages.ghc984;
cabal2nix = haskellPackages.callCabal2nix "jail-nix-tests" ./. { };
testDependencies = [
(haskellPackages.ghc.withPackages (p: cabal2nix.buildInputs))
pkgs.cabal-install
];
mkApp = name: runtimeInputs: script: {
type = "app";
program = lib.getExe (
pkgs.writeShellApplication {
inherit name runtimeInputs;
text = ''
if ! [ -e jail-nix-tests.cabal ]; then
if [ -e tests/jail-nix-tests.cabal ]; then
cd tests
else
echo "${name} must be called in repo root or tests directory"
exit 1
fi
fi
${script}
'';
}
);
};
in
{
apps.x86_64-linux.runTests = mkApp "run-all-jail-nix-tests" testDependencies ''
${
lib.pipe
{
jail-nix = ../.;
nixpkgs = nixpkgs;
}
[
(lib.mapAttrsToList (name: path: "${name}=${path}"))
(lib.concatStringsSep " ")
(lib.toShellVar "NIX_PATH")
]
} cabal run spec -- "$@"
'';
apps.x86_64-linux.checkFmt = mkApp "check-fmt" [ pkgs.nixfmt-tree ] "treefmt --ci";
apps.x86_64-linux.fmt = mkApp "fmt" [ pkgs.nixfmt-tree ] "treefmt";
devShells.x86_64-linux.default = pkgs.mkShell {
buildInputs = testDependencies ++ [
haskellPackages.haskell-language-server
pkgs.ghcid
pkgs.hpack
];
};
};
}