2019-04-10 03:55:19 +03:00
|
|
|
# nixpkgs used only for library functions, not for dependencies
|
|
|
|
{ pkgs ? import ./nixpkgs.nix
|
|
|
|
, lib ? pkgs.lib
|
|
|
|
}:
|
2019-04-05 09:07:08 +03:00
|
|
|
|
|
|
|
let
|
|
|
|
|
2019-04-10 03:55:19 +03:00
|
|
|
# A la lib.composeExtensions, but with any number of extensions
|
|
|
|
composeMultiple = extensions:
|
|
|
|
if extensions == [] then self: super: {}
|
|
|
|
else lib.composeExtensions
|
|
|
|
(lib.head extensions)
|
|
|
|
(composeMultiple (lib.tail extensions));
|
|
|
|
|
|
|
|
# Speeds up Haskell builds
|
|
|
|
speedierBuilds = self: super: {
|
|
|
|
mkDerivation = args: super.mkDerivation (args // {
|
|
|
|
enableLibraryProfiling = false;
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
ghcSpecific = ghcVersion: rec {
|
2019-04-06 07:44:02 +03:00
|
|
|
|
2019-04-10 03:55:19 +03:00
|
|
|
# Reformats the ghc version into the format "8.6.4"
|
|
|
|
versionString = lib.concatStringsSep "."
|
|
|
|
(builtins.match "ghc(.)(.)(.)" ghcVersion);
|
|
|
|
|
2019-04-26 03:29:47 +03:00
|
|
|
# The more recent the version, the higher the priority
|
|
|
|
# But higher priorities are lower on the number scale (WHY?), so we need the -
|
|
|
|
versionPriority = - lib.toInt (lib.head (builtins.match "ghc(.*)" ghcVersion));
|
|
|
|
|
2019-04-10 03:55:19 +03:00
|
|
|
# Evaluates to a nixpkgs that has the given ghc version in it
|
|
|
|
pkgs = let
|
|
|
|
rev = builtins.readFile (./nixpkgsForGhc + "/${ghcVersion}");
|
|
|
|
sha256 = builtins.readFile (./generated/nixpkgsHashes + "/${rev}");
|
|
|
|
in import (fetchTarball {
|
|
|
|
url = "https://github.com/NixOS/nixpkgs/tarball/${rev}";
|
2019-04-06 07:44:02 +03:00
|
|
|
inherit sha256;
|
2019-04-10 03:55:19 +03:00
|
|
|
}) { config = {}; overlays = []; };
|
|
|
|
|
|
|
|
# Returns a Haskell overlay that sets all ghc base libraries to null
|
|
|
|
# (minus a select few)
|
|
|
|
baseLibraryNuller = self: super: let
|
|
|
|
libs = lib.splitString " "
|
|
|
|
(builtins.readFile (./generated/ghcBaseLibraries + "/${ghcVersion}"));
|
|
|
|
libNames = map (lib: (builtins.parseDrvName lib).name) libs;
|
|
|
|
# It seems that some versions require Cabal and some don't
|
|
|
|
filtered = lib.filter (name: ! lib.elem name [ "ghc" "Cabal" ]) libNames;
|
|
|
|
in lib.genAttrs filtered (name: null);
|
|
|
|
|
|
|
|
# Custom overrides for specific ghc versions, declared in ./overrides
|
|
|
|
customOverrides =
|
|
|
|
let path = ./overrides + "/${ghcVersion}.nix";
|
|
|
|
in if builtins.pathExists path then import path
|
|
|
|
else self: super: {};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
# Build for a specific GHC version
|
|
|
|
hieBuild = ghcVersion: let
|
|
|
|
forGhc = ghcSpecific ghcVersion;
|
|
|
|
hlib = forGhc.pkgs.haskell.lib;
|
|
|
|
revision = builtins.readFile ./generated/stack2nix/revision;
|
|
|
|
|
2019-04-26 03:58:21 +03:00
|
|
|
hieOverride = self: super: {
|
2019-04-26 03:29:47 +03:00
|
|
|
haskell-ide-engine = (hlib.overrideCabal super.haskell-ide-engine (old: {
|
2019-04-26 03:58:21 +03:00
|
|
|
# Embed the ghc version into the name
|
2019-04-10 03:55:19 +03:00
|
|
|
pname = "${old.pname}-${ghcVersion}";
|
|
|
|
version = lib.substring 0 8 revision;
|
2019-04-26 03:29:47 +03:00
|
|
|
})).overrideAttrs (old: {
|
|
|
|
nativeBuildInputs = old.nativeBuildInputs or [] ++ [ pkgs.makeWrapper ];
|
2019-04-26 03:58:21 +03:00
|
|
|
# Make sure hie-x.x.x binary exists
|
|
|
|
# And make sure hie-wrapper finds this version
|
2019-04-26 03:29:47 +03:00
|
|
|
postInstall = old.postInstall or "" + ''
|
|
|
|
ln -s hie $out/bin/hie-${forGhc.versionString}
|
|
|
|
wrapProgram $out/bin/hie-wrapper \
|
|
|
|
--suffix PATH : $out/bin
|
|
|
|
'';
|
|
|
|
|
2019-04-26 03:58:21 +03:00
|
|
|
# Assign a priority for allowing multiple versions to be installed at once
|
2019-04-26 03:29:47 +03:00
|
|
|
meta = old.meta // {
|
|
|
|
priority = forGhc.versionPriority;
|
|
|
|
};
|
2019-04-10 03:55:19 +03:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
overrideFun = old: {
|
|
|
|
overrides = composeMultiple [
|
|
|
|
(old.overrides or (self: super: {}))
|
|
|
|
speedierBuilds
|
2019-04-26 03:58:21 +03:00
|
|
|
hieOverride
|
2019-04-10 03:55:19 +03:00
|
|
|
forGhc.baseLibraryNuller
|
|
|
|
forGhc.customOverrides
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
expr = import (./generated/stack2nix + "/${ghcVersion}.nix") {
|
|
|
|
pkgs = forGhc.pkgs;
|
|
|
|
};
|
|
|
|
|
|
|
|
build = hlib.justStaticExecutables
|
|
|
|
(expr.override overrideFun).haskell-ide-engine;
|
|
|
|
|
|
|
|
in build;
|
|
|
|
|
|
|
|
# A set of all ghc versions for all hie versions, like
|
|
|
|
# { stable = { ghc864 = <derivation ..>; ... }; unstable = ...; }
|
|
|
|
allVersions =
|
|
|
|
let ghcVersionFiles = lib.filterAttrs (file: _: file != "revision")
|
|
|
|
(builtins.readDir ./generated/stack2nix);
|
|
|
|
in lib.mapAttrs' (ghcVersionFile: _:
|
|
|
|
|
|
|
|
let ghcVersion = lib.removeSuffix ".nix" ghcVersionFile;
|
|
|
|
in lib.nameValuePair ghcVersion (hieBuild ghcVersion)
|
|
|
|
|
|
|
|
) ghcVersionFiles;
|
|
|
|
|
2019-04-26 03:29:47 +03:00
|
|
|
latest = lib.last (lib.attrValues allVersions);
|
|
|
|
|
2019-04-10 03:55:19 +03:00
|
|
|
# Combined a set of HIE versions (given as { <ghcVersion> = <derivation>; })
|
|
|
|
# into a single derivation which has a binary hie-$major.$minor.$patch for
|
|
|
|
# every GHC version, and binaries hie and hie-wrapper containing a binary that
|
|
|
|
# automatically selects the correct HIE version out of the available ghc
|
|
|
|
# versions
|
2019-04-26 03:29:47 +03:00
|
|
|
combined = versions:
|
|
|
|
# Build an separate derivation to not clutter PATH
|
|
|
|
let env = pkgs.buildEnv {
|
|
|
|
name = "haskell-ide-engine-env";
|
|
|
|
paths = lib.attrValues versions;
|
|
|
|
};
|
|
|
|
in pkgs.runCommandNoCC "haskell-ide-engine-combined" {} ''
|
|
|
|
makeWrapper ${latest}/bin/.hie-wrapper-wrapped $out/bin/hie-wrapper \
|
|
|
|
--suffix PATH : ${env}/bin
|
|
|
|
ln -s hie-wrapper $out/bin/hie
|
|
|
|
'';
|
2019-04-10 03:55:19 +03:00
|
|
|
|
|
|
|
in {
|
|
|
|
|
2019-04-26 03:29:47 +03:00
|
|
|
inherit combined;
|
|
|
|
versions = allVersions;
|
|
|
|
selection = { selector }: combined (selector allVersions);
|
|
|
|
inherit latest;
|
2019-04-05 09:07:08 +03:00
|
|
|
|
2019-04-10 03:55:19 +03:00
|
|
|
}
|