lowdown: add flag to disable the Darwin sandbox

This is a program written in a memory‐unsafe language that processes
potentially‐untrusted user input. We shouldn’t disable upstream’s
sandboxing mechanisms for all downstream consumers without good
reason.

Although the sandbox API is officially marked as deprecated, it is
used as the basis for the supported App Sandbox and it is extremely
unlikely to ever be removed as it is used extensively throughout
the OS for service hardening and by third parties like the Chrome
sandbox. Nix itself uses it to sandbox builds, and its lack of support
for nesting is why this caused problems in the first place. Instead,
introduce a `lowdown-unsandboxed` package that can be used in the
`nativeBuildInputs` of Nix builds, while keeping the sandboxed
version of the program for general use. The name might not be ideal,
as it remains identical to `lowdown` on non‐Darwin platforms,
but I couldn’t think of a better one.

See: #125004
Closes: #346933
This commit is contained in:
Emily 2024-10-06 21:02:23 +01:00
parent c4902d6504
commit dc32d18e52
2 changed files with 12 additions and 3 deletions

View File

@ -2,12 +2,13 @@
, fetchpatch
, enableShared ? !stdenv.hostPlatform.isStatic
, enableStatic ? stdenv.hostPlatform.isStatic
, enableDarwinSandbox ? true
# for passthru.tests
, nix
}:
stdenv.mkDerivation rec {
pname = "lowdown";
pname = "lowdown${lib.optionalString (stdenv.hostPlatform.isDarwin && !enableDarwinSandbox) "-unsandboxed"}";
version = "1.1.0";
outputs = [ "out" "lib" "dev" "man" ];
@ -54,7 +55,9 @@ stdenv.mkDerivation rec {
nativeBuildInputs = [ which dieHook ]
++ lib.optionals stdenv.hostPlatform.isDarwin [ fixDarwinDylibNames ];
preConfigure = lib.optionalString (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) ''
# The Darwin sandbox calls fail inside Nix builds, presumably due to
# being nested inside another sandbox.
preConfigure = lib.optionalString (stdenv.hostPlatform.isDarwin && !enableDarwinSandbox) ''
echo 'HAVE_SANDBOX_INIT=0' > configure.local
'';
@ -103,7 +106,8 @@ stdenv.mkDerivation rec {
'';
doInstallCheck = true;
installCheckPhase = ''
installCheckPhase = lib.optionalString (!stdenv.hostPlatform.isDarwin || !enableDarwinSandbox) ''
runHook preInstallCheck
echo '# TEST' > test.md
$out/bin/lowdown test.md

View File

@ -5434,6 +5434,11 @@ with pkgs;
lowdown = callPackage ../tools/typesetting/lowdown { };
# Less secure variant of lowdown for use inside Nix builds.
lowdown-unsandboxed = lowdown.override {
enableDarwinSandbox = false;
};
numatop = callPackage ../os-specific/linux/numatop { };
numworks-udev-rules = callPackage ../os-specific/linux/numworks-udev-rules { };