Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixos/nix-ld: set NIX_LD by default #206645

Merged
merged 2 commits into from
Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 60 additions & 2 deletions nixos/modules/programs/nix-ld.nix
Original file line number Diff line number Diff line change
@@ -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";
};
};
}
5 changes: 1 addition & 4 deletions nixos/tests/nix-ld.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ import ./make-test-python.nix ({ lib, pkgs, ...} :
};
testScript = ''
start_all()
path = "${pkgs.stdenv.cc}/nix-support/dynamic-linker"
with open(path) as f:
real_ld = f.read().strip()
machine.succeed(f"NIX_LD={real_ld} hello")
machine.succeed("hello")
'';
})
4 changes: 2 additions & 2 deletions pkgs/os-specific/linux/nix-ld/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ let
in
stdenv.mkDerivation rec {
pname = "nix-ld";
version = "1.0.2";
version = "1.0.3";

src = fetchFromGitHub {
owner = "mic92";
repo = "nix-ld";
rev = version;
sha256 = "sha256-DlWU5i/MykqWgB9vstYbECy3e+XagXWCxi+XDJNey0s=";
sha256 = "sha256-KmnT8YfU/KI4VxBlFMUltlAVLNvF7fTEQEsp41ZUHlA=";
};

doCheck = true;
Expand Down