Skip to content

Commit 0611d1c

Browse files
authored
Merge pull request #24 from Mic92/ci
fix import from derivation eval errors when used in pure mode.
2 parents 9c2ba8a + fce39fd commit 0611d1c

File tree

8 files changed

+145
-122
lines changed

8 files changed

+145
-122
lines changed

default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
{ pkgs ? import <nixpkgs> {} }:
1+
{pkgs ? import <nixpkgs> {}}:
22
pkgs.callPackage ./nix-ld.nix {}

examples/masterpdfeditor.nix

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,29 @@
11
with import <nixpkgs> {};
2-
32
# run with
43
# $ nix-shell ./masterpdfeditor.nix
4+
mkShell {
5+
NIX_LD_LIBRARY_PATH = lib.makeLibraryPath [
6+
nss
7+
sane-backends
8+
nspr
9+
qt5.qtbase
10+
qt5.qtsvg
11+
stdenv.cc.cc
12+
];
513

6-
mkShell {
7-
NIX_LD_LIBRARY_PATH = lib.makeLibraryPath [
8-
nss
9-
sane-backends
10-
nspr
11-
qt5.qtbase
12-
qt5.qtsvg
13-
stdenv.cc.cc
14-
];
15-
16-
NIX_LD = builtins.readFile "${stdenv.cc}/nix-support/dynamic-linker";
14+
NIX_LD = builtins.readFile "${stdenv.cc}/nix-support/dynamic-linker";
1715

18-
QT_PLUGIN_PATH = "${qt5.qtbase}/${qt5.qtbase.qtPluginPrefix}";
16+
QT_PLUGIN_PATH = "${qt5.qtbase}/${qt5.qtbase.qtPluginPrefix}";
1917

20-
shellHook = ''
21-
if [ ! -d master-pdf-editor ]; then
22-
echo "unpack master-pdf-editor..."
23-
mkdir master-pdf-editor
24-
tar -C master-pdf-editor \
25-
--strip-components 1 \
26-
-xf ${masterpdfeditor.src}
27-
fi
28-
echo '$ ./master-pdf-editor/masterpdfeditor5'
29-
./master-pdf-editor/masterpdfeditor5
30-
'';
31-
}
18+
shellHook = ''
19+
if [ ! -d master-pdf-editor ]; then
20+
echo "unpack master-pdf-editor..."
21+
mkdir master-pdf-editor
22+
tar -C master-pdf-editor \
23+
--strip-components 1 \
24+
-xf ${masterpdfeditor.src}
25+
fi
26+
echo '$ ./master-pdf-editor/masterpdfeditor5'
27+
./master-pdf-editor/masterpdfeditor5
28+
'';
29+
}

examples/zoom.nix

