Skip to content

Commit

Permalink
runner: wrap rosetta runner in arch
Browse files Browse the repository at this point in the history
Trick all programs into thinking we're on x86.
  • Loading branch information
sandydoo committed Feb 20, 2025
1 parent 7a8f8e9 commit ada9542
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
62 changes: 62 additions & 0 deletions lib/wrap-x86-program.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
lib,
stdenv,
writeScript,
}:

let
wrapPackage =
pkg:
let
wrapBinary =
name:
writeScript "wrapped-${name}" ''
#!/bin/sh
exec arch -x86_64 ${pkg}/bin/${name} "$@"
'';

binFiles = builtins.attrNames (builtins.readDir "${pkg}/bin");

# Create an attribute set of all wrapped binaries
wrappedBinaries = lib.genAttrs binFiles wrapBinary;

wrapped = stdenv.mkDerivation {
pname = "${pkg.pname}-x86_64-wrapped";
version = pkg.version;

buildInputs = [ pkg ];

buildCommand = ''
mkdir -p $out
# Copy other files and directories from the original package
cp -r ${pkg}/* $out/
# Clear the original bin directory
rm -rf $out/bin
mkdir -p $out/bin
# Create symlinks for all wrapped binaries
${lib.concatStringsSep "\n" (
lib.mapAttrsToList (name: path: ''
ln -s ${path} $out/bin/${name}
'') wrappedBinaries
)}
'';

# Preserve meta attributes from the original package
meta = pkg.meta // {
description = "x86_64 wrapped version of ${pkg.meta.description or pkg.name}";
};
};

in
wrapped
// {
# Preserve the original package's override function
override = f: wrapPackage (pkg.override f);

# Expose the original package
passthru.unwrapped = pkg;
};
in
wrapPackage
6 changes: 5 additions & 1 deletion modules/github-runner.nix
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,11 @@ in
];
}
(lib.mkIf cfg.rosetta.enable {
package = pkgs.pkgsx86_64Darwin.github-runner;
package =
let
wrapX86Program = pkgs.callPackage ../lib/wrap-x86-program.nix { };
in
wrapX86Program pkgs.pkgsx86_64Darwin.github-runner;
})
(lib.mkIf pkgs.stdenv.isLinux { user = runnerName; })
cfg.extraService
Expand Down

0 comments on commit ada9542

Please sign in to comment.