3
0
Fork 0
forked from mirrors/nixpkgs

Merge pull request #49814 from aanderse/gitea

nixos/gitea: fix mysql issue, add mysql socket auth, and add a nixos test
This commit is contained in:
Renaud 2018-11-08 23:45:46 +01:00 committed by GitHub
commit 6399b103d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 85 additions and 2 deletions

View file

@ -6,6 +6,7 @@ let
cfg = config.services.gitea; cfg = config.services.gitea;
gitea = cfg.package; gitea = cfg.package;
pg = config.services.postgresql; pg = config.services.postgresql;
useMysql = cfg.database.type == "mysql";
usePostgresql = cfg.database.type == "postgres"; usePostgresql = cfg.database.type == "postgres";
configFile = pkgs.writeText "app.ini" '' configFile = pkgs.writeText "app.ini" ''
APP_NAME = ${cfg.appName} APP_NAME = ${cfg.appName}
@ -14,7 +15,7 @@ let
[database] [database]
DB_TYPE = ${cfg.database.type} 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} NAME = ${cfg.database.name}
USER = ${cfg.database.user} USER = ${cfg.database.user}
PASSWD = #dbpass# PASSWD = #dbpass#
@ -148,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 { path = mkOption {
type = types.str; type = types.str;
default = "${cfg.stateDir}/data/gitea.db"; default = "${cfg.stateDir}/data/gitea.db";
@ -253,7 +261,7 @@ in
systemd.services.gitea = { systemd.services.gitea = {
description = "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" ]; wantedBy = [ "multi-user.target" ];
path = [ gitea.bin ]; path = [ gitea.bin ];

View file

@ -304,6 +304,7 @@ in rec {
tests.fsck = callTest tests/fsck.nix {}; tests.fsck = callTest tests/fsck.nix {};
tests.fwupd = callTest tests/fwupd.nix {}; tests.fwupd = callTest tests/fwupd.nix {};
tests.gdk-pixbuf = callTest tests/gdk-pixbuf.nix {}; tests.gdk-pixbuf = callTest tests/gdk-pixbuf.nix {};
tests.gitea = callSubTests tests/gitea.nix {};
tests.gitlab = callTest tests/gitlab.nix {}; tests.gitlab = callTest tests/gitlab.nix {};
tests.gitolite = callTest tests/gitolite.nix {}; tests.gitolite = callTest tests/gitolite.nix {};
tests.gjs = callTest tests/gjs.nix {}; tests.gjs = callTest tests/gjs.nix {};

74
nixos/tests/gitea.nix Normal file
View file

@ -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/");
'';
};
}