1 { pkgs, lib, config, ... }:
3 cfg = config.programs.nix-ld;
5 nix-ld-libraries = pkgs.buildEnv {
6 name = "ld-library-path";
7 pathsToLink = [ "/lib" ];
8 paths = map lib.getLib cfg.libraries;
9 # TODO make glibc here configurable?
11 ln -s ${pkgs.stdenv.cc.bintools.dynamicLinker} $out/share/nix-ld/lib/ld.so
13 extraPrefix = "/share/nix-ld";
14 ignoreCollisions = true;
18 meta.maintainers = [ lib.maintainers.mic92 ];
19 options.programs.nix-ld = {
20 enable = lib.mkEnableOption ''nix-ld, Documentation: <https://github.com/Mic92/nix-ld>'';
21 package = lib.mkPackageOption pkgs "nix-ld" { };
22 libraries = lib.mkOption {
23 type = lib.types.listOf lib.types.package;
24 description = "Libraries that automatically become available to all programs. The default set includes common libraries.";
26 defaultText = lib.literalExpression "baseLibraries derived from systemd and nix dependencies.";
30 config = lib.mkIf config.programs.nix-ld.enable {
31 environment.ldso = "${cfg.package}/libexec/nix-ld";
33 environment.systemPackages = [ nix-ld-libraries ];
35 environment.pathsToLink = [ "/share/nix-ld" ];
37 environment.sessionVariables = {
38 NIX_LD = "/run/current-system/sw/share/nix-ld/lib/ld.so";
39 NIX_LD_LIBRARY_PATH = "/run/current-system/sw/share/nix-ld/lib";
42 # We currently take all libraries from systemd and nix as the default.
43 # Is there a better list?
44 programs.nix-ld.libraries = with pkgs; [