Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixos/gitea: don't configure the database if createDatabase == false #268849

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 45 additions & 20 deletions nixos/modules/services/misc/gitea.nix
Original file line number Diff line number Diff line change
Expand Up @@ -94,30 +94,37 @@ in

host = mkOption {
type = types.str;
default = "127.0.0.1";
defaultText = literalExpression ''
lib.mkIf config.services.gitea.database.createDatabase "127.0.0.1"
'';
description = "Database host address.";
};

port = mkOption {
type = types.port;
default = if usePostgresql then pg.settings.port else 3306;
defaultText = literalExpression ''
if config.${opt.database.type} != "postgresql"
then 3306
else 5432
lib.mkIf config.services.gitea.database.createDatabase (
if config.${opt.database.type} != "postgresql"
then 3306
else 5432
)
'';
description = "Database host port.";
};

name = mkOption {
type = types.str;
default = "gitea";
defaultText = literalExpression ''
lib.mkIf config.services.gitea.database.createDatabase "gitea"
'';
description = "Database name.";
};

user = mkOption {
type = types.str;
default = "gitea";
defaultText = literalExpression ''
lib.mkIf config.services.gitea.database.createDatabase "gitea"
'';
description = "Database user.";
};

Expand All @@ -143,23 +150,29 @@ in

socket = mkOption {
type = types.nullOr types.path;
default = if (cfg.database.createDatabase && usePostgresql) then "/run/postgresql" else if (cfg.database.createDatabase && useMysql) then "/run/mysqld/mysqld.sock" else null;
defaultText = literalExpression "null";
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";
defaultText = literalExpression ''"''${config.${opt.stateDir}}/data/gitea.db"'';
defaultText = literalExpression ''
lib.mkIf config.services.gitea.database.createDatabase (
"''${config.${opt.stateDir}}/data/gitea.db"
)
'';
description = "Path to the sqlite3 database file.";
};

createDatabase = mkOption {
type = types.bool;
default = true;
description = "Whether to create a local database automatically.";
description = ''
Whether to create a local database automatically.
If set `false`, then the other database settings required by the
configured database type *must* be specified explicitly.
'';
};
};

Expand Down Expand Up @@ -400,12 +413,31 @@ in
message = ''
When creating a database via NixOS, the db user and db name must be equal!
If you already have an existing DB+user and this assertion is new, you can safely set
`services.gitea.createDatabase` to `false` because removal of `ensureUsers`
`services.gitea.database.createDatabase` to `false` because removal of `ensureUsers`
and `ensureDatabases` doesn't have any effect.
'';
}
];

services.gitea.database = lib.mkMerge [
(lib.mkIf cfg.database.createDatabase {
host = lib.mkDefault "127.0.0.1";
port = lib.mkDefault (if usePostgresql then pg.settings.port else 3306);
name = lib.mkDefault "gitea";
user = lib.mkDefault "gitea";
socket = lib.mkDefault (if usePostgresql then "/run/postgresql" else if useMysql then "/run/mysqld/mysqld.sock" else null);
path = lib.mkDefault "${cfg.stateDir}/data/gitea.db";
})
{
# Create database passwordFile default when password is configured.
passwordFile =
mkDefault (toString (pkgs.writeTextFile {
name = "gitea-database-password";
text = cfg.database.password;
}));
}
];

services.gitea.settings = {
"cron.update_checker".ENABLED = lib.mkDefault false;

Expand Down Expand Up @@ -688,13 +720,6 @@ in
See https://nixos.org/manual/nixos/unstable/#module-forgejo for migration instructions.
'';

# Create database passwordFile default when password is configured.
services.gitea.database.passwordFile =
mkDefault (toString (pkgs.writeTextFile {
name = "gitea-database-password";
text = cfg.database.password;
}));

systemd.services.gitea-dump = mkIf cfg.dump.enable {
description = "gitea dump";
after = [ "gitea.service" ];
Expand Down
Loading