1{
2 config,
3 lib,
4 pkgs,
5 ...
6}:
7
8let
9 inherit (lib)
10 last
11 splitString
12 mkOption
13 types
14 optionals
15 ;
16
17 libDir = pkgs.stdenv.hostPlatform.libDir;
18 ldsoBasename = builtins.unsafeDiscardStringContext (
19 last (splitString "/" pkgs.stdenv.cc.bintools.dynamicLinker)
20 );
21
22 # Hard-code to avoid creating another instance of nixpkgs. Also avoids eval errors in some cases.
23 libDir32 = "lib"; # pkgs.pkgsi686Linux.stdenv.hostPlatform.libDir
24 ldsoBasename32 = "ld-linux.so.2"; # last (splitString "/" pkgs.pkgsi686Linux.stdenv.cc.bintools.dynamicLinker)
25in
26{
27 options = {
28 environment.ldso = mkOption {
29 type = types.nullOr types.path;
30 default = null;
31 description = ''
32 The executable to link into the normal FHS location of the ELF loader.
33 '';
34 };
35
36 environment.ldso32 = mkOption {
37 type = types.nullOr types.path;
38 default = null;
39 description = ''
40 The executable to link into the normal FHS location of the 32-bit ELF loader.
41
42 This currently only works on x86_64 architectures.
43 '';
44 };
45 };
46
47 config = {
48 assertions = [
49 {
50 assertion = isNull config.environment.ldso32 || pkgs.stdenv.hostPlatform.isx86_64;
51 message = "Option environment.ldso32 currently only works on x86_64.";
52 }
53 ];
54
55 systemd.tmpfiles.rules =
56 (
57 if isNull config.environment.ldso then
58 [
59 "r /${libDir}/${ldsoBasename} - - - - -"
60 ]
61 else
62 [
63 "d /${libDir} 0755 root root - -"
64 "L+ /${libDir}/${ldsoBasename} - - - - ${config.environment.ldso}"
65 ]
66 )
67 ++ optionals pkgs.stdenv.hostPlatform.isx86_64 (
68 if isNull config.environment.ldso32 then
69 [
70 "r /${libDir32}/${ldsoBasename32} - - - - -"
71 ]
72 else
73 [
74 "d /${libDir32} 0755 root root - -"
75 "L+ /${libDir32}/${ldsoBasename32} - - - - ${config.environment.ldso32}"
76 ]
77 );
78 };
79
80 meta.maintainers = with lib.maintainers; [ tejing ];
81}