kamov
May 13, 2024, 7:21pm
1
Hey, I’ve installed forgejo on my NixOS server, but I’m not sure how to access the command line interface for managing the forgejo instance:
The command line program is not present:
# sudo -H -u forgejo bash -c "forgejo --help"
bash: line 1: forgejo: command not found
Adding forgejo to environment.systemPackages didn’t seem to help.
Hm, maybe the forgejo module should add a script to make accessing the CLI easier:
{ config, pkgs, ...}: {
environment.systemPackages = let
cfg = config.services.forgejo;
forgejo-cli = pkgs.writeScriptBin "forgejo-cli" ''
#!${pkgs.runtimeShell}
cd ${cfg.stateDir}
sudo=exec
if [[ "$USER" != forgejo ]]; then
sudo='exec /run/wrappers/bin/sudo -u ${cfg.user} -g ${cfg.group} --preserve-env=GITEA_WORK_DIR --preserve-env=GITEA_CUSTOM'
fi
# Note that these variable names will change
export GITEA_WORK_DIR=${cfg.stateDir}
export GITEA_CUSTOM=${cfg.customDir}
$sudo ${lib.getExe cfg.package} "$@"
''; in [
forgejo-cli
];
}
Then just run forgejo-cli as any user with wheel permissions and you’re correctly running the forgejo binary as the forgejo user/group.
That said, I’ve personally not actually needed to run the CLI manually in a good number of years of using gitea/forgejo.
kamov
May 14, 2024, 7:05am
3
Thank you, this is exactly what I was looking for
It’s true that the cli doesn’t need to be used often, but it’s nice to be able to use it in case of some issues, just another tool in the toolbox
sokai
January 11, 2026, 3:35pm
4
JFYI, cause I stumbled over this today, there is a semicolon missing in the code …
{
[…]
'' in [
forgejo-cli
];
}
should become
{
[…]
''; in [
forgejo-cli
];
}
Thanks for the code, _which saved my life_!
TLATER
January 11, 2026, 3:54pm
5
Hah, good spot, and sorry; the majority of snippets I share are written from memory while standing in public transport, so sometimes syntax errors slip through.