Lines changed: 45 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,50 @@
1-
with import <nixpkgs> {};
2-
3-
let
1+
with import <nixpkgs> {}; let
42
version = "5.4.57862.0110";
53
src = fetchurl {
64
url = "https://zoom.us/client/${version}/zoom_x86_64.pkg.tar.xz";
75
sha256 = "sha256-ZAwXhbZ3nT6PGkSC1vnX2y/XUOZfped0r3OuedI62gY=";
86
};
9-
in mkShell {
10-
NIX_LD_LIBRARY_PATH = lib.makeLibraryPath [
11-
# found by
12-
# $ LD_LIBRARY_PATH=$NIX_LD_LIBRARY_PATH:$PWD ldd zoom | grep 'not found'
13-
alsaLib
14-
atk
15-
cairo
16-
dbus
17-
libGL
18-
fontconfig
19-
freetype
20-
gtk3
21-
gdk-pixbuf
22-
glib
23-
pango
24-
stdenv.cc.cc
25-
pulseaudio
26-
wayland
27-
xorg.libX11
28-
xorg.libxcb
29-
xorg.libXcomposite
30-
xorg.libXext
31-
libxkbcommon
32-
xorg.libXrender
33-
zlib
34-
xorg.xcbutilimage
35-
xorg.xcbutilkeysyms
36-
xorg.libXfixes
37-
xorg.libXtst
38-
];
39-
NIX_LD = builtins.readFile "${stdenv.cc}/nix-support/dynamic-linker";
40-
shellHook = ''
41-
if [ ! -d zoom ]; then
42-
echo "unpack zoom..."
43-
mkdir zoom
44-
tar -C zoom \
45-
-xf ${src}
46-
fi
47-
export LD_LIBRARY_PATH=$PWD/zoom/opt/zoom/
48-
echo '$ ./zoom/opt/zoom/ZoomLauncher'
49-
./zoom/opt/zoom/ZoomLauncher
50-
'';
51-
}
7+
in
8+
mkShell {
9+
NIX_LD_LIBRARY_PATH = lib.makeLibraryPath [
10+
# found by
11+
# $ LD_LIBRARY_PATH=$NIX_LD_LIBRARY_PATH:$PWD ldd zoom | grep 'not found'
12+
alsaLib
13+
atk
14+
cairo
15+
dbus
16+
libGL
17+
fontconfig
18+
freetype
19+
gtk3
20+
gdk-pixbuf
21+
glib
22+
pango
23+
stdenv.cc.cc
24+
pulseaudio
25+
wayland
26+
xorg.libX11
27+
xorg.libxcb
28+
xorg.libXcomposite
29+
xorg.libXext
30+
libxkbcommon
31+
xorg.libXrender
32+
zlib
33+
xorg.xcbutilimage
34+
xorg.xcbutilkeysyms
35+
xorg.libXfixes
36+
xorg.libXtst
37+
];
38+
NIX_LD = builtins.readFile "${stdenv.cc}/nix-support/dynamic-linker";
39+
shellHook = ''
40+
if [ ! -d zoom ]; then
41+
echo "unpack zoom..."
42+
mkdir zoom
43+
tar -C zoom \
44+
-xf ${src}
45+
fi
46+
export LD_LIBRARY_PATH=$PWD/zoom/opt/zoom/
47+
echo '$ ./zoom/opt/zoom/ZoomLauncher'
48+
./zoom/opt/zoom/ZoomLauncher
49+
'';
50+
}

flake.nix

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,19 @@
77
nixConfig.extra-substituters = [ "https://cache.garnix.io" ];
88
nixConfig.extra-trusted-public-keys = [ "cache.garnix.io:CTFPyKSLcx5RMJKfLo5EEPUObbA78b0YQ2DTCJXqr9g=" ];
99

10-
outputs = { self, nixpkgs, utils }: {
11-
nixosModules.nix-ld = import ./modules/nix-ld.nix;
12-
} // utils.lib.eachSystem ["x86_64-linux" "aarch64-linux"] (system: let
13-
pkgs = nixpkgs.legacyPackages.${system};
14-
in {
15-
packages.nix-ld = pkgs.callPackage ./default.nix {};
16-
defaultPackage = self.packages.${system}.nix-ld;
17-
});
10+
outputs = {
11+
self,
12+
nixpkgs,
13+
utils,
14+
}:
15+
{
16+
nixosModules.nix-ld = import ./modules/nix-ld.nix;
17+
}
18+
// utils.lib.eachSystem ["x86_64-linux" "aarch64-linux"] (system: let
19+
pkgs = nixpkgs.legacyPackages.${system};
20+
in {
21+
packages.nix-ld = pkgs.callPackage ./default.nix {};
22+
defaultPackage = self.packages.${system}.nix-ld;
23+
checks = self.packages.${system}.nix-ld.tests;
24+
});
1825
}

