|
| 1 | +{ pkgs, lib, config, ... }: |
| 2 | +let |
| 3 | + cfg = config.programs.nix-ld.dev; |
| 4 | + |
| 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? |
| 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 | + }; |
| 16 | + |
| 17 | + # We currently take all libraries from systemd and nix as the default. |
| 18 | + # Is there a better list? |
| 19 | + baseLibraries = with pkgs; [ |
| 20 | + zlib |
| 21 | + zstd |
| 22 | + stdenv.cc.cc |
| 23 | + curl |
| 24 | + openssl |
| 25 | + attr |
| 26 | + libssh |
| 27 | + bzip2 |
| 28 | + libxml2 |
| 29 | + acl |
| 30 | + libsodium |
| 31 | + util-linux |
| 32 | + xz |
| 33 | + systemd |
| 34 | + ]; |
| 35 | +in |
| 36 | +{ |
| 37 | + meta.maintainers = [ lib.maintainers.mic92 ]; |
| 38 | + |
| 39 | + |
| 40 | + options.programs.nix-ld.dev = { |
| 41 | + enable = lib.mkEnableOption (lib.mdDoc ''nix-ld, Documentation: <https://github.com/Mic92/nix-ld>'') // { |
| 42 | + default = true; |
| 43 | + }; |
| 44 | + package = lib.mkOption { |
| 45 | + type = lib.types.package; |
| 46 | + description = lib.mdDoc "The package to be used for nix-ld."; |
| 47 | + default = pkgs.callPackage ../package.nix {}; |
| 48 | + }; |
| 49 | + libraries = lib.mkOption { |
| 50 | + type = lib.types.listOf lib.types.package; |
| 51 | + description = lib.mdDoc "Libraries that automatically become available to all programs. The default set includes common libraries."; |
| 52 | + default = baseLibraries; |
| 53 | + defaultText = lib.literalExpression "baseLibraries derived from systemd and nix dependencies."; |
| 54 | + }; |
| 55 | + }; |
| 56 | + |
| 57 | + config = lib.mkIf config.programs.nix-ld.dev.enable { |
| 58 | + assertions = [{ |
| 59 | + assertion = !config.programs.nix-ld.enable; |
| 60 | + message = '' |
| 61 | + nix-ld.dev cannot be enabled at the same time as nix-ld. |
| 62 | + ''; |
| 63 | + }]; |
| 64 | + |
| 65 | + systemd.tmpfiles.packages = [ cfg.package ]; |
| 66 | + |
| 67 | + environment.systemPackages = [ nix-ld-libraries ]; |
| 68 | + |
| 69 | + environment.pathsToLink = [ "/share/nix-ld" ]; |
| 70 | + |
| 71 | + environment.variables = { |
| 72 | + NIX_LD = "/run/current-system/sw/share/nix-ld/lib/ld.so"; |
| 73 | + NIX_LD_LIBRARY_PATH = "/run/current-system/sw/share/nix-ld/lib"; |
| 74 | + }; |
| 75 | + }; |
| 76 | +} |
| 77 | + |
0 commit comments