Skip to content

Commit

Permalink
add config.environment.ld-linux
Browse files Browse the repository at this point in the history
Add option to install symlink to ld-linux(8) system-wide to allow running unmodified ELF binaries.
It might be useful to run games or executables distributed inside jar files as discussed
https://discourse.nixos.org/t/runtime-alternative-to-patchelf-set-interpreter/3539
https://discourse.nixos.org/t/running-binaries-without-fhs-and-patchelf/1828

It is the third concession to FHS after `/bin/sh` and `/usr/bin/env` but it is disabled by default unlike those two
  • Loading branch information
volth committed Sep 18, 2019
1 parent e598c40 commit af665d8
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions nixos/modules/system/activation/activation-script.nix
Expand Up @@ -162,6 +162,16 @@ in
<literal>/usr/bin/env</literal>.
'';
};

environment.ld-linux = mkOption {
default = false;
type = types.bool;
visible = false;
description = ''
Install symlink to ld-linux(8) system-wide to allow running unmodified ELF binaries.
It might be useful to run games or executables distributed inside jar files.
'';
};
};


Expand Down Expand Up @@ -198,6 +208,27 @@ in
rmdir --ignore-fail-on-non-empty /usr/bin /usr
'';

system.activationScripts.ld-linux =
concatStrings (
mapAttrsToList
(target: source:
if config.environment.ld-linux then ''
mkdir -m 0755 -p $(dirname ${target})
ln -sfn ${escapeShellArg source} ${target}.tmp
mv -f ${target}.tmp ${target} # atomically replace
'' else ''
rm -f ${target}
rmdir --ignore-fail-on-non-empty $(dirname ${target})
'')
{
"i686-linux" ."/lib/ld-linux.so.2" = "${pkgs.glibc.out}/lib/ld-linux.so.2";
"x86_64-linux" ."/lib/ld-linux.so.2" = "${pkgs.pkgsi686Linux.glibc.out}/lib/ld-linux.so.2";
"x86_64-linux" ."/lib64/ld-linux-x86-64.so.2" = "${pkgs.glibc.out}/lib64/ld-linux-x86-64.so.2";
"aarch64-linux"."/lib/ld-linux-aarch64.so.1" = "${pkgs.glibc.out}/lib/ld-linux-aarch64.so.1";
"armv7l-linux" ."/lib/ld-linux-armhf.so.3" = "${pkgs.glibc.out}/lib/ld-linux-armhf.so.3";
}.${pkgs.stdenv.system} or {}
);

system.activationScripts.specialfs =
''
specialMount() {
Expand Down

0 comments on commit af665d8

Please sign in to comment.