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;
|
2023-06-05 09:56:05 +02:00
|
|
|
# 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 = {
|
2024-04-13 14:54:15 +02:00
|
|
|
enable = lib.mkEnableOption ''nix-ld, Documentation: <https://github.com/Mic92/nix-ld>'';
|
2023-11-30 19:03:14 +01:00
|
|
|
package = lib.mkPackageOption pkgs "nix-ld" { };
|
2023-01-02 18:45:55 +01:00
|
|
|
libraries = lib.mkOption {
|
|
|
|
type = lib.types.listOf lib.types.package;
|
2024-04-13 14:54:15 +02:00
|
|
|
description = "Libraries that automatically become available to all programs. The default set includes common libraries.";
|
2024-03-27 20:41:01 +01:00
|
|
|
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 = {
|
2023-06-05 09:56:05 +02:00
|
|
|
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";
|
|
|
|
};
|
2024-03-27 20:41:01 +01:00
|
|
|
|
|
|
|
# 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
|
|
|
};
|
|
|
|
}
|