at 24.11-pre 1.7 kB view raw
1{ pkgs, lib, config, ... }: 2let 3 cfg = config.programs.nix-ld; 4 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? 10 postBuild = '' 11 ln -s ${pkgs.stdenv.cc.bintools.dynamicLinker} $out/share/nix-ld/lib/ld.so 12 ''; 13 extraPrefix = "/share/nix-ld"; 14 ignoreCollisions = true; 15 }; 16in 17{ 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."; 25 default = [ ]; 26 defaultText = lib.literalExpression "baseLibraries derived from systemd and nix dependencies."; 27 }; 28 }; 29 30 config = lib.mkIf config.programs.nix-ld.enable { 31 environment.ldso = "${cfg.package}/libexec/nix-ld"; 32 33 environment.systemPackages = [ nix-ld-libraries ]; 34 35 environment.pathsToLink = [ "/share/nix-ld" ]; 36 37 environment.variables = { 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"; 40 }; 41 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; [ 45 zlib 46 zstd 47 stdenv.cc.cc 48 curl 49 openssl 50 attr 51 libssh 52 bzip2 53 libxml2 54 acl 55 libsodium 56 util-linux 57 xz 58 systemd 59 ]; 60 }; 61}