From 5e8c65b70efdf3004e2a23c681523163ca1bf58e Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Mon, 13 Feb 2023 09:49:45 +0800 Subject: [PATCH] hosts/plover: automate the admin creation on Gitea --- hosts/plover/modules/services/gitea.nix | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/hosts/plover/modules/services/gitea.nix b/hosts/plover/modules/services/gitea.nix index 2b7d0107..597e7167 100644 --- a/hosts/plover/modules/services/gitea.nix +++ b/hosts/plover/modules/services/gitea.nix @@ -130,11 +130,25 @@ in # Gitea service module will have to set up certain things first which is # why we have to go first. - preStart = lib.mkBefore '' - # Setting up the appropriate schema for PostgreSQL secure schema usage. - psql -tAc "SELECT 1 FROM information_schema.schemata WHERE schema_name='${giteaDatabaseUser}';" \ - grep -q 1 || psql -tAc "CREATE SCHEMA IF NOT EXISTS AUTHORIZATION ${giteaDatabaseUser};" - ''; + preStart = let + giteaBin = "${lib.getBin config.services.gitea.package}/bin/gitea"; + giteaAdminUsername = lib.escapeShellArg "foodogsquared"; + in + lib.mkMerge [ + (lib.mkBefore '' + # Setting up the appropriate schema for PostgreSQL secure schema usage. + psql -tAc "SELECT 1 FROM information_schema.schemata WHERE schema_name='${giteaDatabaseUser}';" \ + grep -q 1 || psql -tAc "CREATE SCHEMA IF NOT EXISTS AUTHORIZATION ${giteaDatabaseUser};" + '') + + (lib.mkAfter '' + # Setting up the administrator account automated. + ${giteaBin} admin user list --admin | grep -q ${giteaAdminUsername} \ + || ${giteaBin} admin user create \ + --username ${giteaAdminUsername} --email foodogsquared@${config.networking.domain} \ + --random-password --random-password-length 76 --admin + '') + ]; }; # Attaching it altogether with the reverse proxy of choice.