git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #40565 from etu/gitea-improvements

nixos/gitea: Enable configuring of derivation and a systemd timer for creation of backups

commit5830b0381f0015e2cab1838d0c6121857f4ee749 authorSamuel Leathers <disasm@gmail.com> dateMon 21 May 2018, 07:16 (9 years ago) parentd9bdd77ce42182
1 file changed+64−5
nixos/modules/services/misc/gitea.nix+64−5
nixos/modules/services/misc/gitea.nix+64−5
@@ -4,6 +4,7 @@ with lib;
44
55let
66 cfg = config.services.gitea;
7+ gitea = cfg.package;
78 pg = config.services.postgresql;
89 usePostgresql = cfg.database.type == "postgres";
910 configFile = pkgs.writeText "app.ini" ''
@@ -57,6 +58,13 @@ in
5758 description = "Enable Gitea Service.";
5859 };
5960
61+ package = mkOption {
62+ default = pkgs.gitea;
63+ type = types.package;
64+ defaultText = "pkgs.gitea";
65+ description = "gitea derivation to use";
66+ };
67+
6068 useWizard = mkOption {
6169 default = false;
6270 type = types.bool;
@@ -156,6 +164,30 @@ in
156164 };
157165 };
158166
167+ dump = {
168+ enable = mkOption {
169+ type = types.bool;
170+ default = false;
171+ description = ''
172+ Enable a timer that runs gitea dump to generate backup-files of the
173+ current gitea database and repositories.
174+ '';
175+ };
176+
177+ interval = mkOption {
178+ type = types.str;
179+ default = "04:31";
180+ example = "hourly";
181+ description = ''
182+ Run a gitea dump at this interval. Runs by default at 04:31 every day.
183+
184+ The format is described in
185+ <citerefentry><refentrytitle>systemd.time</refentrytitle>
186+ <manvolnum>7</manvolnum></citerefentry>.
187+ '';
188+ };
189+ };
190+
159191 appName = mkOption {
160192 type = types.str;
161193 default = "gitea: Gitea Service";
@@ -203,7 +235,7 @@ in
203235
204236 staticRootPath = mkOption {
205237 type = types.str;
206− default = "${pkgs.gitea.data}";
238+ default = "${gitea.data}";
207239 example = "/var/lib/gitea/data";
208240 description = "Upper level of template and static files path.";
209241 };
@@ -223,7 +255,7 @@ in
223255 description = "gitea";
224256 after = [ "network.target" "postgresql.service" ];
225257 wantedBy = [ "multi-user.target" ];
226− path = [ pkgs.gitea.bin ];
258+ path = [ gitea.bin ];
227259
228260 preStart = let
229261 runConfig = "${cfg.stateDir}/custom/conf/app.ini";
@@ -253,7 +285,7 @@ in
253285 HOOKS=$(find ${cfg.repositoryRoot} -mindepth 4 -maxdepth 4 -type f -wholename "*git/hooks/*")
254286 if [ "$HOOKS" ]
255287 then
256− sed -ri 's,/nix/store/[a-z0-9.-]+/bin/gitea,${pkgs.gitea.bin}/bin/gitea,g' $HOOKS
288+ sed -ri 's,/nix/store/[a-z0-9.-]+/bin/gitea,${gitea.bin}/bin/gitea,g' $HOOKS
257289 sed -ri 's,/nix/store/[a-z0-9.-]+/bin/env,${pkgs.coreutils}/bin/env,g' $HOOKS
258290 sed -ri 's,/nix/store/[a-z0-9.-]+/bin/bash,${pkgs.bash}/bin/bash,g' $HOOKS
259291 sed -ri 's,/nix/store/[a-z0-9.-]+/bin/perl,${pkgs.perl}/bin/perl,g' $HOOKS
@@ -261,7 +293,7 @@ in
261293 if [ ! -d ${cfg.stateDir}/conf/locale ]
262294 then
263295 mkdir -p ${cfg.stateDir}/conf
264− cp -r ${pkgs.gitea.out}/locale ${cfg.stateDir}/conf/locale
296+ cp -r ${gitea.out}/locale ${cfg.stateDir}/conf/locale
265297 fi
266298 '' + optionalString (usePostgresql && cfg.database.createDatabase) ''
267299 if ! test -e "${cfg.stateDir}/db-created"; then
@@ -288,7 +320,7 @@ in
288320 User = cfg.user;
289321 WorkingDirectory = cfg.stateDir;
290322 PermissionsStartOnly = true;
291− ExecStart = "${pkgs.gitea.bin}/bin/gitea web";
323+ ExecStart = "${gitea.bin}/bin/gitea web";
292324 Restart = "always";
293325 };
294326
@@ -318,5 +350,32 @@ in
318350 name = "gitea-database-password";
319351 text = cfg.database.password;
320352 })));
353+
354+ systemd.services.gitea-dump = {
355+ description = "gitea dump";
356+ after = [ "gitea.service" ];
357+ wantedBy = [ "default.target" ];
358+ path = [ gitea.bin ];
359+
360+ environment = {
361+ USER = cfg.user;
362+ HOME = cfg.stateDir;
363+ GITEA_WORK_DIR = cfg.stateDir;
364+ };
365+
366+ serviceConfig = {
367+ Type = "oneshot";
368+ User = cfg.user;
369+ ExecStart = "${gitea.bin}/bin/gitea dump";
370+ WorkingDirectory = cfg.stateDir;
371+ };
372+ };
373+
374+ systemd.timers.gitea-dump = {
375+ description = "Update timer for gitea-dump";
376+ partOf = [ "gitea-dump.service" ];
377+ wantedBy = [ "timers.target" ];
378+ timerConfig.OnCalendar = cfg.dump.interval;
379+ };
321380 };
322381}