modules/nix-ld.nix

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
{ pkgs, ... }:
2-
{
3-
systemd.tmpfiles.rules = let
4-
nix-ld = pkgs.callPackage ./.. { inherit pkgs; };
5-
in [
6-
"L+ ${nix-ld.ldPath} - - - - ${nix-ld}/libexec/nix-ld"
1+
{pkgs, ...}: {
2+
systemd.tmpfiles.packages = [
3+
(pkgs.callPackage ../nix-ld.nix {})
74
];
85
}

nix-ld.nix

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,31 @@
1-
{ lib, system, stdenv, meson, ninja, overrideCC, path, pkgs }:
2-
let
3-
self = stdenv.mkDerivation rec {
1+
{
2+
lib,
3+
stdenv,
4+
meson,
5+
ninja,
6+
overrideCC,
7+
path,
8+
pkgs,
9+
}: let
10+
libDir =
11+
if
12+
stdenv.system
13+
== "x86_64-linux"
14+
|| stdenv.system == "mips64-linux"
15+
|| stdenv.system == "powerpc64le-linux"
16+
then "/lib64"
17+
else "/lib";
18+
in
19+
stdenv.mkDerivation rec {
420
name = "nix-ld";
521
src = ./.;
622

723
doCheck = true;
824

9-
nativeBuildInputs = [ meson ninja ];
25+
nativeBuildInputs = [meson ninja];
1026

1127
mesonFlags = [
12-
"-Dnix-system=${system}"
28+
"-Dnix-system=${stdenv.system}"
1329
];
1430

1531
hardeningDisable = [
@@ -18,22 +34,25 @@ let
1834

1935
postInstall = ''
2036
mkdir -p $out/nix-support
21-
basename $(< ${stdenv.cc}/nix-support/dynamic-linker) > $out/nix-support/ld-name
37+
38+
ldpath=${libDir}/$(basename $(< ${stdenv.cc}/nix-support/dynamic-linker))
39+
echo "$ldpath" > $out/nix-support/ldpath
40+
mkdir -p $out/lib/tmpfiles.d/
41+
cat > $out/lib/tmpfiles.d/nix-ld.conf <<EOF
42+
L+ $ldpath - - - - $out/libexec/nix-ld
43+
EOF
2244
'';
2345

2446
passthru.tests = import ./nixos-test.nix {
2547
makeTest = import (path + "/nixos/tests/make-test-python.nix");
2648
inherit pkgs;
2749
};
28-
passthru.ldPath = let
29-
libDir = if system == "x86_64-linux" ||
30-
system == "mips64-linux" ||
31-
system == "powerpc64le-linux"
32-
then
33-
"/lib64"
34-
else
35-
"/lib";
36-
ldName = lib.fileContents "${self}/nix-support/ld-name";
37-
in "${libDir}/${ldName}";
38-
};
39-
in self
50+
51+
meta = with lib; {
52+
description = "Run unpatched dynamic binaries on NixOS";
53+
homepage = "https://github.com/Mic92/nix-ld";
54+
license = licenses.mit;
55+
maintainers = with maintainers; [ mic92 ];
56+
platforms = platforms.unix;
57+
};
58+
}

nixos-example.nix

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
{ pkgs, ... }:
2-
{
3-
imports = [ ./modules/nix-ld.nix ];
1+
{pkgs, ...}: {
2+
imports = [./modules/nix-ld.nix];
43
environment.systemPackages = [
54
(pkgs.runCommand "patched-hello" {} ''
65
install -D -m755 ${pkgs.hello}/bin/hello $out/bin/hello
7-
patchelf $out/bin/hello --set-interpreter ${(pkgs.callPackage ./. {}).ldPath}
6+
patchelf $out/bin/hello --set-interpreter $(cat ${(pkgs.callPackage ./. {})}/nix-support/ldpath)
87
'')
98
];
109
}

nixos-test.nix

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
1-
{ makeTest ? import <nixpkgs/nixos/tests/make-test-python.nix>, pkgs ? import <nixpkgs> }:
21
{
3-
smoketest = makeTest {
4-
name = "smoketest";
5-
nodes.machine = import ./nixos-example.nix;
6-
testScript = ''
7-
start_all()
8-
path = "${pkgs.stdenv.cc}/nix-support/dynamic-linker"
9-
with open(path) as f:
10-
real_ld = f.read().strip()
11-
machine.succeed(f"NIX_LD={real_ld} hello")
12-
'';
13-
} {
14-
inherit pkgs;
15-
};
2+
makeTest ? import <nixpkgs/nixos/tests/make-test-python.nix>,
3+
pkgs ? import <nixpkgs>,
4+
}: {
5+
smoketest =
6+
makeTest {
7+
name = "smoketest";
8+
nodes.machine = import ./nixos-example.nix;
9+
testScript = ''
10+
start_all()
11+
path = "${pkgs.stdenv.cc}/nix-support/dynamic-linker"
12+
with open(path) as f:
13+
real_ld = f.read().strip()
14+
machine.succeed(f"NIX_LD={real_ld} hello")
15+
'';
16+
} {
17+
inherit pkgs;
18+
inherit (pkgs) system;
19+
};
1620
}

0 commit comments

Comments
 (0)