From 0bbb6f4f2a42c361b2e01a741a2ffdd0ce61e363 Mon Sep 17 00:00:00 2001 From: Aaron Andersen Date: Mon, 5 Nov 2018 20:57:24 -0500 Subject: [PATCH 1/3] nixos/gitea: fix systemd after target when mysql is the database of choice --- nixos/modules/services/misc/gitea.nix | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/nixos/modules/services/misc/gitea.nix b/nixos/modules/services/misc/gitea.nix index a222325579fe..16a4a806202e 100644 --- a/nixos/modules/services/misc/gitea.nix +++ b/nixos/modules/services/misc/gitea.nix @@ -6,6 +6,7 @@ let cfg = config.services.gitea; gitea = cfg.package; pg = config.services.postgresql; + useMysql = cfg.database.type == "mysql"; usePostgresql = cfg.database.type == "postgres"; configFile = pkgs.writeText "app.ini" '' APP_NAME = ${cfg.appName} @@ -253,7 +254,7 @@ in systemd.services.gitea = { description = "gitea"; - after = [ "network.target" "postgresql.service" ]; + after = [ "network.target" ] ++ lib.optional usePostgresql "postgresql.service" ++ lib.optional useMysql "mysql.service"; wantedBy = [ "multi-user.target" ]; path = [ gitea.bin ]; From 3ed52c78047bcc4b74d34e0cee179bb708aebdc0 Mon Sep 17 00:00:00 2001 From: Aaron Andersen Date: Mon, 5 Nov 2018 21:05:42 -0500 Subject: [PATCH 2/3] nixos/gitea: add mysql socket authentication as an option --- nixos/modules/services/misc/gitea.nix | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/nixos/modules/services/misc/gitea.nix b/nixos/modules/services/misc/gitea.nix index 16a4a806202e..7a10bd872994 100644 --- a/nixos/modules/services/misc/gitea.nix +++ b/nixos/modules/services/misc/gitea.nix @@ -15,7 +15,7 @@ let [database] DB_TYPE = ${cfg.database.type} - HOST = ${cfg.database.host}:${toString cfg.database.port} + HOST = ${if cfg.database.socket != null then cfg.database.socket else cfg.database.host + ":" + toString cfg.database.port} NAME = ${cfg.database.name} USER = ${cfg.database.user} PASSWD = #dbpass# @@ -149,6 +149,13 @@ in ''; }; + socket = mkOption { + type = types.nullOr types.path; + default = null; + example = "/run/mysqld/mysqld.sock"; + description = "Path to the unix socket file to use for authentication."; + }; + path = mkOption { type = types.str; default = "${cfg.stateDir}/data/gitea.db"; From 0dde47a58acdd3cff855796bbd899c90c7fb25b5 Mon Sep 17 00:00:00 2001 From: Aaron Andersen Date: Mon, 5 Nov 2018 21:06:30 -0500 Subject: [PATCH 3/3] nixos/gitea: add a nixos test to ensure the initial database migration succeeds so the application can start --- nixos/release.nix | 1 + nixos/tests/gitea.nix | 74 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 nixos/tests/gitea.nix diff --git a/nixos/release.nix b/nixos/release.nix index 4647f28be186..a3d33887db27 100644 --- a/nixos/release.nix +++ b/nixos/release.nix @@ -301,6 +301,7 @@ in rec { tests.fsck = callTest tests/fsck.nix {}; tests.fwupd = callTest tests/fwupd.nix {}; tests.gdk-pixbuf = callTest tests/gdk-pixbuf.nix {}; + tests.gitea = callSubTests tests/gitea.nix {}; tests.gitlab = callTest tests/gitlab.nix {}; tests.gitolite = callTest tests/gitolite.nix {}; tests.gjs = callTest tests/gjs.nix {}; diff --git a/nixos/tests/gitea.nix b/nixos/tests/gitea.nix new file mode 100644 index 000000000000..7ffe05ef3f1f --- /dev/null +++ b/nixos/tests/gitea.nix @@ -0,0 +1,74 @@ +{ system ? builtins.currentSystem }: + +with import ../lib/testing.nix { inherit system; }; +with pkgs.lib; + +{ + mysql = makeTest { + name = "gitea-mysql"; + meta.maintainers = [ maintainers.aanderse ]; + + machine = + { config, pkgs, ... }: + { services.mysql.enable = true; + services.mysql.package = pkgs.mariadb; + services.mysql.ensureDatabases = [ "gitea" ]; + services.mysql.ensureUsers = [ + { name = "gitea"; + ensurePermissions = { "gitea.*" = "ALL PRIVILEGES"; }; + } + ]; + + services.gitea.enable = true; + services.gitea.database.type = "mysql"; + services.gitea.database.socket = "/run/mysqld/mysqld.sock"; + }; + + testScript = '' + startAll; + + $machine->waitForUnit('gitea.service'); + $machine->waitForOpenPort('3000'); + $machine->succeed("curl --fail http://localhost:3000/"); + ''; + }; + + postgres = makeTest { + name = "gitea-postgres"; + meta.maintainers = [ maintainers.aanderse ]; + + machine = + { config, pkgs, ... }: + { + services.gitea.enable = true; + services.gitea.database.type = "postgres"; + services.gitea.database.password = "secret"; + }; + + testScript = '' + startAll; + + $machine->waitForUnit('gitea.service'); + $machine->waitForOpenPort('3000'); + $machine->succeed("curl --fail http://localhost:3000/"); + ''; + }; + + sqlite = makeTest { + name = "gitea-sqlite"; + meta.maintainers = [ maintainers.aanderse ]; + + machine = + { config, pkgs, ... }: + { services.gitea.enable = true; + }; + + testScript = '' + startAll; + + $machine->waitForUnit('gitea.service'); + $machine->waitForOpenPort('3000'); + $machine->succeed("curl --fail http://localhost:3000/"); + ''; + }; +}