Skip to content

Commit 204296f

Browse files
committed
More fixes and work arounds
1 parent 2611a66 commit 204296f

File tree

11 files changed

+53
-12
lines changed

11 files changed

+53
-12
lines changed

builder/comp-builder.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ let
239239
(lib.concatMap (c: if c.isHaskell or false
240240
then builtins.attrValues (c.components.exes or {})
241241
else [c]) build-tools) ++
242-
lib.optional (pkgconfig != []) buildPackages.pkgconfig;
242+
lib.optional (pkgconfig != []) buildPackages.cabalPkgConfigWrapper;
243243

244244
# Unfortunately, we need to wrap ghc commands for cabal builds to
245245
# work in the nix-shell. See ../doc/removing-with-package-wrapper.md.

builder/default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ let
1717
# in the native case, it would be the same in the cross case however
1818
# we *really* want to build the Setup.hs on the build machine and not
1919
# have the stdenv confuse it with the target/host env.
20-
inherit (buildPackages) stdenv pkgconfig;
20+
inherit (buildPackages) stdenv;
2121
inherit buildPackages;
2222
inherit haskellLib nonReinstallablePkgs makeSetupConfigFiles;
2323
};

builder/setup-builder.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{ pkgs, stdenv, lib, buildPackages, haskellLib, ghc, nonReinstallablePkgs, hsPkgs, makeSetupConfigFiles, pkgconfig }@defaults:
1+
{ pkgs, stdenv, lib, buildPackages, haskellLib, ghc, nonReinstallablePkgs, hsPkgs, makeSetupConfigFiles }@defaults:
22

