kamov
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.
3 Likes
kamov
3
Thank you, this is exactly what I was looking for ![:blush: :blush:](https://discourse.nixos.org/images/emoji/twitter/blush.png?v=12)
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