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

nix-ld-rs: init at 2024-03-23 #298607

Merged
merged 3 commits into from Mar 25, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
52 changes: 37 additions & 15 deletions nixos/tests/nix-ld.nix
@@ -1,17 +1,39 @@
import ./make-test-python.nix ({ lib, pkgs, ...} :
{ system ? builtins.currentSystem,
config ? {},
pkgs ? import ../.. { inherit system config; }
}:
let
inherit (import ../lib/testing-python.nix { inherit system pkgs; }) makeTest;
shared =
{ config, pkgs, ... }:
{
programs.nix-ld.enable = true;
environment.systemPackages = [
(pkgs.runCommand "patched-hello" { } ''
install -D -m755 ${pkgs.hello}/bin/hello $out/bin/hello
patchelf $out/bin/hello --set-interpreter $(cat ${config.programs.nix-ld.package}/nix-support/ldpath)
'')
];
};
in
{
name = "nix-ld";
nodes.machine = { pkgs, ... }: {
programs.nix-ld.enable = true;
environment.systemPackages = [
(pkgs.runCommand "patched-hello" {} ''
install -D -m755 ${pkgs.hello}/bin/hello $out/bin/hello
patchelf $out/bin/hello --set-interpreter $(cat ${pkgs.nix-ld}/nix-support/ldpath)
'')
];
nix-ld = makeTest {
name = "nix-ld";
nodes.machine = shared;
testScript = ''
start_all()
machine.succeed("hello")
'';
};
testScript = ''
start_all()
machine.succeed("hello")
'';
})
nix-ld-rs = makeTest {
name = "nix-ld-rs";
nodes.machine = {
imports = [ shared ];
programs.nix-ld.package = pkgs.nix-ld-rs;
};
testScript = ''
start_all()
machine.succeed("hello")
'';
};
}
54 changes: 54 additions & 0 deletions pkgs/by-name/ni/nix-ld-rs/package.nix
@@ -0,0 +1,54 @@
{
stdenv,
fetchFromGitHub,
nixosTests,
rustPlatform,
lib,
}:

rustPlatform.buildRustPackage {
name = "nix-ld-rs";

src = fetchFromGitHub {
owner = "nix-community";
repo = "nix-ld-rs";
rev = "f7154a6aedba4917c8cc72b805b79444b5bfafca";
sha256 = "sha256-tx6gO6NR4BnYVhoskyvQY9l6/8sK0HwoDHvsYcvIlgo=";
};

cargoHash = "sha256-4IDu5qAgF4Zq4GOsimuy8NiRCN9PXM+8oVzD2GO3QmM=";

hardeningDisable = [ "stackprotector" ];

NIX_SYSTEM = stdenv.system;
RUSTC_BOOTSTRAP = "1";

preCheck = ''
export NIX_LD=${stdenv.cc.bintools.dynamicLinker}
'';

postInstall = ''
mkdir -p $out/libexec
ln -s $out/bin/nix-ld-rs $out/libexec/nix-ld-rs
ln -s $out/bin/nix-ld-rs $out/libexec/nix-ld

mkdir -p $out/nix-support

ldpath=/${stdenv.hostPlatform.libDir}/$(basename ${stdenv.cc.bintools.dynamicLinker})
echo "$ldpath" > $out/nix-support/ldpath
mkdir -p $out/lib/tmpfiles.d/
cat > $out/lib/tmpfiles.d/nix-ld.conf <<EOF
L+ $ldpath - - - - $out/libexec/nix-ld-rs
EOF
'';

passthru.tests = nixosTests.nix-ld;

meta = with lib; {
description = "Run unpatched dynamic binaries on NixOS (rust version)";
homepage = "https://github.com/nix-community/nix-ld-rs";
license = licenses.mit;
maintainers = with maintainers; [ mic92 ];
platforms = platforms.linux;
};
}
Expand Up @@ -32,15 +32,15 @@ stdenv.mkDerivation rec {
postInstall = ''
mkdir -p $out/nix-support

ldpath=/${stdenv.hostPlatform.libDir}/$(basename $(< ${stdenv.cc}/nix-support/dynamic-linker))
ldpath=/${stdenv.hostPlatform.libDir}/$(basename ${stdenv.cc.bintools.dynamicLinker})
echo "$ldpath" > $out/nix-support/ldpath
mkdir -p $out/lib/tmpfiles.d/
cat > $out/lib/tmpfiles.d/nix-ld.conf <<EOF
L+ $ldpath - - - - $out/libexec/nix-ld
EOF
'';

passthru.tests.nix-ld = nixosTests.nix-ld;
passthru.tests = nixosTests.nix-ld;

meta = with lib; {
description = "Run unpatched dynamic binaries on NixOS";
Expand Down
2 changes: 0 additions & 2 deletions pkgs/top-level/all-packages.nix
Expand Up @@ -33416,8 +33416,6 @@ with pkgs;

nixos-shell = callPackage ../tools/virtualization/nixos-shell { };

nix-ld = callPackage ../os-specific/linux/nix-ld { };

noaa-apt = callPackage ../applications/radio/noaa-apt { };

node-problem-detector = callPackage ../applications/networking/cluster/node-problem-detector { };
Expand Down