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 flake.nix and test on CI #270

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
51 changes: 50 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,51 @@ 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"

check-flake:
name: Check Flake
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v30
- uses: DeterminateSystems/magic-nix-cache-action@v8
- run: nix flake check
- name: Check whether .nix files are formatted
run: |
nix fmt
git diff --exit-code

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 build .#${{ matrix.version }}.all
- run: nix develop .#${{ matrix.version }} -c cabal update
- run: nix develop .#${{ matrix.version }} -c cabal test
12 changes: 0 additions & 12 deletions .travis.yml

This file was deleted.

6 changes: 0 additions & 6 deletions all-ghcs.nix

This file was deleted.

File renamed without changes.
6 changes: 5 additions & 1 deletion clay.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ Tested-With:
GHC==8.10.7,
GHC==9.0.2,
GHC==9.2.2,
GHC==9.4.2
GHC==9.4.2,
GHC==9.6.6,
GHC==9.8.1,
GHC==9.10.1,
GHC==9.12.1

Source-Repository head
Type: git
Expand Down
19 changes: 13 additions & 6 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
{ compiler ? builtins.getEnv "GHC_VERSION" }:

let
compilerWithDefault = if compiler == "" then "ghc884" else compiler;
release = import ./release.nix { compiler = compilerWithDefault; };
in { inherit (release) clay examples; }
(import
(
let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
nodeName = lock.nodes.root.inputs.flake-compat;
in
fetchTarball {
url = lock.nodes.${nodeName}.locked.url or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.${nodeName}.locked.rev}.tar.gz";
sha256 = lock.nodes.${nodeName}.locked.narHash;
}
)
{ src = ./.; }
).defaultNix
77 changes: 77 additions & 0 deletions flake.lock

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

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

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

outputs = { self, nixpkgs, flake-utils, ... }:
let
inherit (nixpkgs) lib;

# Always keep in sync with the tested-with section in the cabal file
supportedGhcs = [
"ghc810"
"ghc90"
"ghc92"
"ghc94"
"ghc96"
"ghc98"
"ghc910"
# "ghc912" # Uncomment as soon as nixpkgs is more advanced
];

localPackages = {
clay = ./.;
clay-examples = ./examples;
};

haskellPackagesFor = pkgs: lib.genAttrs supportedGhcs (ghc: pkgs.haskell.packages.${ghc}) // { default = pkgs.haskellPackages; };
hoverlay = pkgs: hfinal: hprev: with pkgs.haskell.lib;
lib.mapAttrs
(package: path: hfinal.callCabal2nix package path { })
localPackages
//
{
# HLS depends on clay transitively, but we don't want to rebuild HLS for the dev env
haskell-language-server = hprev.haskell-language-server.override (_: {
stan = hprev.stan.override (_: {
clay = hprev.clay;
});
});
}
//
# GHC-version dependent overrides. Try to remove whenever nixpkgs is bumped.
lib.optionalAttrs (lib.versionAtLeast (hprev.ghc.version) "9.12") {
primitive = doJailbreak hprev.primitive;
};
overlay = final: prev: {
haskell = prev.haskell // {
packageOverrides = lib.composeManyExtensions [
(hoverlay prev)
prev.haskell.packageOverrides
];
};
};

