generated from cachix/cachix-deploy-hetzner-dedicated
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Trick all programs into thinking we're on x86.
- Loading branch information
Showing
2 changed files
with
67 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters