Skip to content

Commit

Permalink
Compute devShell combinations
Browse files Browse the repository at this point in the history
  • Loading branch information
andreabedini committed Oct 17, 2023
1 parent b6ff21f commit c09b473
Showing 1 changed file with 61 additions and 65 deletions.
126 changes: 61 additions & 65 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
else pkgs;
js-pkgs = pkgs.pkgsCross.ghcjs;
windows-pkgs = pkgs.pkgsCross.mingwW64;

devShellsWithToolsModule = toolsModule:
let compilers = pkgs: builtins.removeAttrs pkgs.haskell-nix.compiler
# Exclude old versions of GHC to speed up `nix flake check`
Expand All @@ -88,75 +89,70 @@
"ghc945"
];
windows-compilers = pkgs:
pkgs.lib.optionalAttrs (__elem system ["x86_64-linux"])
pkgs.lib.optionalAttrs (builtins.elem system ["x86_64-linux"])
(builtins.removeAttrs (compilers pkgs)
[
]);
in (builtins.mapAttrs (compiler-nix-name: compiler:
import ./dynamic.nix { inherit pkgs self compiler compiler-nix-name toolsModule; withIOG = false; }
) (compilers pkgs)
// pkgs.lib.mapAttrs' (compiler-nix-name: compiler:
pkgs.lib.nameValuePair "${compiler-nix-name}-minimal" (
import ./dynamic.nix { inherit pkgs self compiler compiler-nix-name toolsModule; withHLS = false; withHlint = false; withIOG = false; }
)) (compilers pkgs)
// pkgs.lib.mapAttrs' (compiler-nix-name: compiler:
pkgs.lib.nameValuePair "${compiler-nix-name}-static" (
import ./static.nix { pkgs = static-pkgs; inherit self compiler compiler-nix-name toolsModule; withIOG = false; }
)) (compilers static-pkgs.buildPackages)
// pkgs.lib.mapAttrs' (compiler-nix-name: compiler:
pkgs.lib.nameValuePair "${compiler-nix-name}-static-minimal" (
import ./static.nix { pkgs = static-pkgs; inherit self compiler compiler-nix-name toolsModule; withHLS = false; withHlint = false; withIOG = false; }
)) (compilers static-pkgs.buildPackages)
// pkgs.lib.mapAttrs' (compiler-nix-name: compiler:
pkgs.lib.nameValuePair "${compiler-nix-name}-js" (
import ./cross-js.nix { pkgs = js-pkgs.buildPackages; inherit self compiler compiler-nix-name toolsModule; }
)) (js-compilers js-pkgs.buildPackages)
// pkgs.lib.mapAttrs' (compiler-nix-name: compiler:
pkgs.lib.nameValuePair "${compiler-nix-name}-js-minimal" (
import ./cross-js.nix { pkgs = js-pkgs.buildPackages; inherit self compiler compiler-nix-name toolsModule; withHLS = false; withHlint = false; }
)) (js-compilers js-pkgs.buildPackages)
// pkgs.lib.mapAttrs' (compiler-nix-name: compiler:
pkgs.lib.nameValuePair "${compiler-nix-name}-windows" (
import ./cross-windows.nix { pkgs = windows-pkgs; inherit self compiler compiler-nix-name; }
)) (windows-compilers windows-pkgs.buildPackages)
// pkgs.lib.mapAttrs' (compiler-nix-name: compiler:
pkgs.lib.nameValuePair "${compiler-nix-name}-windows-minimal" (
import ./cross-windows.nix { pkgs = windows-pkgs; inherit self compiler compiler-nix-name; withHLS = false; withHlint = false; }
)) (windows-compilers windows-pkgs.buildPackages)
// pkgs.lib.mapAttrs' (compiler-nix-name: compiler:
pkgs.lib.nameValuePair "${compiler-nix-name}-iog" (
import ./dynamic.nix { inherit pkgs self compiler compiler-nix-name toolsModule; withIOG = true; }
)) (compilers pkgs)
// pkgs.lib.mapAttrs' (compiler-nix-name: compiler:
pkgs.lib.nameValuePair "${compiler-nix-name}-minimal-iog" (
import ./dynamic.nix { inherit pkgs self compiler compiler-nix-name toolsModule; withHLS = false; withHlint = false; withIOG = true; }
)) (compilers pkgs)
// pkgs.lib.mapAttrs' (compiler-nix-name: compiler:
pkgs.lib.nameValuePair "${compiler-nix-name}-static-iog" (
import ./static.nix { pkgs = static-pkgs; inherit self compiler compiler-nix-name toolsModule; withIOG = true; }
)) (compilers static-pkgs.buildPackages)
// pkgs.lib.mapAttrs' (compiler-nix-name: compiler:
pkgs.lib.nameValuePair "${compiler-nix-name}-static-minimal-iog" (
import ./static.nix { pkgs = static-pkgs; inherit self compiler compiler-nix-name toolsModule; withHLS = false; withHlint = false; withIOG = true; }
)) (compilers static-pkgs.buildPackages)
// pkgs.lib.mapAttrs' (compiler-nix-name: compiler:
pkgs.lib.nameValuePair "${compiler-nix-name}-js-iog" (
import ./cross-js.nix { pkgs = js-pkgs.buildPackages; inherit self compiler compiler-nix-name toolsModule; withIOG = true; }
)) (js-compilers js-pkgs.buildPackages)
// pkgs.lib.mapAttrs' (compiler-nix-name: compiler:
pkgs.lib.nameValuePair "${compiler-nix-name}-js-minimal-iog" (
import ./cross-js.nix { pkgs = js-pkgs.buildPackages; inherit self compiler compiler-nix-name toolsModule; withHLS = false; withHlint = false; withIOG = true; }
)) (js-compilers js-pkgs.buildPackages)
// pkgs.lib.mapAttrs' (compiler-nix-name: compiler:
pkgs.lib.nameValuePair "${compiler-nix-name}-windows-iog" (
import ./cross-windows.nix { pkgs = windows-pkgs; inherit self compiler compiler-nix-name; withIOG = true; }
)) (windows-compilers windows-pkgs.buildPackages)
// pkgs.lib.mapAttrs' (compiler-nix-name: compiler:
pkgs.lib.nameValuePair "${compiler-nix-name}-windows-minimal-iog" (
import ./cross-windows.nix { pkgs = windows-pkgs; inherit self compiler compiler-nix-name; withHLS = false; withHlint = false; withIOG = true; }
)) (windows-compilers windows-pkgs.buildPackages)
);


