Forgejo: Difference between revisions
Add way to create/ensure users without wizard/webpage |
m Made code snippet more readable, modular, and informative. |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 89: | Line 89: | ||
url = "https://git.example.com"; | url = "https://git.example.com"; | ||
# Obtaining the path to the runner token file may differ | # Obtaining the path to the runner token file may differ | ||
# tokenFile should be in format TOKEN=<secret>, since it's EnvironmentFile for systemd | |||
tokenFile = config.age.secrets.forgejo-runner-token.path; | tokenFile = config.age.secrets.forgejo-runner-token.path; | ||
labels = [ | labels = [ | ||
Line 106: | Line 107: | ||
Using the following snippet, you can ensure users: | Using the following snippet, you can ensure users: | ||
<syntaxhighlight lang="nixos"> | <syntaxhighlight lang="nixos"> | ||
systemd.services.forgejo.preStart = | sops.secrets.forgejo-admin-password.owner = "forgejo"; | ||
systemd.services.forgejo.preStart = let | |||
$create --admin --email " | adminCmd = "${lib.getExe cfg.package} admin user"; | ||
''; | pwd = config.sops.secrets.forgejo-admin-password; | ||
user = "joe"; # Note, Forgejo doesn't allow creation of an account named "admin" | |||
in '' | |||
${adminCmd} create --admin --email "root@localhost" --username ${user} --password "$(tr -d '\n' < ${pwd.path})" || true | |||
## uncomment this line to change an admin user which was already created | |||
# ${adminCmd} change-password --username ${user} --password "$(tr -d '\n' < ${pwd.path})" || true | |||
''; | |||
</syntaxhighlight> | </syntaxhighlight> | ||
You may remove the <code>--admin</code> flag to create only a regular user. The <code> | You may remove the <code>--admin</code> flag to create only a regular user. The <code>|| true</code> is necessary, so the snippet does not fail if the user already exists. | ||
Naturally, instead of sops, you may use any file or secret manager, as explained above. | Naturally, instead of sops, you may use any file or secret manager, as explained above. |