nixos/forgejo-runner: init#529621
Conversation
798a282 to
aa5bcf6
Compare
Full git range-diff
$ git range-diff master c8cccbad788c1bd01828361526abfe120c2a6807 aa5bcf6a109d70f6e56364a2f36a4f4a8e0ad3311: 03bc79224f81 ! 1: 8f77e07e3b61 nixos/forgejo-runner: init
@@ Metadata
## Commit message ##
nixos/forgejo-runner: init
- ## ci/OWNERS ##
-@@ ci/OWNERS: pkgs/development/python-modules/buildcatrust/ @ajs124 @lukegb @mweinelt
- /pkgs/applications/networking/cluster/terraform-providers @zowoq
-
- # Forgejo
--nixos/modules/services/misc/forgejo.* @adamcstephens @bendlas @christoph-heiss @emilylange @nycodeghg @pyrox0 @tebriel
--pkgs/by-name/fo/forgejo/ @adamcstephens @bendlas @christoph-heiss @emilylange @nycodeghg @pyrox0 @tebriel
--nixos/tests/forgejo.nix @adamcstephens @bendlas @christoph-heiss @emilylange @nycodeghg @pyrox0 @tebriel
-+nixos/modules/services/misc/forgejo.* @adamcstephens @bendlas @christoph-heiss @emilylange @nycodeghg @pyrox0 @tebriel
-+pkgs/by-name/fo/forgejo/ @adamcstephens @bendlas @christoph-heiss @emilylange @nycodeghg @pyrox0 @tebriel
-+nixos/tests/forgejo.nix @adamcstephens @bendlas @christoph-heiss @emilylange @nycodeghg @pyrox0 @tebriel
-+nixos/modules/services/continuous-integration/forgejo-runner.nix @adamcstephens @bendlas @christoph-heiss @emilylange @nycodeghg @pyrox0 @tebriel
-+pkgs/by-name/fo/forgejo-runner/ @adamcstephens @bendlas @christoph-heiss @emilylange @nycodeghg @pyrox0 @tebriel
-
- # Dotnet
- /pkgs/build-support/dotnet @corngood
-
## nixos/doc/manual/release-notes/rl-2611.section.md ##
@@
- - [tranquil](https://tangled.org/tranquil.farm/tranquil-pds) is an ATProto PDS (personal data server) implementation in Rust. A featureful, spec conscious and community driven alternative to the Bluesky reference implementation PDS. Available as [services.tranquil-pds](#opt-services.tranquil-pds.enable).
+ - [scx_loader](https://github.com/sched-ext/scx-loader), a system daemon and DBus-based loader for sched_ext schedulers. `scxctl` is the command-line client for interacting with the loader, allowing users to switch schedulers, modes, and arguments dynamically. Available as [services.scx-loader](#opt-services.scx-loader.enable)
+- [Forgejo Runner](https://forgejo.org/docs/latest/admin/actions/), a daemon for Forgejo Actions. Available as [services.forgejo-runner](#opt-services.forgejo-runner.instances).
+
@@ nixos/modules/services/continuous-integration/forgejo-runner.nix (new)
+ }:
+
+ {
-+ imports = [
-+ ../../misc/assertions.nix
-+
-+ # compat for users coming from nixos/gitea-actions-runner
-+ (mkRemovedOptionModule [ "name" ] ''
-+ The option `${options.name}' has been removed, because it has no longer
-+ any effect, as runners no longer self-report their name to Forgejo.
-+ '')
-+ (mkRenamedOptionModule [ "url" ] [ "settings" "server" "connections" "default" "url" ])
-+ (mkRenamedOptionModule [ "token" ] [ "settings" "server" "connections" "default" "token" ])
-+ (mkRemovedOptionModule [ "tokenFile" ] ''
-+ The option `${options.tokenFile}' has been renamed to
-+ `${options.secrets}.server.connections.default.token_url'
-+ and expects a different file structure.
-+ Before updating your config, remove the leading `TOKEN=' in your file.
-+ '')
-+ (mkRenamedOptionModule [ "labels" ] [ "settings" "runner" "labels" ])
++ imports =
++ let
++ tokenInstructionsCommon = ''
++ but additional attention is required.
+
-+ ];
++ Assuming you are migrating from `services.gitea-actions-runner', you will need to:
++
++ 1. Find the old `.runner' file of your previously registered runner. You will need
++ to extract two values from it. Given the instance name of "${name}", it should
++ be able to find it at `/var/lib/gitea-runner/${name}/.runner'.
++
++ 2. Read the contents of it, for example using `cat /var/lib/gitea-runner/native/.runner'.
++
++ 3. Take note of the "uuid" and set the option `${options.settings}.server.connections.default.uuid'
++ to that value. For example "c9e50be9-a7c3-4aee-ba35-624c4ff8c519".
++ '';
++ in
++ [
++ ../../misc/assertions.nix
++
++ # compat for users coming from nixos/gitea-actions-runner
++ (mkRenamedOptionModule [ "url" ] [ "settings" "server" "connections" "default" "url" ])
++ (mkRenamedOptionModule [ "labels" ] [ "settings" "runner" "labels" ])
++ (mkRemovedOptionModule [ "name" ] ''
++ The option `${options.name}' has been removed, because it has no longer
++ any effect, as runners no longer self-report their name to Forgejo.
++ '')
++ (mkRemovedOptionModule [ "token" ] ''
++ The option `${options.token}' has been renamed to
++ `${options.settings}.server.connections.default.token'
++ ${tokenInstructionsCommon}
++ 4. Take note of the "token" and set the option `${options.settings}.server.connections.default.token'
++ to that value. For example "6634bb58be0db23cc013a2e72dd1828ae0257cf".
++
++ 5. Rename `${options.token}' to `${options.settings}.server.connections.default.token'.
++ '')
++ (mkRemovedOptionModule [ "tokenFile" ] ''
++ The option `${options.tokenFile}' has been renamed to
++ `${options.secrets}.server.connections.default.token_url'
++ ${tokenInstructionsCommon}
++ 4. Take note of the "token" and replace the contents of your existing token file with it.
++ You no longer need to prefix the token with `TOKEN='. Put just the token in that file
++ and nothing else.
++
++ 5. Rename `${options.tokenFile}' to `${options.secrets}.server.connections.default.token_url'.
++ '')
++ ];
+
+ config = {
+ assertions = [
@@ nixos/modules/services/continuous-integration/forgejo-runner.nix (new)
+ that is *not* null.
+
+ Hint:
-+ `cfg.secrets.server.connections.${name}.token_url' will set
-+ `cfg.settings.server.connections.${name}.token_url' for you.
++ `${options.secrets}.server.connections.${name}.token_url' will set
++ `${options.settings}.settings.server.connections.${name}.token_url' for you.
+ '';
+ }
+ ];
2: 8fd5a8189ba6 = 2: aa5bcf6a109d nixos/tests/forgejo: test `nixos/forgejo-runner`
3: c8cccbad788c < -: ------------ nixos/gitea-actions-runner: nudge users with `forgejo-runner` to `nixos/forgejo-runner`$ git range-diff upstream/master aa5bcf6a109d70f6e56364a2f36a4f4a8e0ad331 d5cb8bca8f114efdbce5dac1badad8f455e0bddb |
aa5bcf6 to
d5cb8bc
Compare
| labels = | ||
| instance: | ||
| instance.settings.runner.labels | ||
| ++ (lib.flatten ( | ||
| lib.mapAttrsToList (_: value: value.labels or [ ]) instance.settings.server.connections | ||
| )); |
There was a problem hiding this comment.
I think collecting labels from conections could be simplified. TOOD: think about how, don't make any mistakes.
There was a problem hiding this comment.
I am sorry Dave hexa, I am afraid I can't do that.
I looked at a bunch of lib functions again but came back empty-handed. I mean sure, I could rewrite this as a lib.foldr, but I don't think that would make this easier to follow.
Adam came up with the following. Perhaps you prefer his version?
https://github.com/NixOS/nixpkgs/pull/496325/changes#diff-e6cd9d8453d0e3b230ed171ddae369068e84fc862d636e14fd46cc349eb0e11aR37-R42
|
just migrated to this PR, works as expected. configuration is nice that it follows the pattern like |
d5cb8bc to
b39d26c
Compare
b39d26c to
ebbed83
Compare
|
I decided to also drop the nested
|
This comment was marked as low quality.
This comment was marked as low quality.
| environment = { | ||
| HOME = "/var/lib/forgejo-runner/${name}"; | ||
| } | ||
| // optionalAttrs (instance.isDockerRunner && hasPodman) { |
There was a problem hiding this comment.
If a machine has both docker and podman enabled, this currently defaults to podman.
What if the user wants the runner to use docker instead?
Do we call this an unsupported configuration or do we want to provide an option to change the container runtime?
There was a problem hiding this comment.
I've had similar awkwardness with this heuristic in gitea-runner, being able to explicitly set the runtime would be appreciated.
There was a problem hiding this comment.
Hm.. this is inherited from nixos/gitea-actions-runner which I worked on together with hexa 3 years ago.
Until now, I falsely assumed virtualisation.docker.enable conflicts with virtualisation.podman.enable. But no, it's virtualisation.docker.enable and virtualisation.podman.dockerSocket.enable (or virtualisation.podman.dockerCompat) which makes a lot more sense, honestly.
nixpkgs/nixos/modules/virtualisation/podman/default.nix
Lines 331 to 342 in e711415
https://code.forgejo.org/forgejo/runner/src/tag/v12.11.1/internal/pkg/config/config.example.yaml#L203-L209 did not exist back then.
Meaning there is little reason to keep setting systemd.services.<name>.environment.DOCKER_HOST = "unix:///run/podman/podman.sock".
How about we set cfg.settings.container.docker_host = lib.mkDefault "unix:///run/podman/podman.sock" if Podman is enabled? We can emit a warning if both Docker and Podman are enabled and the user did not explicitly specify cfg.settings.container.docker_host.
There was a problem hiding this comment.
I'm trying to remember why I really needed to opt out of the gitea-actions-runner logic for these, but it was not for this exact reason. But something else equally as reasonable, I swear 😅 I wished at the time that there was an escape hatch provided to just set the flag that is then used further in the module. I think it might come up again. The default heuristic is good subject to your new findings, just need to be able to set these manually if needed by user tbh
There was a problem hiding this comment.
I don't understand. The escape hatch would be you simply set cfg.settings.container.docker_host to a (different) value. Your value will take priority over lib.mkDefault.
Are you using a remote socket like ssh:// tls://?
I mean sure, we could make cfg.isDockerRunner public, downgrade the assertion to a warning, or introduce some sort of cfg.runtimes that allows you to pick host, docker and/or podman.
There was a problem hiding this comment.
I wish I could remember exactly. The things contributing to the issue were the infix booleans potentially in combination with the docker/podman issue identified here. It was annoying, I was experimenting with the runner in kubernetes and trying nix-snapshotter and similar approaches, beats me its been a while but i had to patch or fork the gitea-actions-runner module to get past it. If it's possible without much trouble to let users set these flags manually, it can only help I think.
There was a problem hiding this comment.
I agree with the idea that setting cfg.settings.container.docker_host would take precedence over everything else. This allows people to control what they want to use.
As another suggestion, what about containerRuntime as an option?
containerRuntime = mkOption {
type = types.nullOr (types.enum [ "docker" "podman" ]);
default = null;
};The user would be able to select docker or podman explicitly, and the module do whatever is needed for each runtime: assertions, groups, setting cfg.settings.container.docker_host if one of the options is chosen.
docker_hostis set: takes precedence over everything elsecontainerRuntime != null: assertions, groups, setsdocker_host...
|
@emilylange were you able to progress on this PR? I've been running your module and everything is running just fine on |
@ratsclub Thanks for testing! I haven't decided what to make of #529621 (comment) yet and the nixpkgs Forgejo team situation is still a bit fuzzy. There is also https://code.forgejo.org/forgejo/runner/pulls/1571 which added yet another way to specify runner labels. We probably want to extend the module to support that too. |
ratsclub
left a comment
There was a problem hiding this comment.
@emilylange just two comments with suggestions.
|
|
||
| Hint: | ||
| `${options.secrets}.server.connections.${name}.token_url' will set | ||
| `${options.settings}.settings.server.connections.${name}.token_url' for you. |
There was a problem hiding this comment.
I believe this will duplicate the path when generating the documentation.
| `${options.settings}.settings.server.connections.${name}.token_url' for you. | |
| `${options.settings}.server.connections.${name}.token_url' for you. |
| ]; | ||
|
|
||
| config = { | ||
| assertions = [ |
There was a problem hiding this comment.
Do you think it makes sense to have an assertion checking if there is at least one connection? This would stop a useless service from spawning, maybe only check when the service is enabled.
| pathType = types.pathWith { | ||
| inStore = false; | ||
| absolute = true; | ||
| }; |
There was a problem hiding this comment.
saw today that this is the same as lib.types.externalPath
Alternative to #496325.
Highly opinionated, but open to rework large parts of it.
I'll approach upstream to suggest
uuid_urlsimilar totoken_url. That would allow us to drop the hack in the VM test and is arguably more compatible with the NixOS deployment primitives overall.We could also consider making
cfg.instances.<name>.configFiletogether withcfg.instances.<name>.isDockerpublic, but I am personally not entirely sold on that yet.The runner mode ephemeral is not supported.
forgejo-runnerwill refuse to start if an ephemeral UUID and Token pair is specified. We can add support for that in the future.And finally, I would like to truly drop support for running
nixos/gitea-actions-runnerwithpkgs.forgejo-runnerin26.11or maybe the release after that (27.05?) and remove thegitMinimalwrapper innixpkgs/pkgs/by-name/fo/forgejo-runner/package.nix
Lines 91 to 92 in 5ace65c
Things done
passthru.tests.nixpkgs-reviewon this PR. See nixpkgs-review usage../result/bin/.