inherit (pkgs) lib;

combinations = lib.cartesianProductOfSets {
iog = [false true];
minimal = [false true];
cross = [
{
name = "native";
file = ./dynamic.nix;
pkgs = pkgs;
compilers = compilers pkgs;
}
{
name = "static";
file = ./static.nix;
pkgs = static-pkgs;
compilers = compilers static-pkgs.buildPackages;
}
{
name = "js";
file = ./cross-js.nix;
pkgs = js-pkgs;
compilers = js-compilers js-pkgs.buildPackages;
}
{
name = "windows";
file = ./cross-windows.nix;
pkgs = windows-pkgs;
compilers = windows-compilers windows-pkgs;
}
];
};

mkDevShell = {iog, minimal, cross}:
lib.mapAttrs' (compiler-nix-name: compiler:
{
# devShell name
name =
compiler-nix-name
+ (if cross.name == "native" then "" else "-${cross.name}")
+ lib.optionalString minimal "-minimal"
+ lib.optionalString iog "-iog";
# devShell derivation
value =
import cross.file {
inherit (cross) pkgs;
inherit self compiler compiler-nix-name toolsModule;
withIOG = iog;
withHLS = !minimal;
withHlint = !minimal;
};
})
cross.compilers;

in lib.foldAttrs lib.mergeAttrs {} (builtins.map mkDevShell combinations);

devShells = devShellsWithToolsModule {};

# Eval must be done on linux when we use hydra to build environment
# scripts for other platforms. That way a linux GHA can download the
# cached files without needing access to the actual build platform.
Expand Down

0 comments on commit c09b473

Please sign in to comment.