Skip to content

Commit a045d79

Browse files
paumrrvlhamishmack
authored
Updated system-nixpkgs-map.nix and a default for X11 package (fixes #984) (#988)
After investigating adding a project argument to override the mapping of libs to packages we realised we could fix the X11 package by updating `modules/configuration-nix.nix`. We also updated `system-nixpkgs-map.nix` to allow multiple packages to be mapped for a single library (turned out not to be necessary for X11). Co-authored-by: Rodney Lorrimar <[email protected]> Co-authored-by: Hamish Mackenzie <[email protected]>
1 parent 4b213e7 commit a045d79

File tree

5 files changed

+152
-84
lines changed

5 files changed

+152
-84
lines changed

docs/tutorials/pkg-map.md

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,39 @@ nixpkgs.overlays = [
2929
];
3030
```
3131

32+
### Replace libraries of components
33+
34+
If a component is missing a dependency it can be added via modules. For example:
35+
36+
``` nix
37+
project = pkgs.haskell-nix.project' {
38+
src = self;
39+
compiler-nix-name = "ghc8102";
40+
modules = [{
41+
# Replace `extra-libraries` dependencies
42+
packages.X11.components.library.libs = pkgs.lib.mkForce (with pkgs.xorg;
43+
[ libX11 libXrandr libXext libXScrnSaver libXinerama ]);
44+
}];
45+
};
46+
```
47+
3248
### Mapping in Haskell.nix
3349

3450
Alternatively, if the name is commonly used, an alias can be added to
3551
the Haskell.nix sources, so that it's solved for all users.
3652

37-
* [`lib/pkgconf-nixpkgs-map.nix`](https://github.com/input-output-hk/haskell.nix/blob/master/lib/pkgconf-nixpkgs-map.nix) - for `pkgconfig-depends`
38-
* [`lib/system-nixpkgs-map.nix`](https://github.com/input-output-hk/haskell.nix/blob/master/lib/system-nixpkgs-map.nix) - for `build-tool-depends`, `frameworks`, `extra-libraries`, etc.
53+
* [`lib/pkgconf-nixpkgs-map.nix`](https://github.com/input-output-hk/haskell.nix/blob/master/lib/pkgconf-nixpkgs-map.nix)
54+
— for `pkgconfig-depends`.
55+
56+
Each mapping entry is a list of packages.
57+
58+
* [`lib/system-nixpkgs-map.nix`](https://github.com/input-output-hk/haskell.nix/blob/master/lib/system-nixpkgs-map.nix)
59+
— for `build-tool-depends`, `frameworks`, `extra-libraries`, etc.
60+
61+
Each name can be mapped to:
62+
1. A single package from nixkpgs.
63+
2. `null` — eliminates the dependency
64+
3. A list of packages — sometimes needed for dependencies such as `X11`.
3965

4066
!!! tip "Open a PR"
4167
Please go ahead and open a [pull request](https://github.com/input-output-hk/haskell.nix/pulls)

lib/system-nixpkgs-map.nix

Lines changed: 83 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,86 @@
1-
# Maps of system pkg references from
2-
# cabal file to nixpkgs pkgs.
3-
# See ../docs/dev/pkg-map.md
1+
# Maps of system pkg references from cabal file to nixpkgs pkgs.
2+
# library name (from `extra-libraries` field of `.cabal` file) -> nixpkgs package(s) mapping.
3+
# This mapping is used to construct the `libs` component attribute.
4+
# See ../docs/tutorials/pkg-map.md
45
pkgs:
5-
# fetchgit should always come from the evalPackages
6-
# if it comes from the targetPackages we won't even
7-
# be able to execute it.
8-
{ fetchgit = pkgs.evalPackages.fetchgit; }
9-
# haskell lib -> nix lib mapping
6+
7+
with pkgs;
8+
109
# -- linux
11-
// { crypto = pkgs.openssl;
12-
"c++" = null; # no libc++
13-
"stdc++" = null; "stdc++-6" = null;
14-
ssl = pkgs.openssl;
15-
z = pkgs.zlib;
16-
pthread = null; # available by default
17-
GL = pkgs.libGL;
18-
GLU = pkgs.libGLU;
19-
alut = pkgs.freealut;
20-
X11 = pkgs.xorg.libX11;
21-
Xrandr = pkgs.xorg.libXrandr;
22-
Xext = pkgs.xorg.libXext;
23-
Xi = pkgs.xorg.libXi;
24-
Xxf86vm = pkgs.xorg.libXxf86vm;
25-
Xcursor = pkgs.xorg.libXcursor;
26-
Xinerama = pkgs.xorg.libXinerama;
27-
mysqlclient = pkgs.mysql;
28-
Imlib2 = pkgs.imlib2;
29-
asound = pkgs.alsaLib;
30-
ffi = null;
31-
bz2 = pkgs.bzip2;
32-
util = pkgs.utillinux;
33-
magic = pkgs.file;
34-
pq = pkgs.postgresql;
35-
iconv = pkgs.libiconv;
36-
lapack = pkgs.liblapack;
37-
boost_atomic = pkgs.boost;
38-
boost_chrono = pkgs.boost;
39-
boost_container = pkgs.boost;
40-
boost_context = pkgs.boost;
41-
boost_contract = pkgs.boost;
42-
boost_coroutine = pkgs.boost;
43-
boost_date_time = pkgs.boost;
44-
boost_fiber = pkgs.boost;
45-
boost_filesystem = pkgs.boost;
46-
boost_graph = pkgs.boost;
47-
boost_iostreams = pkgs.boost;
48-
boost_locale = pkgs.boost;
49-
boost_log_setup = pkgs.boost;
50-
boost_log = pkgs.boost;
51-
boost_math_c99f = pkgs.boost;
52-
boost_math_c99l = pkgs.boost;
53-
boost_math_c99 = pkgs.boost;
54-
boost_math_tr1f = pkgs.boost;
55-
boost_math_tr1l = pkgs.boost;
56-
boost_math_tr1 = pkgs.boost;
57-
boost_prg_exec_monitor = pkgs.boost;
58-
boost_program_options = pkgs.boost;
59-
boost_random = pkgs.boost;
60-
boost_regex = pkgs.boost;
61-
boost_serialization = pkgs.boost;
62-
boost_signals = pkgs.boost;
63-
boost_stacktrace_addr2line = pkgs.boost;
64-
boost_stacktrace_basic = pkgs.boost;
65-
boost_stacktrace_noop = pkgs.boost;
66-
boost_system = pkgs.boost;
67-
boost_thread = pkgs.boost;
68-
boost_timer = pkgs.boost;
69-
boost_type_erasure = pkgs.boost;
70-
boost_unit_test_framework = pkgs.boost;
71-
boost_wave = pkgs.boost;
72-
boost_wserialization = pkgs.boost;
73-
tensorflow = pkgs.libtensorflow;
74-
opencv = pkgs.opencv3;
75-
icuuc = pkgs.icu;
76-
icui18n = pkgs.icu;
77-
icudata = pkgs.icu;
78-
vulkan = pkgs.vulkan-loader;
79-
sodium = pkgs.libsodium;
80-
gfortran = pkgs.gfortran.cc.lib;
81-
}
10+
{ crypto = [ openssl ];
11+
"c++" = null; # no libc++
12+
"stdc++" = null;
13+
"stdc++-6" = null;
14+
ssl = [ openssl ];
15+
z = [ zlib ];
16+
pthread = null; # available by default
17+
GL = [ libGL ];
18+
GLU = [ libGLU ];
19+
alut = [ freealut ];
20+
X11 = with xorg; [ libX11 ];
21+
Xrandr = [ xorg.libXrandr ];
22+
Xrender = [ xorg.libXrender ];
23+
Xss = [ xorg.libXScrnSaver ];
24+
Xext = [ xorg.libXext ];
25+
Xi = [ xorg.libXi ];
26+
Xxf86vm = [ xorg.libXxf86vm ];
27+
Xcursor = [ xorg.libXcursor ];
28+
Xinerama = [ xorg.libXinerama ];
29+
mysqlclient = [ mysql ];
30+
Imlib2 = [ imlib2 ];
31+
asound = [ alsaLib ];
32+
ffi = null;
33+
bz2 = [ bzip2 ];
34+
util = [ utillinux ];
35+
magic = [ file ];
36+
pq = [ postgresql ];
37+
iconv = [ libiconv ];
38+
lapack = [ liblapack ];
39+
boost_atomic = [ boost ];
40+
boost_chrono = [ boost ];
41+
boost_container = [ boost ];
42+
boost_context = [ boost ];
43+
boost_contract = [ boost ];
44+
boost_coroutine = [ boost ];
45+
boost_date_time = [ boost ];
46+
boost_fiber = [ boost ];
47+
boost_filesystem = [ boost ];
48+
boost_graph = [ boost ];
49+
boost_iostreams = [ boost ];
50+
boost_locale = [ boost ];
51+
boost_log_setup = [ boost ];
52+
boost_log = [ boost ];
53+
boost_math_c99f = [ boost ];
54+
boost_math_c99l = [ boost ];
55+
boost_math_c99 = [ boost ];
56+
boost_math_tr1f = [ boost ];
57+
boost_math_tr1l = [ boost ];
58+
boost_math_tr1 = [ boost ];
59+
boost_prg_exec_monitor = [ boost ];
60+
boost_program_options = [ boost ];
61+
boost_random = [ boost ];
62+
boost_regex = [ boost ];
63+
boost_serialization = [ boost ];
64+
boost_signals = [ boost ];
65+
boost_stacktrace_addr2line = [ boost ];
66+
boost_stacktrace_basic = [ boost ];
67+
boost_stacktrace_noop = [ boost ];
68+
boost_system = [ boost ];
69+
boost_thread = [ boost ];
70+
boost_timer = [ boost ];
71+
boost_type_erasure = [ boost ];
72+
boost_unit_test_framework = [ boost ];
73+
boost_wave = [ boost ];
74+
boost_wserialization = [ boost ];
75+
tensorflow = [ libtensorflow ];
76+
opencv = [ opencv3 ];
77+
icuuc = [ icu ];
78+
icui18n = [ icu ];
79+
icudata = [ icu ];
80+
vulkan = [ vulkan-loader ];
81+
sodium = [ libsodium ];
82+
gfortran = [ gfortran.cc.lib ];
83+
}
8284
# -- windows
8385
// { advapi32 = null; gdi32 = null; imm32 = null; msimg32 = null;
8486
shell32 = null; shfolder = null; shlwapi = null; user32 = null;
@@ -88,12 +90,12 @@ pkgs:
8890
# if it's not we have more severe
8991
# issues anyway.
9092
gcc_s_seh-1 = null;
91-
ssl32 = null; eay32 = pkgs.openssl;
93+
ssl32 = null; eay32 = [ openssl ];
9294
iphlpapi = null; # IP Help API
9395
msvcrt = null; # this is the libc
9496
Crypt32 = null;
9597
mswsock = null;
9698
}
9799
# -- os x
98100
# NB: these map almost 1:1 to the framework names
99-
// pkgs.darwin.apple_sdk.frameworks
101+
// darwin.apple_sdk.frameworks

lib/system-pkgs.nix

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Cabal packages can depend on operating system packages. However
2+
# package names vary between distributions - there is no standard.
3+
#
4+
# This file augments the nixpkgs package set with extra attributes
5+
# from the system packages map file.
6+
#
7+
# This package set will be used when resolving system package
8+
# dependencies of package descriptions.
9+
10+
pkgs:
11+
12+
let
13+
buildEnvMaybe = name: paths:
14+
if builtins.length paths == 1
15+
then builtins.head paths
16+
else pkgs.buildEnv { name = "${name}-env"; inherit paths; };
17+
18+
mapPackages = name: ps:
19+
if builtins.typeOf ps == "list"
20+
then buildEnvMaybe name ps
21+
else ps;
22+
23+
in
24+
# Base packages.
25+
pkgs
26+
27+
# fetchgit should always come from the evalPackages
28+
# if it comes from the targetPackages we won't even
29+
# be able to execute it.
30+
// { fetchgit = pkgs.evalPackages.fetchgit; }
31+
32+
# Apply the mapping.
33+
// builtins.mapAttrs mapPackages (import ./system-nixpkgs-map.nix pkgs)

modules/configuration-nix.nix

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,11 @@
88
# this if we used the terminfo shipped with GHC, but this package is
99
# reinstallable so we'd rather have it defined in the plan.
1010
packages.terminfo.components.library.libs = [pkgs.ncurses];
11+
12+
# The `extra-libraries` field in `X11.cabal` does not include Xss and Xinerama
13+
# see https://github.com/input-output-hk/haskell.nix/pull/988
14+
packages.X11.components.library.libs = [
15+
pkgs.xorg.libXScrnSaver
16+
pkgs.xorg.libXinerama
17+
];
1118
}

package-set.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ in pkgs.lib.evalModules {
1212
# The package descriptions depend on pkgs, which are used to resolve system package dependencies
1313
# as well as pkgconfPkgs, which are used to resolve pkgconfig name to nixpkgs names. We simply
1414
# augment the existing pkgs set with the specific mappings:
15-
pkgs = pkgs // (import ./lib/system-nixpkgs-map.nix pkgs);
15+
pkgs = import ./lib/system-pkgs.nix pkgs;
1616
pkgconfPkgs = import ./lib/pkgconf-nixpkgs-map.nix pkgs;
1717

1818
inherit buildModules;

0 commit comments

Comments
 (0)