hosts/plover: automate the admin creation on Gitea

This commit is contained in:
Gabriel Arazas 2023-02-13 09:49:45 +08:00
parent fc7ec80933
commit 5e8c65b70e
No known key found for this signature in database
GPG Key ID: ADE0C41DAB221FCC

View File

@ -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.