Skip to content

Commit

Permalink
Add newPkgSet and newPkgSetDevShell output attributes.
Browse files Browse the repository at this point in the history
  • Loading branch information
cdepillabout committed Feb 9, 2023
1 parent 0ce6406 commit 156180d
Show file tree
Hide file tree
Showing 3 changed files with 158 additions and 10 deletions.
31 changes: 31 additions & 0 deletions nix/build-support/stacklock2nix/cabal2nixArgsForPkg.nix
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,55 @@
# for testing, but this is not necessary to build the Haskell library.
#
# Please feel free to send PRs adding necessary overrides here.
#
# Make sure to keep this list in alphabetical order.

cabal2nixArgsOverrides {
"gi-cairo" = ver: { cairo = pkgs.cairo; };

"gi-gdk" = ver: { gtk3 = pkgs.gtk3; };

"gi-gio" = ver: { glib = pkgs.glib; };

"gi-glib" = ver: { glib = pkgs.glib; };

"gi-gtk" = ver: { gtk3 = pkgs.gtk3; };

"gi-gmodule" = ver: { gmodule = null; };

"gi-gobject" = ver: { glib = pkgs.glib; };

"gi-harfbuzz" = ver: { harfbuzz-gobject = null; };

"gi-pango" = ver: { cairo = pkgs.cairo; pango = pkgs.pango; };

"gi-vte" = ver: { vte_291 = pkgs.vte; };

"glib" = ver: { glib = pkgs.glib; };

"haskell-gi" = ver: { glib = pkgs.glib; gobject-introspection = pkgs.gobject-introspection; };

"haskell-gi-base" = ver: { glib = pkgs.glib; };

# The PSQueue and fingertree-psqueue packages are used in benchmarks, but they are not on Stackage.
"psqueues" = ver: { fingertree-psqueue = null; PSQueue = null; };

"saltine" = ver: { libsodium = pkgs.libsodium; };

"secp256k1-haskell" = ver: { secp256k1 = pkgs.secp256k1; };

"splitmix" = ver: { testu01 = null; };

"test-framework" = ver: { libxml = pkgs.libxml; };

"termonad" = ver: { vte_291 = pkgs.vte; gtk3 = pkgs.gtk3; pcre2 = pkgs.pcre2;};

# unordered-containers uses the Haskell package nothunks in its test-suite,
# but nothunks is not in Stackage. We disable the tests for unordered-containers
# in the suggestedOverlay.nix file, but callCabal2Nix is called on it before
# suggestedOverlay.nix is applied. So here we need to just pass in null for
# the nothunks dependency, since it won't end up being used.
"unordered-containers" = ver: { nothunks = null; };

"zlib" = ver: { zlib = pkgs.zlib; };
}
129 changes: 122 additions & 7 deletions nix/build-support/stacklock2nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
, lib
, runCommand
, stdenv
, newScope
, path
}@topargs:

{ # The path to your stack.yaml file.
Expand Down Expand Up @@ -77,6 +79,9 @@
# This is not used if `baseHaskellPkgSet` is `null`.
all-cabal-hashes ? null
, callPackage ? topargs.callPackage
, newScope ? topargs.newScope
, # Path to Nixpkgs
path ? topargs.path
}:

# The stack.yaml path can be computed from the stack.yaml.lock path, or
Expand Down Expand Up @@ -372,7 +377,7 @@ let
# This roughly returns an overlay that looks like the following:
# ```
# { lens = callHackage "lens" "5.0.1" {};
# conduit = callHackage "conduit" "5.0.1" {};
# conduit = callHackage "conduit" "1.3.4" {};
# }
# ```
haskPkgLocksToOverlay = haskPkgLocks: hfinal: hprev:
Expand Down Expand Up @@ -635,22 +640,130 @@ let
inherit all-cabal-hashes;
});

devShellForPkgSet = packageSet:
if packageSet == null then
null
else
packageSet.shellFor {
packages = localPkgsSelector;
nativeBuildInputs = additionalDevShellNativeBuildInputs packageSet;
};

# A development shell created by passing all your local packages (from
# `localPkgsSelector`) to `pkgSet.shellFor`.
#
# devShell :: Drv
#
# Note that this derivation is specifically meant to be passed to `nix
# develop` or `nix-shell`.
devShell =
if pkgSet == null then
devShell = devShellForPkgSet pkgSet;

