Skip to content

Commit 93178f6

Browse files
authored
nixos/binfmt: Avoid adding to extra-sandbox-paths with fixBinary (#494593)
2 parents f1e8952 + d312012 commit 93178f6

2 files changed

Lines changed: 21 additions & 4 deletions

File tree

nixos/modules/system/boot/binfmt.nix

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,9 @@ in
262262
interpreter = mkDefault interpreterReg;
263263
fixBinary = mkDefault useStaticEmulator;
264264
wrapInterpreterInShell = mkDefault (!config.preserveArgvZero && !config.fixBinary);
265-
interpreterSandboxPath = mkDefault (dirOf (dirOf config.interpreter));
265+
interpreterSandboxPath = mkDefault (
266+
if config.fixBinary then null else dirOf (dirOf config.interpreter)
267+
);
266268
}
267269
// (magics.${system} or (throw "Cannot create binfmt registration for system ${system}"))
268270
);
@@ -276,10 +278,13 @@ in
276278
let
277279
ruleFor = system: cfg.registrations.${system};
278280
hasWrappedRule = lib.any (system: (ruleFor system).wrapInterpreterInShell) cfg.emulatedSystems;
281+
allFixBinary = lib.all (system: (ruleFor system).fixBinary) cfg.emulatedSystems;
279282
in
280-
[ "/run/binfmt" ]
283+
lib.optional (!allFixBinary) "/run/binfmt"
281284
++ lib.optional hasWrappedRule "${pkgs.bash}"
282-
++ (map (system: (ruleFor system).interpreterSandboxPath) cfg.emulatedSystems);
285+
++ lib.filter (x: x != null) (
286+
map (system: (ruleFor system).interpreterSandboxPath) cfg.emulatedSystems
287+
);
283288
};
284289

285290
environment.etc."binfmt.d/nixos.conf".source = builtins.toFile "binfmt_nixos.conf" (

nixos/tests/systemd-binfmt.nix

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,12 @@ in
103103
chroot = makeTest {
104104
name = "systemd-binfmt-chroot";
105105
nodes.machine =
106-
{ pkgs, lib, ... }:
106+
{
107+
pkgs,
108+
lib,
109+
config,
110+
...
111+
}:
107112
{
108113
boot.binfmt.emulatedSystems = [
109114
"aarch64-linux"
@@ -121,6 +126,13 @@ in
121126
echo 42 | chroot /tmp/chroot /yaml2json | grep 42
122127
'')
123128
];
129+
130+
assertions = [
131+
{
132+
assertion = config.nix.settings.extra-sandbox-paths == [ ];
133+
message = "Using binfmt_misc with static emulators, nix.settings.extra-sandbox-paths should be empty";
134+
}
135+
];
124136
};
125137
testScript = ''
126138
machine.start()

0 commit comments

Comments
 (0)