diff options
author | Jörg Thalheim <Mic92@users.noreply.github.com> | 2022-12-19 16:26:02 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-19 16:26:02 +0000 |
commit | 9bf4ec690947311dd0b080bb8d86a3019d5f4f24 (patch) | |
tree | edbfbe6de9f92d03ac5d1d7432992788258ca3f6 /nixos/modules/programs | |
parent | 1c387ed1a698417c3ccfe933f1c742279361ae17 (diff) | |
parent | aa65dd1225b268a0ed3631b20c812aea16c18d37 (diff) |
Merge pull request #206645 from Mic92/nix-ld
nixos/nix-ld: set NIX_LD by default
Diffstat (limited to 'nixos/modules/programs')
-rw-r--r-- | nixos/modules/programs/nix-ld.nix | 62 |
1 files changed, 60 insertions, 2 deletions
diff --git a/nixos/modules/programs/nix-ld.nix b/nixos/modules/programs/nix-ld.nix index 602278d1ba9b6..f753cf5f97e5b 100644 --- a/nixos/modules/programs/nix-ld.nix +++ b/nixos/modules/programs/nix-ld.nix @@ -1,10 +1,68 @@ { pkgs, lib, config, ... }: +let + cfg = config.programs.nix-ld; + + # TODO make glibc here configureable? + nix-ld-so = pkgs.runCommand "ld.so" {} '' + ln -s "$(cat '${pkgs.stdenv.cc}/nix-support/dynamic-linker')" $out + ''; + + nix-ld-libraries = pkgs.buildEnv { + name = "lb-library-path"; + pathsToLink = [ "/lib" ]; + paths = map lib.getLib cfg.libraries; + extraPrefix = "/share/nix-ld"; + ignoreCollisions = true; + }; + + # We currently take all libraries from systemd and nix as the default. + # Is there a better list? + baseLibraries = with pkgs; [ + zlib + zstd + stdenv.cc.cc + curl + openssl + attr + libssh + bzip2 + libxml2 + acl + libsodium + util-linux + xz + systemd + ]; +in { meta.maintainers = [ lib.maintainers.mic92 ]; options = { - programs.nix-ld.enable = lib.mkEnableOption (lib.mdDoc ''nix-ld, Documentation: <https://github.com/Mic92/nix-ld>''); + programs.nix-ld = { + enable = lib.mkEnableOption (lib.mdDoc ''nix-ld, Documentation: <https://github.com/Mic92/nix-ld>''); + package = lib.mkOption { + type = lib.types.package; + description = lib.mdDoc "Which package to use for the nix-ld."; + default = pkgs.nix-ld; + defaultText = lib.mdDoc "pkgs.nix-ld"; + }; + libraries = lib.mkOption { + type = lib.types.listOf lib.types.package; + description = lib.mdDoc "Libraries that automatically become available to all programs. The default set includes common libraries."; + default = baseLibraries; + defaultText = lib.mdDoc "baseLibraries"; + }; + }; }; config = lib.mkIf config.programs.nix-ld.enable { - systemd.tmpfiles.packages = [ pkgs.nix-ld ]; + systemd.tmpfiles.packages = [ cfg.package ]; + + environment.systemPackages = [ nix-ld-libraries ]; + + environment.pathsToLink = [ "/share/nix-ld" ]; + + environment.variables = { + NIX_LD = toString nix-ld-so; + NIX_LD_LIBRARY_PATH = "/run/current-system/sw/share/nix-ld/lib"; + }; }; } |