haskell.nix/overlays/tools.nix
Alexander Kudryashov de3f82a419
Add native musl support (#578)
* Add native musl support

- adds haskellLibl.isNaviveMusl and related fixes (previously it was
assumed that for musl we always use cross-compilation)
- fixed some issues for musl intoduced in nixpkgs 20.03 (ssh/fetchcvs
infinite recursion, busybox pkgsMusl.pkgsStatic chain, etc.)
- cross-compilation fixes for ghc (absolute path for ar, always pass
target to configure, libffi and gmp packages for target platform) -
this needs more testing

* Better explanation for targetPlatform.{libffi, gmp}

* Ghc configure script now respect AR env variable


Co-authored-by: Moritz Angermann <moritz.angermann@gmail.com>
2020-05-08 15:32:40 +08:00

104 lines
3.8 KiB
Nix

# This overlay helps accessing common executable components.
# Typically we want to make these available in a nix-shell
# created with shellFor. In most cases the package name
# will be the same as the executable, but we have a
# `toolPackageName` mapping to help when it is not.
#
# To get a single tool:
# haskell-nix.tool "cabal" "3.2.0.0"
#
# This does the same thing as:
# (haskell-nix.hackage-package {
# name = "cabal-install"
# version = "3.2.0.0"
# }).components.exes.cabal
#
# To get an attr set containing multiple tools:
# haskell-nix.tools { cabal = "3.2.0.0"; hlint = "2.2.11"; }
#
# To add tools to a shell:
# shellFor { tools = { cabal = "3.2.0.0"; hlint = "2.2.11"; }; }
#
# When used in shellFor the tools will be compiled with the same version
# of ghc used in the shell (the build ghc in the case of cross compilation).
#
# Instead of a version string we can use an attr set containing
# arguments that will be passed to `cabalProject`.
#
# For instance to specify the ghc used to compile. Use:
# haskell-nix.tool "cabal" {
# version = "3.2.0.0";
# ghc = haskell-nix.compiler.ghc883;
# }
#
final: prev:
let
inherit (final) lib;
in { haskell-nix = prev.haskell-nix // {
# Some times the package name in hackage is not the same as tool name.
toolPackageName = {
cabal = "cabal-install";
};
hackage-tool = { name, ... }@args:
(final.haskell-nix.hackage-package
(args // { name = final.haskell-nix.toolPackageName."${name}" or name; }))
.components.exes."${name}";
tool = name: versionOrArgs:
let
args = final.haskell-nix.haskellLib.versionOrArgsToArgs versionOrArgs;
in
(if final.haskell-nix.custom-tools ? "${name}"
&& final.haskell-nix.custom-tools."${name}" ? "${args.version}"
then final.haskell-nix.custom-tools."${name}"."${args.version}"
else final.haskell-nix.hackage-tool) (args // { inherit name; });
tools = lib.mapAttrs final.haskell-nix.tool;
# Like `tools` but allows default ghc to be specified
toolsForGhc = ghc: toolSet:
final.haskell-nix.tools (
lib.mapAttrs (name: versionOrArgs:
# Add default ghc if not specified in the args
{ inherit ghc; }
// final.haskell-nix.haskellLib.versionOrArgsToArgs versionOrArgs
) toolSet
);
# Tools not in hackage yet
custom-tools = {
ghcide.object-code = args:
(final.haskell-nix.cabalProject (args // {
name = "ghcide";
src = final.fetchFromGitHub {
owner = "mpickering";
repo = "ghcide";
rev = "706c59c97c25c66798815c1dc3ee6885a298918a";
sha256 = "0d158xifwvz0y69ah98ckxakzqpz229mq7rpf2bpbmwhnpw3jmm6";
};
modules = [({config, ...}: {
packages.ghcide.configureFlags = lib.optional (!final.stdenv.targetPlatform.isMusl)
"--enable-executable-dynamic";
nonReinstallablePkgs = [ "Cabal" "array" "base" "binary" "bytestring" "containers" "deepseq"
"directory" "filepath" "ghc" "ghc-boot" "ghc-boot-th" "ghc-compact"
"ghc-heap" "ghc-prim" "ghci" "haskeline" "hpc" "integer-gmp"
"libiserv" "mtl" "parsec" "pretty" "process" "rts" "stm"
"template-haskell" "terminfo" "text" "time" "transformers" "unix"
"xhtml"
];
})];
pkg-def-extras = [
(hackage: {
packages = {
"alex" = (((hackage.alex)."3.2.5").revisions).default;
"happy" = (((hackage.happy)."1.19.12").revisions).default;
};
})
];
})).ghcide.components.exes.ghcide;
};
}; }