mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-15 06:14:57 +01:00
6afb255d97
these changes were generated with nixq 0.0.2, by running nixq ">> lib.mdDoc[remove] Argument[keep]" --batchmode nixos/**.nix nixq ">> mdDoc[remove] Argument[keep]" --batchmode nixos/**.nix nixq ">> Inherit >> mdDoc[remove]" --batchmode nixos/**.nix two mentions of the mdDoc function remain in nixos/, both of which are inside of comments. Since lib.mdDoc is already defined as just id, this commit is a no-op as far as Nix (and the built manual) is concerned.
56 lines
1.6 KiB
Nix
56 lines
1.6 KiB
Nix
{ config, lib, pkgs, ... }:
|
|
|
|
let
|
|
inherit (lib) optionalString mkOption types mkIf mkDefault;
|
|
|
|
cfg = config.environment.stub-ld;
|
|
|
|
message = ''
|
|
NixOS cannot run dynamically linked executables intended for generic
|
|
linux environments out of the box. For more information, see:
|
|
https://nix.dev/permalink/stub-ld
|
|
'';
|
|
|
|
stub-ld-for = pkgsArg: messageArg: pkgsArg.pkgsStatic.runCommandCC "stub-ld" {
|
|
nativeBuildInputs = [ pkgsArg.unixtools.xxd ];
|
|
inherit messageArg;
|
|
} ''
|
|
printf "%s" "$messageArg" | xxd -i -n message >main.c
|
|
cat <<EOF >>main.c
|
|
#include <stdio.h>
|
|
int main(int argc, char * argv[]) {
|
|
fprintf(stderr, "Could not start dynamically linked executable: %s\n", argv[0]);
|
|
fwrite(message, sizeof(unsigned char), message_len, stderr);
|
|
return 127; // matches behavior of bash and zsh without a loader. fish uses 139
|
|
}
|
|
EOF
|
|
$CC -Os main.c -o $out
|
|
'';
|
|
|
|
pkgs32 = pkgs.pkgsi686Linux;
|
|
|
|
stub-ld = stub-ld-for pkgs message;
|
|
stub-ld32 = stub-ld-for pkgs32 message;
|
|
in {
|
|
options = {
|
|
environment.stub-ld = {
|
|
enable = mkOption {
|
|
type = types.bool;
|
|
default = true;
|
|
example = false;
|
|
description = ''
|
|
Install a stub ELF loader to print an informative error message
|
|
in the event that a user attempts to run an ELF binary not
|
|
compiled for NixOS.
|
|
'';
|
|
};
|
|
};
|
|
};
|
|
|
|
config = mkIf cfg.enable {
|
|
environment.ldso = mkDefault stub-ld;
|
|
environment.ldso32 = mkIf pkgs.stdenv.isx86_64 (mkDefault stub-ld32);
|
|
};
|
|
|
|
meta.maintainers = with lib.maintainers; [ tejing ];
|
|
}
|