Skip to content

Commit

Permalink
github-runner: nixfmt-rfc-style
Browse files Browse the repository at this point in the history
  • Loading branch information
osnyx committed Oct 22, 2024
1 parent 6f4d16a commit a5decc1
Showing 1 changed file with 124 additions and 95 deletions.
219 changes: 124 additions & 95 deletions pkgs/development/tools/continuous-integration/github-runner/default.nix
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
{ autoSignDarwinBinariesHook
, buildDotnetModule
, dotnetCorePackages
, fetchFromGitHub
, fetchpatch
, git
, glibc
, glibcLocales
, lib
, nixosTests
, stdenv
, which
, buildPackages
, runtimeShell
{
autoSignDarwinBinariesHook,
buildDotnetModule,
dotnetCorePackages,
fetchFromGitHub,
fetchpatch,
git,
glibc,
glibcLocales,
lib,
nixosTests,
stdenv,
which,
buildPackages,
runtimeShell,
# List of Node.js runtimes the package should support
, nodeRuntimes ? [ "node20" ]
, nodejs_20
nodeRuntimes ? [ "node20" ],
nodejs_20,
}:

# Node.js runtimes supported by upstream
Expand Down Expand Up @@ -81,18 +82,22 @@ buildDotnetModule rec {
})
];

postPatch = ''
# Ignore changes to src/Runner.Sdk/BuildConstants.cs
substituteInPlace src/dir.proj \
--replace 'git update-index --assume-unchanged ./Runner.Sdk/BuildConstants.cs' \
'true'
'' + lib.optionalString (nodeRuntimes == [ "node20" ]) ''
postPatch =
''
# Ignore changes to src/Runner.Sdk/BuildConstants.cs
substituteInPlace src/dir.proj \
--replace 'git update-index --assume-unchanged ./Runner.Sdk/BuildConstants.cs' \
'true'
''
+ lib.optionalString (nodeRuntimes == [ "node20" ]) ''
substituteInPlace src/Runner.Common/Util/NodeUtil.cs \
--replace-fail '_defaultNodeVersion = "node16"' '_defaultNodeVersion = "node20"'
'';

DOTNET_SYSTEM_GLOBALIZATION_INVARIANT = isNull glibcLocales;
LOCALE_ARCHIVE = lib.optionalString (!DOTNET_SYSTEM_GLOBALIZATION_INVARIANT) "${glibcLocales}/lib/locale/locale-archive";
LOCALE_ARCHIVE = lib.optionalString (
!DOTNET_SYSTEM_GLOBALIZATION_INVARIANT
) "${glibcLocales}/lib/locale/locale-archive";

