1 { autoSignDarwinBinariesHook
15 # List of Node.js runtimes the package should support
16 , nodeRuntimes ? [ "node20" ]
20 # Node.js runtimes supported by upstream
21 assert builtins.all (x: builtins.elem x [ "node20" ]) nodeRuntimes;
23 buildDotnetModule rec {
24 pname = "github-runner";
27 src = fetchFromGitHub {
31 hash = "sha256-kKfwLZYV4uEkHt82YWNtDehbspgnH8heckVU5aA/YiY=";
34 git -C $out rev-parse --short HEAD > $out/.git-revision
39 # The git commit is read during the build and some tests depend on a git repo to be present
40 # https://github.com/actions/runner/blob/22d1938ac420a4cb9e3255e47a91c2e43c38db29/src/dir.proj#L5
42 cp -r $src $TMPDIR/src
43 chmod -R +w $TMPDIR/src
46 export PATH=${buildPackages.git}/bin:$PATH
48 git config user.email "root@localhost"
49 git config user.name "root"
51 git commit -m "Initial commit"
52 git checkout -b v${version}
55 cat > $TMPDIR/bin/git <<EOF
57 if [ \$# -eq 1 ] && [ "\$1" = "rev-parse" ]; then
58 echo $(cat $TMPDIR/src/.git-revision)
61 exec ${buildPackages.git}/bin/git "\$@"
63 chmod +x $TMPDIR/bin/git
64 export PATH=$TMPDIR/bin:$PATH
68 # Replace some paths that originally point to Nix's read-only store
69 ./patches/host-context-dirs.patch
70 # Use GetDirectory() to obtain "diag" dir
71 ./patches/use-get-directory-for-diag.patch
72 # Don't try to install service
73 ./patches/dont-install-service.patch
74 # Access `.env` and `.path` relative to `$RUNNER_ROOT`, if set
75 ./patches/env-sh-use-runner-root.patch
76 # Fix FHS path: https://github.com/actions/runner/pull/2464
78 name = "ln-fhs.patch";
79 url = "https://github.com/actions/runner/commit/5ff0ce1.patch";
80 hash = "sha256-2Vg3cKZK3cE/OcPDZkdN2Ro2WgvduYTTwvNGxwCfXas=";
82 ] ++ lib.optionals (nodeRuntimes == [ "node20" ]) [
83 # If the package is built without Node 16, make Node 20 the default internal version
84 # https://github.com/actions/runner/pull/2844
86 name = "internal-node-20.patch";
87 url = "https://github.com/actions/runner/commit/acdc6ed.patch";
88 hash = "sha256-3/6yhhJPr9OMWBFc5/NU/DRtn76aTYvjsjQo2u9ZqnU=";
93 # Ignore changes to src/Runner.Sdk/BuildConstants.cs
94 substituteInPlace src/dir.proj \
95 --replace 'git update-index --assume-unchanged ./Runner.Sdk/BuildConstants.cs' \
99 DOTNET_SYSTEM_GLOBALIZATION_INVARIANT = isNull glibcLocales;
100 LOCALE_ARCHIVE = lib.optionalString (!DOTNET_SYSTEM_GLOBALIZATION_INVARIANT) "${glibcLocales}/lib/locale/locale-archive";
103 # Generate src/Runner.Sdk/BuildConstants.cs
105 -t:GenerateConstant \
106 -p:ContinuousIntegrationBuild=true \
107 -p:Deterministic=true \
108 -p:PackageRuntime="${dotnetCorePackages.systemToDotnetRid stdenv.hostPlatform.system}" \
109 -p:RunnerVersion="${version}" \
113 nativeBuildInputs = [
116 ] ++ lib.optionals (stdenv.isDarwin && stdenv.isAarch64) [
117 autoSignDarwinBinariesHook
120 buildInputs = [ stdenv.cc.cc.lib ];
122 dotnet-sdk = dotnetCorePackages.sdk_6_0;
123 dotnet-runtime = dotnetCorePackages.runtime_6_0;
125 dotnetFlags = [ "-p:PackageRuntime=${dotnetCorePackages.systemToDotnetRid stdenv.hostPlatform.system}" ];
127 # As given here: https://github.com/actions/runner/blob/0befa62/src/dir.proj#L33-L41
130 "src/Runner.Common/Runner.Common.csproj"
131 "src/Runner.Listener/Runner.Listener.csproj"
132 "src/Runner.Worker/Runner.Worker.csproj"
133 "src/Runner.PluginHost/Runner.PluginHost.csproj"
134 "src/Runner.Sdk/Runner.Sdk.csproj"
135 "src/Runner.Plugins/Runner.Plugins.csproj"
137 nugetDeps = ./deps.nix;
141 __darwinAllowLocalNetworking = true;
143 # Fully qualified name of disabled tests
146 "GitHub.Runner.Common.Tests.Listener.SelfUpdaterL0.TestSelfUpdateAsync"
147 "GitHub.Runner.Common.Tests.ProcessInvokerL0.OomScoreAdjIsInherited"
149 ++ map (x: "GitHub.Runner.Common.Tests.Listener.SelfUpdaterL0.TestSelfUpdateAsync_${x}") [
150 "Cancel_CloneHashTask_WhenNotNeeded"
151 "CloneHash_RuntimeAndExternals"
153 "FallbackToFullPackage"
154 "NoUpdateOnOldVersion"
155 "NotUseExternalsRuntimeTrimmedPackageOnHashMismatch"
156 "UseExternalsRuntimeTrimmedPackage"
157 "UseExternalsTrimmedPackage"
160 ++ map (x: "GitHub.Runner.Common.Tests.Listener.SelfUpdaterV2L0.${x}") [
161 "TestSelfUpdateAsync_DownloadRetry"
162 "TestSelfUpdateAsync_ValidateHash"
163 "TestSelfUpdateAsync"
165 ++ map (x: "GitHub.Runner.Common.Tests.Worker.ActionManagerL0.PrepareActions_${x}") [
166 "CompositeActionWithActionfile_CompositeContainerNested"
167 "CompositeActionWithActionfile_CompositePrestepNested"
168 "CompositeActionWithActionfile_MaxLimit"
169 "CompositeActionWithActionfile_Node"
170 "DownloadActionFromGraph"
171 "NotPullOrBuildImagesMultipleTimes"
172 "RepositoryActionWithActionYamlFile_DockerHubImage"
173 "RepositoryActionWithActionfileAndDockerfile"
174 "RepositoryActionWithActionfile_DockerHubImage"
175 "RepositoryActionWithActionfile_Dockerfile"
176 "RepositoryActionWithActionfile_DockerfileRelativePath"
177 "RepositoryActionWithActionfile_Node"
178 "RepositoryActionWithDockerfile"
179 "RepositoryActionWithDockerfileInRelativePath"
180 "RepositoryActionWithDockerfilePrepareActions_Repository"
181 "RepositoryActionWithInvalidWrapperActionfile_Node"
182 "RepositoryActionWithWrapperActionfile_PreSteps"
184 ++ map (x: "GitHub.Runner.Common.Tests.DotnetsdkDownloadScriptL0.${x}") [
185 "EnsureDotnetsdkBashDownloadScriptUpToDate"
186 "EnsureDotnetsdkPowershellDownloadScriptUpToDate"
188 ++ [ "GitHub.Runner.Common.Tests.Listener.RunnerL0.TestRunOnceHandleUpdateMessage" ]
189 # Tests for trimmed runner packages which aim at reducing the update size. Not relevant for Nix.
190 ++ map (x: "GitHub.Runner.Common.Tests.PackagesTrimL0.${x}") [
191 "RunnerLayoutParts_CheckExternalsHash"
192 "RunnerLayoutParts_CheckDotnetRuntimeHash"
194 ++ lib.optionals (stdenv.hostPlatform.system == "aarch64-linux") [
195 # "JavaScript Actions in Alpine containers are only supported on x64 Linux runners. Detected Linux Arm64"
196 "GitHub.Runner.Common.Tests.Worker.StepHostL0.DetermineNodeRuntimeVersionInAlpineContainerAsync"
197 "GitHub.Runner.Common.Tests.Worker.StepHostL0.DetermineNode20RuntimeVersionInAlpineContainerAsync"
199 ++ lib.optionals DOTNET_SYSTEM_GLOBALIZATION_INVARIANT [
200 "GitHub.Runner.Common.Tests.ProcessExtensionL0.SuccessReadProcessEnv"
201 "GitHub.Runner.Common.Tests.Util.StringUtilL0.FormatUsesInvariantCulture"
202 "GitHub.Runner.Common.Tests.Worker.VariablesL0.Constructor_SetsOrdinalIgnoreCaseComparer"
203 "GitHub.Runner.Common.Tests.Worker.WorkerL0.DispatchCancellation"
204 "GitHub.Runner.Common.Tests.Worker.WorkerL0.DispatchRunNewJob"
206 ++ lib.optionals (!lib.elem "node16" nodeRuntimes) [
207 "GitHub.Runner.Common.Tests.ProcessExtensionL0.SuccessReadProcessEnv"
210 testProjectFile = [ "src/Test/Test.csproj" ];
213 mkdir -p _layout/externals
214 '' + lib.optionalString (lib.elem "node20" nodeRuntimes) ''
215 ln -s ${nodejs_20} _layout/externals/node20
221 install -m755 src/Misc/layoutbin/runsvc.sh $out/lib/github-runner
222 install -m755 src/Misc/layoutbin/RunnerService.js $out/lib/github-runner
223 install -m755 src/Misc/layoutroot/run.sh $out/lib/github-runner
224 install -m755 src/Misc/layoutroot/run-helper.sh.template $out/lib/github-runner/run-helper.sh
225 install -m755 src/Misc/layoutroot/config.sh $out/lib/github-runner
226 install -m755 src/Misc/layoutroot/env.sh $out/lib/github-runner
228 # env.sh is patched to not require any wrapping
229 ln -sr "$out/lib/github-runner/env.sh" "$out/bin/"
231 substituteInPlace $out/lib/github-runner/config.sh \
232 --replace './bin/Runner.Listener' "$out/bin/Runner.Listener"
233 '' + lib.optionalString stdenv.isLinux ''
234 substituteInPlace $out/lib/github-runner/config.sh \
235 --replace 'command -v ldd' 'command -v ${glibc.bin}/bin/ldd' \
236 --replace 'ldd ./bin' '${glibc.bin}/bin/ldd ${dotnet-runtime}/shared/Microsoft.NETCore.App/${dotnet-runtime.version}/' \
237 --replace '/sbin/ldconfig' '${glibc.bin}/bin/ldconfig'
239 # Remove uneeded copy for run-helper template
240 substituteInPlace $out/lib/github-runner/run.sh --replace 'cp -f "$DIR"/run-helper.sh.template "$DIR"/run-helper.sh' ' '
241 substituteInPlace $out/lib/github-runner/run-helper.sh --replace '"$DIR"/bin/' '"$DIR"/'
243 # Make paths absolute
244 substituteInPlace $out/lib/github-runner/runsvc.sh \
245 --replace './externals' "$out/lib/externals" \
246 --replace './bin/RunnerService.js' "$out/lib/github-runner/RunnerService.js"
248 # The upstream package includes Node and expects it at the path
249 # externals/node$version. As opposed to the official releases, we don't
250 # link the Alpine Node flavors.
251 mkdir -p $out/lib/externals
252 '' + lib.optionalString (lib.elem "node20" nodeRuntimes) ''
253 ln -s ${nodejs_20} $out/lib/externals/node20
255 # Install Nodejs scripts called from workflows
256 install -D src/Misc/layoutbin/hashFiles/index.js $out/lib/github-runner/hashFiles/index.js
257 mkdir -p $out/lib/github-runner/checkScripts
258 install src/Misc/layoutbin/checkScripts/* $out/lib/github-runner/checkScripts/
259 '' + lib.optionalString stdenv.isLinux ''
260 # Wrap explicitly to, e.g., prevent extra entries for LD_LIBRARY_PATH
263 # We don't wrap with libicu
264 substituteInPlace $out/lib/github-runner/config.sh \
265 --replace '$LDCONFIG_COMMAND -NXv ''${libpath//:/ }' 'echo libicu'
267 # XXX: Using the corresponding Nix argument does not work as expected:
268 # https://github.com/NixOS/nixpkgs/issues/218449
269 # Common wrapper args for `executables`
271 --run 'export RUNNER_ROOT="''${RUNNER_ROOT:-"$HOME/.github-runner"}"'
272 --run 'mkdir -p "$RUNNER_ROOT"'
277 # List of files to wrap
287 doInstallCheck = true;
288 installCheckPhase = ''
289 runHook preInstallCheck
291 export RUNNER_ROOT="$TMPDIR"
293 $out/bin/config.sh --help >/dev/null
294 $out/bin/Runner.Listener --help >/dev/null
296 version=$($out/bin/Runner.Listener --version)
297 if [[ "$version" != "${version}" ]]; then
298 printf 'Unexpected version %s' "$version"
302 commit=$($out/bin/Runner.Listener --commit)
303 if [[ "$commit" != "$(git rev-parse HEAD)" ]]; then
304 printf 'Unexpected commit %s' "$commit"
308 runHook postInstallCheck
312 tests.smoke-test = nixosTests.github-runner;
313 updateScript = ./update.sh;
317 changelog = "https://github.com/actions/runner/releases/tag/v${version}";
318 description = "Self-hosted runner for GitHub Actions";
319 homepage = "https://github.com/actions/runner";
320 license = licenses.mit;
321 maintainers = with maintainers; [ veehaitch newam kfollesdal aanderse zimbatm ];
322 platforms = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
323 sourceProvenance = with sourceTypes; [ binaryNativeCode ];