in
flake-utils.lib.eachDefaultSystem
(system:
let
pkgs = nixpkgs.legacyPackages.${system}.extend overlay;

allLocalPackagesFor = ghcVersion: haskellPackages: pkgs.linkFarm "${ghcVersion}-allLocalPackages"
(lib.mapAttrs (pname: _: haskellPackages.${pname}) localPackages);
localPackagesFor = ghcVersion: haskellPackages: lib.mapAttrs (pname: _: haskellPackages.${pname}) localPackages;

clay-all = pkgs.linkFarm "clay-all"
(lib.mapAttrs (ghcVersion: haskellPackages: allLocalPackagesFor ghcVersion haskellPackages) (haskellPackagesFor pkgs));
in
{
inherit self nixpkgs;

packages = lib.mapAttrs
(ghcVersion: haskellPackages:
localPackagesFor ghcVersion haskellPackages // { all = allLocalPackagesFor ghcVersion haskellPackages; })
(haskellPackagesFor pkgs) // {
default = clay-all;
};

devShells = lib.mapAttrs
(ghcVersion: haskellPackages: haskellPackages.shellFor {
packages = hps: builtins.attrValues (localPackagesFor ghcVersion hps);
nativeBuildInputs = (with haskellPackages;
lib.optional (lib.versionAtLeast haskellPackages.ghc.version "9.2") haskell-language-server)
++ (with pkgs;
[ cabal-install ]
)
;
})
(haskellPackagesFor pkgs);

formatter = pkgs.nixpkgs-fmt;
}
) // {
inherit supportedGhcs;
overlays.default = overlay;
};
}
36 changes: 18 additions & 18 deletions release.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,27 @@ let
generatedOverrides = haskellPackagesNew: haskellPackagesOld:
let
toPackage = file: _: {
name = builtins.replaceStrings [ ".nix" ] [ "" ] file;
name = builtins.replaceStrings [ ".nix" ] [ "" ] file;
value = haskellPackagesNew.callPackage (./. + "/nix/${file}") { };
};
in
pkgs.lib.mapAttrs' toPackage (builtins.readDir ./nix);
pkgs.lib.mapAttrs' toPackage (builtins.readDir ./nix);

makeOverrides =
function: names: haskellPackagesNew: haskellPackagesOld:
let
toPackage = name: {
inherit name;
value = function haskellPackagesOld.${name};
};
in
builtins.listToAttrs (map toPackage names);
let
toPackage = name: {
inherit name;
value = function haskellPackagesOld.${name};
};
in
builtins.listToAttrs (map toPackage names);

composeExtensionsList =
pkgs.lib.fold pkgs.lib.composeExtensions (_: _: {});
pkgs.lib.fold pkgs.lib.composeExtensions (_: _: { });

# More exotic overrides go here
manualOverrides = haskellPackagesNew: haskellPackagesOld: {
};
manualOverrides = haskellPackagesNew: haskellPackagesOld: { };

config = {
packageOverrides = pkgs: rec {
Expand All @@ -46,7 +45,7 @@ let
"${compiler}" = pkgs.haskell.packages."${compiler}".override {
overrides = composeExtensionsList [
generatedOverrides
(makeOverrides pkgs.haskell.lib.dontCheck dontCheckPackages )
(makeOverrides pkgs.haskell.lib.dontCheck dontCheckPackages)
(makeOverrides pkgs.haskell.lib.doJailbreak doJailbreakPackages)
(makeOverrides pkgs.haskell.lib.dontHaddock dontHaddockPackages)
manualOverrides
Expand All @@ -60,8 +59,9 @@ let
pkgs = import (builtins.fetchTarball (import ./nix/nixpkgs.nix)) { inherit config; };

in
{ clay = pkgs.haskell.packages.${compiler}.clay;
examples = pkgs.haskell.packages.${compiler}.callCabal2nix "examples" ./examples {};
cabal = pkgs.haskellPackages.cabal-install;
pkgs = pkgs;
}
{
clay = pkgs.haskell.packages.${compiler}.clay;
examples = pkgs.haskell.packages.${compiler}.callCabal2nix "examples" ./examples { };
cabal = pkgs.haskellPackages.cabal-install;
pkgs = pkgs;
}
23 changes: 13 additions & 10 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
{ compiler ? "ghc884" }:

let
release = (import ./release.nix {inherit compiler;});
in release.pkgs.lib.overrideDerivation release.clay.env (oldAttrs: rec {
nativeBuildInputs = (oldAttrs.nativeBuildInputs or []) ++ [
release.cabal
release.pkgs.haskellPackages.cabal2nix
];
})
(import
(
let
lock = builtins.fromJSON (builtins.readFile ./flake.lock);
nodeName = lock.nodes.root.inputs.flake-compat;
in
fetchTarball {
url = lock.nodes.${nodeName}.locked.url or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.${nodeName}.locked.rev}.tar.gz";
sha256 = lock.nodes.${nodeName}.locked.narHash;
}
)
{ src = ./.; }
).shellNix
Loading