jail.nix/tests/flake.nix

84 lines
2.5 KiB
Nix
Raw Permalink Normal View History

2025-07-17 20:25:17 -07:00
{
# This is a separate flake file from the one at the root because we don't
# want to depend on nixpkgs
2026-07-08 10:45:14 -07:00
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-26.05";
2025-09-11 07:31:48 -07:00
outputs =
{ nixpkgs, ... }:
let
pkgs = import nixpkgs { system = "x86_64-linux"; };
lib = pkgs.lib;
2026-01-28 10:08:00 -08:00
haskellPackages = pkgs.haskell.packages.ghc912;
2026-01-28 13:06:37 -08:00
cabal2nix = haskellPackages.callCabal2nix "jail-nix-tests" (lib.fileset.toSource {
root = ./.;
fileset = ./jail-nix-tests.cabal;
}) { };
2025-09-11 07:31:48 -07:00
testDependencies = [
(haskellPackages.ghc.withPackages (p: cabal2nix.buildInputs))
2025-09-11 07:31:48 -07:00
pkgs.cabal-install
2025-08-19 00:08:44 -07:00
];
2026-01-28 10:53:41 -08:00
mkTestPackage =
name: runtimeInputs: script:
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
2026-01-28 10:53:41 -08:00
fi
${script}
'';
};
2025-09-11 07:31:48 -07:00
in
2026-01-28 10:53:41 -08:00
rec {
packages.x86_64-linux = rec {
all-for-ci = pkgs.linkFarmFromDrvs "all-for-ci" [
run-tests
check-fmt
fmt
devShells.x86_64-linux.default
];
2025-09-11 07:31:48 -07:00
2026-01-28 10:53:41 -08:00
run-tests = mkTestPackage "run-tests" testDependencies ''
${
lib.pipe
{
2026-01-28 13:06:37 -08:00
jail-nix =
with lib.fileset;
toSource {
root = ../.;
fileset = difference ../. (unions [
../.build.yml
../LICENSE
../README.md
../tests
../website
]);
};
2026-01-28 10:53:41 -08:00
nixpkgs = nixpkgs;
}
[
(lib.mapAttrsToList (name: path: "${name}=${path}"))
(lib.concatStringsSep " ")
(lib.toShellVar "NIX_PATH")
]
} cabal run spec -- "$@"
'';
2025-09-11 07:31:48 -07:00
2026-01-28 10:53:41 -08:00
check-fmt = mkTestPackage "check-fmt" [ pkgs.nixfmt-tree ] "treefmt --ci";
fmt = mkTestPackage "fmt" [ pkgs.nixfmt-tree ] "treefmt";
};
2025-09-11 07:31:48 -07:00
devShells.x86_64-linux.default = pkgs.mkShell {
buildInputs = testDependencies ++ [
haskellPackages.haskell-language-server
2025-09-11 07:31:48 -07:00
pkgs.ghcid
pkgs.hpack
];
};
2025-08-19 00:08:44 -07:00
};
2025-07-17 20:25:17 -07:00
}