postConfigure = ''
# Generate src/Runner.Sdk/BuildConstants.cs
Expand All @@ -105,19 +110,23 @@ buildDotnetModule rec {
src/dir.proj
'';

nativeBuildInputs = [
which
git
] ++ lib.optionals (stdenv.isDarwin && stdenv.isAarch64) [
autoSignDarwinBinariesHook
];
nativeBuildInputs =
[
which
git
]
++ lib.optionals (stdenv.isDarwin && stdenv.isAarch64) [
autoSignDarwinBinariesHook
];

buildInputs = [ stdenv.cc.cc.lib ];

dotnet-sdk = dotnetCorePackages.sdk_6_0;
dotnet-runtime = dotnetCorePackages.runtime_6_0;

dotnetFlags = [ "-p:PackageRuntime=${dotnetCorePackages.systemToDotnetRid stdenv.hostPlatform.system}" ];
dotnetFlags = [
"-p:PackageRuntime=${dotnetCorePackages.systemToDotnetRid stdenv.hostPlatform.system}"
];

# As given here: https://github.com/actions/runner/blob/0befa62/src/dir.proj#L33-L41
projectFile = [
Expand Down Expand Up @@ -204,70 +213,79 @@ buildDotnetModule rec {

testProjectFile = [ "src/Test/Test.csproj" ];

preCheck = ''
mkdir -p _layout/externals
'' + lib.optionalString (lib.elem "node20" nodeRuntimes) ''
ln -s ${nodejs_20} _layout/externals/node20
'';
preCheck =
''
mkdir -p _layout/externals
''
+ lib.optionalString (lib.elem "node20" nodeRuntimes) ''
ln -s ${nodejs_20} _layout/externals/node20
'';

postInstall = ''
mkdir -p $out/bin
install -m755 src/Misc/layoutbin/runsvc.sh $out/lib/github-runner
install -m755 src/Misc/layoutbin/RunnerService.js $out/lib/github-runner
install -m755 src/Misc/layoutroot/run.sh $out/lib/github-runner
install -m755 src/Misc/layoutroot/run-helper.sh.template $out/lib/github-runner/run-helper.sh
install -m755 src/Misc/layoutroot/config.sh $out/lib/github-runner
install -m755 src/Misc/layoutroot/env.sh $out/lib/github-runner
# env.sh is patched to not require any wrapping
ln -sr "$out/lib/github-runner/env.sh" "$out/bin/"
substituteInPlace $out/lib/github-runner/config.sh \
--replace './bin/Runner.Listener' "$out/bin/Runner.Listener"
'' + lib.optionalString stdenv.isLinux ''
substituteInPlace $out/lib/github-runner/config.sh \
--replace 'command -v ldd' 'command -v ${glibc.bin}/bin/ldd' \
--replace 'ldd ./bin' '${glibc.bin}/bin/ldd ${dotnet-runtime}/shared/Microsoft.NETCore.App/${dotnet-runtime.version}/' \
--replace '/sbin/ldconfig' '${glibc.bin}/bin/ldconfig'
'' + ''
# Remove uneeded copy for run-helper template
substituteInPlace $out/lib/github-runner/run.sh --replace 'cp -f "$DIR"/run-helper.sh.template "$DIR"/run-helper.sh' ' '
substituteInPlace $out/lib/github-runner/run-helper.sh --replace '"$DIR"/bin/' '"$DIR"/'
# Make paths absolute
substituteInPlace $out/lib/github-runner/runsvc.sh \
--replace './externals' "$out/lib/externals" \
--replace './bin/RunnerService.js' "$out/lib/github-runner/RunnerService.js"
# The upstream package includes Node and expects it at the path
# externals/node$version. As opposed to the official releases, we don't
# link the Alpine Node flavors.
mkdir -p $out/lib/externals
'' + lib.optionalString (lib.elem "node20" nodeRuntimes) ''
ln -s ${nodejs_20} $out/lib/externals/node20
'' + ''
# Install Nodejs scripts called from workflows
install -D src/Misc/layoutbin/hashFiles/index.js $out/lib/github-runner/hashFiles/index.js
mkdir -p $out/lib/github-runner/checkScripts
install src/Misc/layoutbin/checkScripts/* $out/lib/github-runner/checkScripts/
'' + lib.optionalString stdenv.isLinux ''
# Wrap explicitly to, e.g., prevent extra entries for LD_LIBRARY_PATH
makeWrapperArgs=()
# We don't wrap with libicu
substituteInPlace $out/lib/github-runner/config.sh \
--replace '$LDCONFIG_COMMAND -NXv ''${libpath//:/ }' 'echo libicu'
'' + ''
# XXX: Using the corresponding Nix argument does not work as expected:
# https://github.com/NixOS/nixpkgs/issues/218449
# Common wrapper args for `executables`
makeWrapperArgs+=(
--run 'export RUNNER_ROOT="''${RUNNER_ROOT:-"$HOME/.github-runner"}"'
--run 'mkdir -p "$RUNNER_ROOT"'
--chdir "$out"
)
'';
postInstall =
''
mkdir -p $out/bin
install -m755 src/Misc/layoutbin/runsvc.sh $out/lib/github-runner
install -m755 src/Misc/layoutbin/RunnerService.js $out/lib/github-runner
install -m755 src/Misc/layoutroot/run.sh $out/lib/github-runner
install -m755 src/Misc/layoutroot/run-helper.sh.template $out/lib/github-runner/run-helper.sh
install -m755 src/Misc/layoutroot/config.sh $out/lib/github-runner
install -m755 src/Misc/layoutroot/env.sh $out/lib/github-runner
# env.sh is patched to not require any wrapping
ln -sr "$out/lib/github-runner/env.sh" "$out/bin/"
substituteInPlace $out/lib/github-runner/config.sh \
--replace './bin/Runner.Listener' "$out/bin/Runner.Listener"
''
+ lib.optionalString stdenv.isLinux ''
substituteInPlace $out/lib/github-runner/config.sh \
--replace 'command -v ldd' 'command -v ${glibc.bin}/bin/ldd' \
--replace 'ldd ./bin' '${glibc.bin}/bin/ldd ${dotnet-runtime}/shared/Microsoft.NETCore.App/${dotnet-runtime.version}/' \
--replace '/sbin/ldconfig' '${glibc.bin}/bin/ldconfig'
''
+ ''
# Remove uneeded copy for run-helper template
substituteInPlace $out/lib/github-runner/run.sh --replace 'cp -f "$DIR"/run-helper.sh.template "$DIR"/run-helper.sh' ' '
substituteInPlace $out/lib/github-runner/run-helper.sh --replace '"$DIR"/bin/' '"$DIR"/'
# Make paths absolute
substituteInPlace $out/lib/github-runner/runsvc.sh \
--replace './externals' "$out/lib/externals" \
--replace './bin/RunnerService.js' "$out/lib/github-runner/RunnerService.js"
# The upstream package includes Node and expects it at the path
# externals/node$version. As opposed to the official releases, we don't
# link the Alpine Node flavors.
mkdir -p $out/lib/externals
''
+ lib.optionalString (lib.elem "node20" nodeRuntimes) ''
ln -s ${nodejs_20} $out/lib/externals/node20
''
+ ''
# Install Nodejs scripts called from workflows
install -D src/Misc/layoutbin/hashFiles/index.js $out/lib/github-runner/hashFiles/index.js
mkdir -p $out/lib/github-runner/checkScripts
install src/Misc/layoutbin/checkScripts/* $out/lib/github-runner/checkScripts/
''
+ lib.optionalString stdenv.isLinux ''
# Wrap explicitly to, e.g., prevent extra entries for LD_LIBRARY_PATH
makeWrapperArgs=()
# We don't wrap with libicu
substituteInPlace $out/lib/github-runner/config.sh \
--replace '$LDCONFIG_COMMAND -NXv ''${libpath//:/ }' 'echo libicu'
''
+ ''
# XXX: Using the corresponding Nix argument does not work as expected:
# https://github.com/NixOS/nixpkgs/issues/218449
# Common wrapper args for `executables`
makeWrapperArgs+=(
--run 'export RUNNER_ROOT="''${RUNNER_ROOT:-"$HOME/.github-runner"}"'
--run 'mkdir -p "$RUNNER_ROOT"'
--chdir "$out"
)
'';

# List of files to wrap
executables = [
Expand Down Expand Up @@ -313,8 +331,19 @@ buildDotnetModule rec {
description = "Self-hosted runner for GitHub Actions";
homepage = "https://github.com/actions/runner";
license = licenses.mit;
maintainers = with maintainers; [ veehaitch newam kfollesdal aanderse zimbatm ];
platforms = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
maintainers = with maintainers; [
veehaitch
newam
kfollesdal
aanderse
zimbatm
];
platforms = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
sourceProvenance = with sourceTypes; [ binaryNativeCode ];
};
}

0 comments on commit a5decc1

Please sign in to comment.