Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

haskell: Add hoogle option to developPackage #103061

Merged
merged 3 commits into from Nov 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/default.nix
Expand Up @@ -5,7 +5,7 @@
*/
let

inherit (import ./fixed-points.nix {}) makeExtensible;
inherit (import ./fixed-points.nix { inherit lib; }) makeExtensible;

lib = makeExtensible (self: let
callLibs = file: import file { lib = self; };
Expand Down Expand Up @@ -69,7 +69,7 @@ let
importJSON importTOML warn info showWarnings nixpkgsVersion version mod compare
splitByAndCompare functionArgs setFunctionArgs isFunction toHexString toBaseDigits;
inherit (self.fixedPoints) fix fix' converge extends composeExtensions
makeExtensible makeExtensibleWithCustomName;
composeManyExtensions makeExtensible makeExtensibleWithCustomName;
inherit (self.attrsets) attrByPath hasAttrByPath setAttrByPath
getAttrFromPath attrVals attrValues getAttrs catAttrs filterAttrs
filterAttrsRecursive foldAttrs collect nameValuePair mapAttrs
Expand Down
11 changes: 10 additions & 1 deletion lib/fixed-points.nix
@@ -1,4 +1,4 @@
{ ... }:
{ lib, ... }:
rec {
# Compute the fixed point of the given function `f`, which is usually an
# attribute set that expects its final, non-recursive representation as an
Expand Down Expand Up @@ -77,6 +77,15 @@ rec {
super' = super // fApplied;
in fApplied // g self super';

# Compose several extending functions of the type expected by 'extends' into
# one where changes made in preceding functions are made available to
# subsequent ones.
#
# composeManyExtensions : [packageSet -> packageSet -> packageSet] -> packageSet -> packageSet -> packageSet
# ^final ^prev ^overrides ^final ^prev ^overrides
composeManyExtensions =
lib.foldr (x: y: composeExtensions x y) (self: super: {});

# Create an overridable, recursive attribute set. For example:
#
# nix-repl> obj = makeExtensible (self: { })
Expand Down
20 changes: 20 additions & 0 deletions lib/tests/misc.nix
Expand Up @@ -87,6 +87,26 @@ runTests {
expected = true;
};

testComposeManyExtensions0 = {
expr = let obj = makeExtensible (self: { foo = true; });
emptyComposition = composeManyExtensions [];
composed = obj.extend emptyComposition;
in composed.foo;
expected = true;
};

testComposeManyExtensions =
let f = self: super: { bar = false; baz = true; };
g = self: super: { bar = super.baz or false; };
h = self: super: { qux = super.bar or false; };
obj = makeExtensible (self: { foo = self.qux; });
in {
expr = let composition = composeManyExtensions [f g h];
composed = obj.extend composition;
in composed.foo;
expected = (obj.extend (composeExtensions f (composeExtensions g h))).foo;
};

testBitAnd = {
expr = (bitAnd 3 10);
expected = 2;
Expand Down
21 changes: 19 additions & 2 deletions pkgs/development/haskell-modules/make-package-set.nix
Expand Up @@ -221,30 +221,47 @@ in package-set { inherit pkgs stdenv callPackage; } self // {
# , overrides : Defaulted (HaskellPackageOverrideSet)
# , modifier : Defaulted
# , returnShellEnv : Defaulted
# , withHoogle : Defaulted
# } -> NixShellAwareDerivation
# Given a path to a haskell package directory, an optional package name
# which defaults to the base name of the path, an optional set of source
# overrides as appropriate for the 'packageSourceOverrides' function, an
# optional set of arbitrary overrides, and an optional haskell package
# modifier, return a derivation appropriate for nix-build or nix-shell to
# build that package.
# If 'returnShellEnv' is true this returns a derivation which will give you
# an environment suitable for developing the listed packages with an
# incremental tool like cabal-install.
# If 'withHoogle' is true (the default if a shell environment is requested)
# then 'ghcWithHoogle' is used to generate the derivation (instead of
# 'ghcWithPackages'), see the documentation there for more information.
developPackage =
{ root
, name ? builtins.baseNameOf root
, source-overrides ? {}
, overrides ? self: super: {}
, modifier ? drv: drv
, returnShellEnv ? pkgs.lib.inNixShell }:
, returnShellEnv ? pkgs.lib.inNixShell
, withHoogle ? returnShellEnv }:
let drv =
(extensible-self.extend
(pkgs.lib.composeExtensions
(self.packageSourceOverrides source-overrides)
overrides))
.callCabal2nix name root {};
in if returnShellEnv then (modifier drv).env else modifier drv;
in if returnShellEnv
then (modifier drv).envFunc {inherit withHoogle;}
else modifier drv;

ghcWithPackages = selectFrom: withPackages (selectFrom self);

# Put 'hoogle' into the derivation's PATH with a database containing all
# the package's dependencies; run 'hoogle server --local' in a shell to
# host a search engine for the dependencies.
#
# To reload the Hoogle server automatically on .cabal file changes try
# this:
# echo *.cabal | entr -r -- nix-shell --run 'hoogle server --local'
ghcWithHoogle = selectFrom:
let
packages = selectFrom self;
Expand Down