nixpkgs/pkgs/by-name/ni/nix-ld/package.nix
2024-07-14 20:04:35 +02:00

54 lines
1.2 KiB
Nix

{
stdenv,
fetchFromGitHub,
nixosTests,
rustPlatform,
lib,
}:
rustPlatform.buildRustPackage {
name = "nix-ld";
src = fetchFromGitHub {
owner = "mic92";
repo = "nix-ld";
rev = "2.0.0";
sha256 = "sha256-rmSXQ4MYQe/OFDBRlqqw5kyp9b/aeEg0Fg9c167xofg=";
};
cargoHash = "sha256-w6CQx9kOyBtM2nMwdFb+LtU4oHVEYrTNVmH1A6R5DHM=";
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 $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
EOF
'';
passthru.tests = nixosTests.nix-ld;
meta = with lib; {
description = "Run unpatched dynamic binaries on NixOS";
homepage = "https://github.com/Mic92/nix-ld";
license = licenses.mit;
maintainers = with maintainers; [ mic92 ];
platforms = platforms.linux;
};
}