33
let self =
44
{ component, package, name, src, enableDWARF ? false, flags ? {}, revision ? null, patches ? [], defaultSetupSrc
@@ -38,7 +38,7 @@ let
3838
(lib.concatMap (c: if c.isHaskell or false
3939
then builtins.attrValues (c.components.exes or {})
4040
else [c]) component.build-tools) ++
41-
lib.optional (component.pkgconfig != []) pkgconfig;
41+
lib.optional (component.pkgconfig != []) buildPackages.cabalPkgConfigWrapper;
4242

4343
drv =
4444
stdenv.mkDerivation ({

lib/call-cabal-project-to-nix.nix

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ in
6666
# any plutus-apps input being used for a
6767
# package.
6868
, evalPackages
69-
, pkgconfSelector ? (_: [])
69+
, pkgconfigSelector ? (_: [])
7070
, ...
7171
}@args:
7272

@@ -467,7 +467,9 @@ let
467467
inherit checkMaterialization;
468468
}) (evalPackages.runCommand (nameAndSuffix "plan-to-nix-pkgs") {
469469
nativeBuildInputs = [ nix-tools dummy-ghc dummy-ghc-pkg cabal-install evalPackages.rsync evalPackages.gitMinimal evalPackages.pkgconfig ];
470-
buildInputs = pkgconfSelector pkgconfPkgs;
470+
# We only need the `.dev` derivation (if there is one), since it will have
471+
# the pkgconfig files needed by cabal.
472+
buildInputs = map pkgs.lib.getDev (builtins.concatLists (pkgconfigSelector pkgconfPkgs));
471473
# Needed or stack-to-nix will die on unicode inputs
472474
LOCALE_ARCHIVE = pkgs.lib.optionalString (evalPackages.stdenv.buildPlatform.libc == "glibc") "${evalPackages.glibcLocales}/lib/locale/locale-archive";
473475
LANG = "en_US.UTF-8";

lib/pkgconf-nixpkgs-map.nix

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,7 @@ pkgs:
143143
"sctp" = [ pkgs."lksctp-tools" ]; # This is linux-specific, we should create a common attribute if we ever add sctp support for other systems.
144144
"sdl2" = [ pkgs."SDL2" ];
145145
"sndfile" = [ pkgs."libsndfile" ];
146-
"sodium" = [ pkgs."libsodium".dev ];
147-
"libsodium" = [ pkgs."libsodium".dev ];
146+
"sodium" = [ pkgs."libsodium" ];
148147
"sqlite3" = [ pkgs."sqlite" ];
149148
"ssh2" = [ pkgs."libssh2" ];
150149
"statgrab" = [ pkgs."libstatgrab" ];

modules/cabal-project.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ in {
130130
type = nullOr (listOf unspecified);
131131
default = [];
132132
};
133-
pkgconfSelector = mkOption {
133+
pkgconfigSelector = mkOption {
134134
type = unspecified;
135135
default = (_: []);
136136
};

overlays/cabal-pkg-config.nix

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
final: prev:
2+
{
3+
# cabal 3.8 asks pkg-config for linker options for both
4+
# dynamic and static linking.
5+
# For some derivations (glib for instance) pkg-config can
6+
# fail when `--static` is passed. This might be because
7+
# the library only has dynamic libraries.
8+
#
9+
# To work around this problem this wrapper makes cabal lazy
10+
# by return a single command line option when it fails.
11+
# That option should never be used and if it is hopefully
12+
# the name of the option itself will be helpful.
13+
#
14+
# See https://github.com/input-output-hk/haskell.nix/issues/1642
15+
#
16+
cabalPkgConfigWrapper = prev.pkgconfig.overrideAttrs (attrs: {
17+
installPhase = attrs.installPhase + ''
18+
mv $out/bin/${attrs.targetPrefix}${attrs.baseBinName} \
19+
$out/bin/${attrs.targetPrefix}${attrs.baseBinName}-wrapped
20+
21+
cat <<EOF >$out/bin/${attrs.targetPrefix}${attrs.baseBinName}
22+
#!${final.stdenv.shell}
23+
if [[ "\$1" == "--libs" && "\$2" == "--static" ]]; then
24+
OUTPUT=\$(mktemp)
25+
ERROR=\$(mktemp)
26+
if ${final.pkgconfig}/bin/pkg-config "\$@" >output 2>\$ERROR; then
27+
cat \$OUTPUT
28+
else
29+
echo "--error-pkg-config-static-failed=\$ERROR"
30+
fi
31+
else
32+
${final.pkgconfig}/bin/pkg-config "\$@"
33+
fi
34+
EOF
35+
chmod +x $out/bin/${attrs.targetPrefix}${attrs.baseBinName}
36+
'';
37+
});
38+
}

overlays/default.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ let
2121
gobject-introspection = import ./gobject-introspection.nix;
2222
hix = import ./hix.nix;
2323
ghcjs = import ./ghcjs.nix;
24+
cabalPkgConfig = import ./cabal-pkg-config.nix;
2425
};
2526

2627
composeExtensions = f: g: final: prev:
@@ -51,6 +52,7 @@ let
5152
emscripten
5253
nix-prefetch-git-minimal
5354
ghcjs
55+
cabalPkgConfig
5456
gobject-introspection
5557
hix
5658
hydra

test/exe-dlls/default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ let
77
project = project' {
88
inherit compiler-nix-name evalPackages;
99
src = testSrc "exe-dlls";
10-
pkgconfSelector = p: [p.libsodium];
10+
pkgconfigSelector = p: [p.libsodium];
1111
};
1212

1313
packages = project.hsPkgs;

test/exe-lib-dlls/default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ let
77
project = project' {
88
inherit compiler-nix-name evalPackages;
99
src = testSrc "exe-lib-dlls";
10-
pkgconfSelector = p: [p.libsodium];
10+
pkgconfigSelector = p: [p.libsodium];
1111
};
1212

1313
packages = project.hsPkgs;

test/th-dlls/default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ let
77
project = project' {
88
inherit compiler-nix-name evalPackages;
99
src = testSrc "th-dlls";
10-
pkgconfSelector = p: [p.libsodium];
10+
pkgconfigSelector = p: [p.libsodium];
1111
};
1212

1313
packages = project.hsPkgs;

0 commit comments

Comments
 (0)