From 98dd7f5307544263991252f281e4869167bdbf55 Mon Sep 17 00:00:00 2001 From: Pyrox Date: Fri, 24 Feb 2023 20:59:26 -0500 Subject: [PATCH] nixos/gitea: Move to lib.getExe This makes it so that alternative packages, such as `pkgs.forgejo` are able to be used instead of the default `pkgs.gitea`. Also adds myself as a maintainer of the module. The varible `gitea`, which was used instead of `cfg.package`, has been replaced with the variable `exe`, and is instead the value of the main executable, as gotten from `lib.getExe`. `cfg.package` is used when this value is not appropriate. --- nixos/modules/services/misc/gitea.nix | 30 +++++++++++++-------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/nixos/modules/services/misc/gitea.nix b/nixos/modules/services/misc/gitea.nix index 14bf6aebb681..643ef05b7a21 100644 --- a/nixos/modules/services/misc/gitea.nix +++ b/nixos/modules/services/misc/gitea.nix @@ -5,7 +5,7 @@ with lib; let cfg = config.services.gitea; opt = options.services.gitea; - gitea = cfg.package; + exe = lib.getExe cfg.package; pg = config.services.postgresql; useMysql = cfg.database.type == "mysql"; usePostgresql = cfg.database.type == "postgres"; @@ -248,7 +248,7 @@ in staticRootPath = mkOption { type = types.either types.str types.path; - default = gitea.data; + default = cfg.package.data; defaultText = literalExpression "package.data"; example = "/var/lib/gitea/data"; description = lib.mdDoc "Upper level of template and static files path."; @@ -481,14 +481,14 @@ in # If we have a folder or symlink with gitea locales, remove it # And symlink the current gitea locales in place - "L+ '${cfg.stateDir}/conf/locale' - - - - ${gitea.out}/locale" + "L+ '${cfg.stateDir}/conf/locale' - - - - ${cfg.package.out}/locale" ]; systemd.services.gitea = { description = "gitea"; after = [ "network.target" ] ++ lib.optional usePostgresql "postgresql.service" ++ lib.optional useMysql "mysql.service"; wantedBy = [ "multi-user.target" ]; - path = [ gitea pkgs.git pkgs.gnupg ]; + path = [ cfg.package pkgs.git pkgs.gnupg ]; # In older versions the secret naming for JWT was kind of confusing. # The file jwt_secret hold the value for LFS_JWT_SECRET and JWT_SECRET @@ -512,7 +512,7 @@ in cp -f ${configFile} ${runConfig} if [ ! -s ${secretKey} ]; then - ${gitea}/bin/gitea generate secret SECRET_KEY > ${secretKey} + ${exe} generate secret SECRET_KEY > ${secretKey} fi # Migrate LFS_JWT_SECRET filename @@ -521,15 +521,15 @@ in fi if [ ! -s ${oauth2JwtSecret} ]; then - ${gitea}/bin/gitea generate secret JWT_SECRET > ${oauth2JwtSecret} + ${exe} generate secret JWT_SECRET > ${oauth2JwtSecret} fi if [ ! -s ${lfsJwtSecret} ]; then - ${gitea}/bin/gitea generate secret LFS_JWT_SECRET > ${lfsJwtSecret} + ${exe} generate secret LFS_JWT_SECRET > ${lfsJwtSecret} fi if [ ! -s ${internalToken} ]; then - ${gitea}/bin/gitea generate secret INTERNAL_TOKEN > ${internalToken} + ${exe} generate secret INTERNAL_TOKEN > ${internalToken} fi chmod u+w '${runConfig}' @@ -548,15 +548,15 @@ in ''} # run migrations/init the database - ${gitea}/bin/gitea migrate + ${exe} migrate # update all hooks' binary paths - ${gitea}/bin/gitea admin regenerate hooks + ${exe} admin regenerate hooks # update command option in authorized_keys if [ -r ${cfg.stateDir}/.ssh/authorized_keys ] then - ${gitea}/bin/gitea admin regenerate keys + ${exe} admin regenerate keys fi ''; @@ -565,7 +565,7 @@ in User = cfg.user; Group = "gitea"; WorkingDirectory = cfg.stateDir; - ExecStart = "${gitea}/bin/gitea web --pid /run/gitea/gitea.pid"; + ExecStart = "${exe} web --pid /run/gitea/gitea.pid"; Restart = "always"; # Runtime directory and mode RuntimeDirectory = "gitea"; @@ -635,7 +635,7 @@ in systemd.services.gitea-dump = mkIf cfg.dump.enable { description = "gitea dump"; after = [ "gitea.service" ]; - path = [ gitea ]; + path = [ cfg.package ]; environment = { USER = cfg.user; @@ -646,7 +646,7 @@ in serviceConfig = { Type = "oneshot"; User = cfg.user; - ExecStart = "${gitea}/bin/gitea dump --type ${cfg.dump.type}" + optionalString (cfg.dump.file != null) " --file ${cfg.dump.file}"; + ExecStart = "${exe} dump --type ${cfg.dump.type}" + optionalString (cfg.dump.file != null) " --file ${cfg.dump.file}"; WorkingDirectory = cfg.dump.backupDir; }; }; @@ -658,5 +658,5 @@ in timerConfig.OnCalendar = cfg.dump.interval; }; }; - meta.maintainers = with lib.maintainers; [ srhb ma27 ]; + meta.maintainers = with lib.maintainers; [ srhb ma27 thehedgeh0g ]; }