Skip to content

Commit

Permalink
Add flake.nix and test on CI
Browse files Browse the repository at this point in the history
  • Loading branch information
turion committed Jan 8, 2025
1 parent 3805af8 commit 406a5ad
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 1 deletion.
39 changes: 38 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ghc: ['8.4.4', '8.6.5', '8.8.4', '8.10.7', '9.0.2', '9.2.2', '9.4.2', '9.6.3', '9.8.1', '9.10.1', '9.12.1']
# Always keep in sync with the tested-with section in the cabal file
ghc: ['8.4.4', '8.6.5', '8.8.4', '8.10.7', '9.0.2', '9.2.2', '9.4.2', '9.6.6', '9.8.1', '9.10.1', '9.12.1']
name: Haskell GHC ${{ matrix.ghc }} cabal
env:
cabal_project_freeze: cabal.project.${{ matrix.ghc }}.freeze
Expand Down Expand Up @@ -33,3 +34,39 @@ jobs:
- name: Cabal test
run: |
cabal test all --enable-tests --test-show-details=Always --project-file=cabal.project.${{ matrix.ghc }}
generate-flake-ghc-matrix:
name: Generate GHC versions for nix flake build matrix
runs-on: ubuntu-latest
outputs:
versions: ${{ steps.generate-versions.outputs.versions }}
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v30
- uses: DeterminateSystems/magic-nix-cache-action@v8
- name: Generate versions
id: generate-versions
run: |
echo -n "versions=" >> "$GITHUB_OUTPUT"
nix eval .#supportedGhcs --json >> "$GITHUB_OUTPUT"
build-flake:
name: Nix Flake
needs:
- generate-flake-ghc-matrix
strategy:
matrix:
version: ${{ fromJSON(needs.generate-flake-ghc-matrix.outputs.versions) }}
os:
- ubuntu-latest
- macos-latest
fail-fast: false # So the cache is still filled
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v30
- uses: DeterminateSystems/magic-nix-cache-action@v8
- run: nix flake check
- run: nix build .#${{ matrix.version }}
- run: nix develop .#${{ matrix.version }} -c cabal update
- run: nix develop .#${{ matrix.version }} -c cabal test
61 changes: 61 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
description = "clay";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable-small";
flake-utils.url = "github:numtide/flake-utils";
};

outputs = { self, nixpkgs, flake-utils }:
let
inherit (nixpkgs) lib;
supportedGhcs = [ "ghc810" "ghc90" "ghc92" "ghc94" "ghc96" "ghc98" "ghc910" "ghc912" ];
haskellPackagesFor = pkgs: lib.genAttrs supportedGhcs (ghc: pkgs.haskell.packages.${ghc}) // {default = pkgs.haskellPackages;};
hoverlay = hfinal: hprev: {
clay = hfinal.callCabal2nix "clay" ./. {};
};
overlay = final: prev: {
haskell = prev.haskell // {
packageOverrides = lib.composeManyExtensions [
hoverlay
prev.haskell.packageOverrides
];
};
};
in
flake-utils.lib.eachDefaultSystem (system:
let
# Always keep in sync with the tested-with section in the cabal file
pkgs = nixpkgs.legacyPackages.${system};
pkgsOverridden = pkgs.extend overlay;
clay-all = pkgsOverridden.linkFarm "clay-all" (lib.mapAttrs (_ghcVersion: haskellPackages: haskellPackages.clay) (haskellPackagesFor pkgsOverridden));
in {
inherit self nixpkgs;

packages = lib.mapAttrs (_ghcVersion: haskellPackages: haskellPackages.clay) (haskellPackagesFor pkgsOverridden) // {
default = clay-all;
};
devShells = lib.mapAttrs (_ghcVersion: haskellPackages: haskellPackages.shellFor {
packages = hps: with hps; [clay];
nativeBuildInputs = with haskellPackages;
lib.optional (lib.versionAtLeast haskellPackages.ghc.version "9.2") haskell-language-server;
}) (haskellPackagesFor pkgs);

}
) // {
inherit supportedGhcs;
overlays.default = overlay;
};
}

0 comments on commit 406a5ad

Please sign in to comment.