# An Nixpkgs Haskell overlay that has GHC boot packages set to `null`. This
# is used as an initial overlay when creating a brand new package set.
newPkgSetCompilerConfig = self: super: {
# TODO: Should llvmPackages be enabled here?
# llvmPackages = pkgs.lib.dontRecurseIntoAttrs self.ghc.llvmPackages;

# Disable GHC core libraries.
array = null;
base = null;
binary = null;
bytestring = null;
Cabal = null;
containers = null;
deepseq = null;
directory = null;
exceptions = null;
filepath = null;
ghc-bignum = null;
ghc-boot = null;
ghc-boot-th = null;
ghc-compact = null;
ghc-heap = null;
ghc-prim = null;
ghci = null;
haskeline = null;
hpc = null;
integer-gmp = null;
libiserv = null;
mtl = null;
parsec = null;
pretty = null;
process = null;
rts = null;
stm = null;
template-haskell = null;

# GHC only builds terminfo if it is a native compiler
# terminfo = if pkgs.stdenv.hostPlatform == pkgs.stdenv.buildPlatform then null else self.terminfo_0_4_1_5;
terminfo = null;

text = null;
time = null;
transformers = null;
unix = null;

# GHC only bundles the xhtml library if haddock is enabled, check if this is
# still the case when updating: https://gitlab.haskell.org/ghc/ghc/-/blob/0198841877f6f04269d6050892b98b5c3807ce4c/ghc.mk#L463
# xhtml = if self.ghc.hasHaddock or true then null else self.xhtml_3000_2_2_1;
xhtml = null;
};

# This is similar to `pkgSet`.
#
# While `pkgSet` is `baseHaskellPkgSet` overridden with overlays from your
# stack.yaml.lock file, `newPkgSet` is a completely new Nixpkgs Haskell
# package set. It _only_ contains packages defined in the `stack.yaml` file.
#
# newPkgSet :: HaskellPkgSet
#
# `newPkgSet` will contain local packages. For instance, if you have a local
# package called `my-haskell-pkg`:
#
# Example: `newPkgSet.my-haskell-pkg`
#
# `newPkgSet` will also contain packages in your stack.yaml resolver. For
# instance:
#
# Example: `newPkgSet.lens`
#
# `pkgSet` will _not_ contain packages from the underlying Haskell package
# set. For instance, `termonad` is not available in Stackage, so it is not
# available in `newPkgSet`.
newPkgSet =
if baseHaskellPkgSet == null then
null
else
pkgSet.shellFor {
packages = localPkgsSelector;
nativeBuildInputs = additionalDevShellNativeBuildInputs pkgSet;
};
let
callPackage' = newScope {
haskellLib = haskell.lib.compose;
};

haskPkgSet = callPackage' (path + "/pkgs/development/haskell-modules") {
# TODO: Is it okay to use a completely different package set as the
# base package set like this?
buildHaskellPackages = baseHaskellPkgSet;
ghc = baseHaskellPkgSet.ghc;
compilerConfig = newPkgSetCompilerConfig;
initialPackages = _: _: {};

overrides = lib.composeManyExtensions [
combinedOverlay
additionalHaskellPkgSetOverrides
];

nonHackagePackages = _: _: {};
configurationCommon = _: _: _: {};
configurationNix = _: _: _: {};
configurationArm = _: _: _: {};
configurationDarwin = _: _: _: {};
};
in haskPkgSet;

# Same as `devShell`, but based on `newPkgSet`.
#
# newPkgSetDevShell :: Drv
newPkgSetDevShell = devShellForPkgSet newPkgSet;
in

{ inherit
Expand All @@ -662,6 +775,8 @@ in
localPkgsSelector
pkgSet
devShell
newPkgSet
newPkgSetDevShell
;

# These are a bunch of internal attributes, used for testing.
Expand Down
8 changes: 5 additions & 3 deletions nix/build-support/stacklock2nix/suggestedOverlay.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
# ```
#
# These will be maintained on a best-effort basis. Again, please send PRs.
#
# Make sure to keep this list in alphabetical order.

hfinal: hprev: with haskell.lib.compose; {

Expand Down Expand Up @@ -155,9 +157,6 @@ hfinal: hprev: with haskell.lib.compose; {

nanospec = dontCheck hprev.nanospec;

# test suite doesn't build
nothunks = dontCheck hprev.nothunks;

# circular dependency in tests
options = dontCheck hprev.options;

Expand Down Expand Up @@ -213,6 +212,9 @@ hfinal: hprev: with haskell.lib.compose; {
# tests don't support musl
unix-time = dontCheck hprev.unix-time;

# Test suite requires the nothunks library, which isn't on stackage.
unordered-containers = dontCheck hprev.unordered-containers;

vector = dontCheck hprev.vector;

# test suite uses phantom js
Expand Down

0 comments on commit 156180d

Please sign in to comment.