Forgejo: Difference between revisions

m Added the comment for the tokenFile for forgejo-runner code block
Stoat (talk | contribs)
m Made code snippet more readable, modular, and informative.
Line 108: Line 108:
<syntaxhighlight lang="nixos">
<syntaxhighlight lang="nixos">
sops.secrets.forgejo-admin-password.owner = "forgejo";
sops.secrets.forgejo-admin-password.owner = "forgejo";
systemd.services.forgejo.preStart = ''
systemd.services.forgejo.preStart = let
   admin="${lib.getExe config.services.forgejo.package} admin user"
   adminCmd = "${lib.getExe cfg.package} admin user";
   $admin create --admin --email "root@localhost" --username admin --password "$(tr -d '\n' < $
  pwd = config.sops.secrets.forgejo-admin-password;
{config.sops.secrets.forgejo-admin-password.path})" || true
  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
   ## uncomment this line to change an admin user which was already created
   # $admin change-password --username admin --password "$(tr -d '\n' < ${config.sops.secrets.f
   # ${adminCmd} change-password --username ${user} --password "$(tr -d '\n' < ${pwd.path})" || true
orgejo-admin-password.path})" || true
'';  
'';
 
</syntaxhighlight>
</syntaxhighlight>
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.  
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.