nixos/binfmt: replace activationScript via tmpfiles

nikstur 88f63d11 cb08d3dd

Changed files
+27 -24
nixos
modules
system
boot
+27 -24
nixos/modules/system/boot/binfmt.nix
···
optionalString fixBinary "F";
in ":${name}:${type}:${offset'}:${magicOrExtension}:${mask'}:${interpreter}:${flags}";
-
activationSnippet = name: { interpreter, wrapInterpreterInShell, ... }: if wrapInterpreterInShell then ''
-
rm -f /run/binfmt/${name}
-
cat > /run/binfmt/${name} << 'EOF'
-
#!${pkgs.bash}/bin/sh
-
exec -- ${interpreter} "$@"
-
EOF
-
chmod +x /run/binfmt/${name}
-
'' else ''
-
rm -f /run/binfmt/${name}
-
ln -s ${interpreter} /run/binfmt/${name}
-
'';
+
mkInterpreter = name: { interpreter, wrapInterpreterInShell, ... }:
+
if wrapInterpreterInShell
+
then pkgs.writeShellScript "${name}-interpreter" ''
+
#!${pkgs.bash}/bin/sh
+
exec -- ${interpreter} "$@"
+
''
+
else interpreter;
getEmulator = system: (lib.systems.elaborate { inherit system; }).emulator pkgs;
getQemuArch = system: (lib.systems.elaborate { inherit system; }).qemuArch;
···
environment.etc."binfmt.d/nixos.conf".source = builtins.toFile "binfmt_nixos.conf"
(lib.concatStringsSep "\n" (lib.mapAttrsToList makeBinfmtLine config.boot.binfmt.registrations));
-
system.activationScripts.binfmt = stringAfter [ "specialfs" ] ''
-
mkdir -p /run/binfmt
-
chmod 0755 /run/binfmt
-
${lib.concatStringsSep "\n" (lib.mapAttrsToList activationSnippet config.boot.binfmt.registrations)}
-
'';
-
systemd = lib.mkIf (config.boot.binfmt.registrations != {}) {
-
additionalUpstreamSystemUnits = [
-
"proc-sys-fs-binfmt_misc.automount"
-
"proc-sys-fs-binfmt_misc.mount"
-
"systemd-binfmt.service"
-
];
-
services.systemd-binfmt.restartTriggers = [ (builtins.toJSON config.boot.binfmt.registrations) ];
-
};
+
+
systemd = lib.mkMerge [
+
({ tmpfiles.rules = [
+
"d /run/binfmt 0755 -"
+
] ++ lib.mapAttrsToList
+
(name: interpreter:
+
"L+ /run/binfmt/${name} - - - - ${interpreter}"
+
)
+
(lib.mapAttrs mkInterpreter config.boot.binfmt.registrations);
+
})
+
+
(lib.mkIf (config.boot.binfmt.registrations != {}) {
+
additionalUpstreamSystemUnits = [
+
"proc-sys-fs-binfmt_misc.automount"
+
"proc-sys-fs-binfmt_misc.mount"
+
"systemd-binfmt.service"
+
];
+
services.systemd-binfmt.restartTriggers = [ (builtins.toJSON config.boot.binfmt.registrations) ];
+
})
+
];
};
}