1 { pkgs, lib, config, ... }:
3 cfg = config.programs.nix-ld;
5 nix-ld-libraries = pkgs.buildEnv {
6 name = "lb-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;
17 # We currently take all libraries from systemd and nix as the default.
18 # Is there a better list?
19 baseLibraries = with pkgs; [
37 meta.maintainers = [ lib.maintainers.mic92 ];
38 options.programs.nix-ld = {
39 enable = lib.mkEnableOption (lib.mdDoc ''nix-ld, Documentation: <https://github.com/Mic92/nix-ld>'');
40 package = lib.mkPackageOptionMD pkgs "nix-ld" { };
41 libraries = lib.mkOption {
42 type = lib.types.listOf lib.types.package;
43 description = lib.mdDoc "Libraries that automatically become available to all programs. The default set includes common libraries.";
44 default = baseLibraries;
45 defaultText = lib.literalExpression "baseLibraries derived from systemd and nix dependencies.";
49 config = lib.mkIf config.programs.nix-ld.enable {
50 systemd.tmpfiles.packages = [ cfg.package ];
52 environment.systemPackages = [ nix-ld-libraries ];
54 environment.pathsToLink = [ "/share/nix-ld" ];
56 environment.variables = {
57 NIX_LD = "/run/current-system/sw/share/nix-ld/lib/ld.so";
58 NIX_LD_LIBRARY_PATH = "/run/current-system/sw/share/nix-ld/lib";