nixpkgs/nixos/modules/programs/nix-ld.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

62 lines
1.7 KiB
Nix
Raw Normal View History

2022-03-15 13:22:18 +01:00
{ pkgs, lib, config, ... }:
2022-12-18 01:35:04 +01:00
let
cfg = config.programs.nix-ld;
nix-ld-libraries = pkgs.buildEnv {
2024-03-27 21:24:33 +01:00
name = "ld-library-path";
2022-12-18 01:35:04 +01:00
pathsToLink = [ "/lib" ];
paths = map lib.getLib cfg.libraries;
# TODO make glibc here configurable?
postBuild = ''
ln -s ${pkgs.stdenv.cc.bintools.dynamicLinker} $out/share/nix-ld/lib/ld.so
'';
2022-12-18 01:35:04 +01:00
extraPrefix = "/share/nix-ld";
ignoreCollisions = true;
};
in
2022-03-15 13:22:18 +01:00
{
meta.maintainers = [ lib.maintainers.mic92 ];
2023-01-02 18:45:55 +01:00
options.programs.nix-ld = {
enable = lib.mkEnableOption ''nix-ld, Documentation: <https://github.com/Mic92/nix-ld>'';
package = lib.mkPackageOption pkgs "nix-ld" { };
2023-01-02 18:45:55 +01:00
libraries = lib.mkOption {
type = lib.types.listOf lib.types.package;
description = "Libraries that automatically become available to all programs. The default set includes common libraries.";
default = [ ];
2023-01-02 18:45:55 +01:00
defaultText = lib.literalExpression "baseLibraries derived from systemd and nix dependencies.";
2022-12-18 01:35:04 +01:00
};
2022-03-15 13:22:18 +01:00
};
2023-01-02 18:45:55 +01:00
2022-03-15 13:22:18 +01:00
config = lib.mkIf config.programs.nix-ld.enable {
2023-11-27 12:50:25 +01:00
environment.ldso = "${cfg.package}/libexec/nix-ld";
2022-12-18 01:35:04 +01:00
environment.systemPackages = [ nix-ld-libraries ];
environment.pathsToLink = [ "/share/nix-ld" ];
environment.variables = {
NIX_LD = "/run/current-system/sw/share/nix-ld/lib/ld.so";
2022-12-18 01:35:04 +01:00
NIX_LD_LIBRARY_PATH = "/run/current-system/sw/share/nix-ld/lib";
};
# We currently take all libraries from systemd and nix as the default.
# Is there a better list?
programs.nix-ld.libraries = with pkgs; [
zlib
zstd
stdenv.cc.cc
curl
openssl
attr
libssh
bzip2
libxml2
acl
libsodium
util-linux
xz
systemd
];
2022-03-15 13:22:18 +01:00
};
}