Skip to content

Commit

Permalink
Add alternative approach for multiple versions of the compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
oscar-izval committed Jul 23, 2024
1 parent 785787d commit 24f267e
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 49 deletions.
13 changes: 9 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,15 @@ jobs:
with:
extra-conf: accept-flake-config = true
- uses: DeterminateSystems/magic-nix-cache-action@v7
- name: Compile code
run: nix build .#test
- name: Run tests
run: nix run .#test
# TODO: improve with matrix
- name: Compile code ghc8107
run: nix build .#test-ghc8107
- name: Run tests ghc8107
run: nix run .#test-ghc8107
- name: Compile code ghc902
run: nix build .#test-ghc902
- name: Run tests ghc902
run: nix run .#test-ghc902

docker:
uses: ./.github/workflows/reusable-docker.yml
Expand Down
111 changes: 66 additions & 45 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,53 +17,74 @@
];
};

outputs = inputs@{ self, flake-utils, haskellNix, nixpkgs }:
let
buildWithGhc = ghcVersion: system:
let
pkgs = import nixpkgs {
inherit system;
inherit (haskellNix) config;
overlays = [
haskellNix.overlay
(final: prev: {
hapistrano = final.haskell-nix.cabalProject' {
src = final.haskell-nix.haskellLib.cleanGit {
name = "hapistrano";
src = ./.;
};
compiler-nix-name = ghcVersion;
outputs = inputs@{ self, flake-utils, haskellNix, nixpkgs }:
# https://input-output-hk.github.io/haskell.nix/tutorials/getting-started-flakes.html
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
inherit (haskellNix) config;
overlays = [
haskellNix.overlay
(final: prev: {
hapistrano-ghc8107 = final.haskell-nix.cabalProject' {
src = final.haskell-nix.haskellLib.cleanGit {
name = "hapistrano";
src = ./.;
};
})
];
};
flake = pkgs.hapistrano.flake { };
in
flake // rec {
apps = {
test = {
type = "app";
program = "${packages.test}/bin/test";
};
compiler-nix-name = "ghc8107";
};
hapistrano-ghc902 = final.haskell-nix.cabalProject' {
src = final.haskell-nix.haskellLib.cleanGit {
name = "hapistrano";
src = ./.;
};
compiler-nix-name = "ghc902";
};
})
];
};
flake-ghc8107 = pkgs.hapistrano-ghc8107.flake { };
flake-ghc902 = pkgs.hapistrano-ghc902.flake { };
in
flake-ghc8107 // flake-ghc902 // rec {
apps = {
test-ghc8107 = {
type = "app";
program = "${packages.test-ghc8107}/bin/test";
};
legacyPackages = pkgs;
packages = {
default = flake.packages."hapistrano:exe:hap";
test = flake.packages."hapistrano:test:test".overrideAttrs (_: {
postFixup = ''
wrapProgram $out/bin/test \
--set PATH ${pkgs.lib.makeBinPath [
pkgs.bash
pkgs.coreutils
pkgs.findutils
pkgs.git
pkgs.zsh
]}
'';
});
test-ghc902 = {
type = "app";
program = "${packages.test-ghc902}/bin/test";
};
};
in
flake-utils.lib.eachDefaultSystem (buildWithGhc "ghc902") //
flake-utils.lib.eachDefaultSystem (buildWithGhc "ghc8107");
legacyPackages = pkgs;
packages = {
default = flake-ghc8107.packages."hapistrano:exe:hap";
test-ghc8107 = flake-ghc8107.packages."hapistrano:test:test".overrideAttrs (_: {
postFixup = ''
wrapProgram $out/bin/test \
--set PATH ${pkgs.lib.makeBinPath [
pkgs.bash
pkgs.coreutils
pkgs.findutils
pkgs.git
pkgs.zsh
]}
'';
});
test-ghc902 = flake-ghc902.packages."hapistrano:test:test".overrideAttrs (_: {
postFixup = ''
wrapProgram $out/bin/test \
--set PATH ${pkgs.lib.makeBinPath [
pkgs.bash
pkgs.coreutils
pkgs.findutils
pkgs.git
pkgs.zsh
]}
'';
});
};
});
}

0 comments on commit 24f267e

Please sign in to comment.