Skip to content

Commit 3001014

Browse files
Merge remote-tracking branch 'origin/main'
2 parents 8407f02 + cd94646 commit 3001014

2 files changed

Lines changed: 31 additions & 55 deletions

File tree

module.nix

Lines changed: 29 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ flake: {
1010
cfg = config.services.tarmoqchi;
1111

1212
# Flake shipped default binary
13-
fpkg = flake.packages.${pkgs.stdenv.hostPlatform.system}.default;
13+
fpkg = flake.packages.${pkgs.stdenv.hostPlatform.system}.server;
1414

1515
# Toml management
1616
toml = pkgs.formats.toml {};
@@ -22,16 +22,17 @@ flake: {
2222

2323
# The digesting configuration of server
2424
toml-config = toml.generate "config.toml" {
25-
port = cfg.port;
26-
url = cfg.address;
27-
database_url = "#databaseUrl#";
28-
github_client_id = "#ghcid#";
29-
github_client_secret = "#ghcsecret#";
30-
github_redirect_url = "https://tarmoqchi.uz/github/callback";
25+
app.port = toString cfg.port;
26+
spring.datasource.url = "#databaseUrl#";
27+
github = {
28+
client-id = "#ghcid#";
29+
client-secret = "#ghcsecret#";
30+
redirect-uri = "https://${cfg.proxy-reverse.domain}/github/callback";
31+
};
3132
};
3233

3334
# Caddy proxy reversing
34-
caddy = mkIf (cfg.enable && cfg.proxy-reverse.enable && cfg.proxy == "caddy") {
35+
caddy = mkIf (cfg.enable && cfg.proxy-reverse.enable && cfg.proxy-reverse.proxy == "caddy") {
3536
services.caddy.virtualHosts = lib.debug.traceIf (builtins.isNull cfg.proxy-reverse.domain) "domain can't be null, please specicy it properly!" {
3637
"${cfg.proxy-reverse.domain}" = {
3738
extraConfig = ''
@@ -42,11 +43,14 @@ flake: {
4243
};
4344

4445
# Nginx proxy reversing
45-
nginx = mkIf (cfg.enable && cfg.proxy-reverse.enable && cfg.proxy == "nginx") {
46+
nginx = mkIf (cfg.enable && cfg.proxy-reverse.enable && cfg.proxy-reverse.proxy == "nginx") {
4647
services.nginx.virtualHosts = lib.debug.traceIf (builtins.isNull cfg.proxy-reverse.domain) "domain can't be null, please specicy it properly!" {
4748
"${cfg.proxy-reverse.domain}" = {
4849
addSSL = true;
4950
enableACME = true;
51+
serverAliases = [
52+
"*.${cfg.proxy-reverse.domain}"
53+
];
5054
locations."/" = {
5155
proxyPass = "http://127.0.0.1:${toString cfg.port}";
5256
proxyWebsockets = true;
@@ -124,17 +128,19 @@ flake: {
124128
# Write configuration file for server
125129
cp -f ${toml-config} ${cfg.dataDir}/config.toml
126130
127-
${lib.optionalString cfg.database.socketAuth ''
128-
echo "DATABASE_URL=postgres://${cfg.database.user}@/${cfg.database.name}?host=${cfg.database.socket}" > "${cfg.dataDir}/.env"
129-
sed -i "s|#databaseUrl#|postgres://${cfg.database.user}@/${cfg.database.name}?host=${cfg.database.socket}|g" "${cfg.dataDir}/config.toml"
130-
''}
131-
132-
${lib.optionalString (!cfg.database.socketAuth) ''
133-
echo "DATABASE_URL=postgres://${cfg.database.user}:#password#@${cfg.database.host}/${cfg.database.name}" > "${cfg.dataDir}/.env"
134-
replace-secret '#password#' '${cfg.database.passwordFile}' '${cfg.dataDir}/.env'
135-
source "${cfg.dataDir}/.env"
136-
sed -i "s|#databaseUrl#|$DATABASE_URL|g" "${cfg.dataDir}/config.toml"
137-
''}
131+
echo "DATABASE_URL=jdbc:postgres://${cfg.database.user}:#password#@${cfg.database.host}/${cfg.database.name}" > "${cfg.dataDir}/.env"
132+
echo "GITHUB_ID=#ghcid#" >> "${cfg.dataDir}/.env"
133+
echo "GITHUB_SECRET=#ghcsecret#" >> "${cfg.dataDir}/.env"
134+
135+
replace-secret '#password#' '${cfg.database.passwordFile}' '${cfg.dataDir}/.env'
136+
replace-secret '#ghcid#' '${cfg.github.id}' '${cfg.dataDir}/.env'
137+
replace-secret '#ghcsecret#' '${cfg.github.secret}' '${cfg.dataDir}/.env'
138+
139+
source "${cfg.dataDir}/.env"
140+
141+
sed -i "s|#databaseUrl#|$DATABASE_URL|g" "${cfg.dataDir}/config.toml"
142+
sed -i "s|#ghcid#|$GITHUB_ID|g" "${cfg.dataDir}/config.toml"
143+
sed -i "s|#ghcsecret#|$GITHUB_SECRET|g" "${cfg.dataDir}/config.toml"
138144
'';
139145
};
140146
};
@@ -144,7 +150,7 @@ flake: {
144150
description = "tarmoqchi HTTP & TCP tunneling";
145151
documentation = ["https://tarmoqchi.uz"];
146152

147-
after = ["network.target" "tarmoqchi-config.service" "tarmoqchi-migration.service"] ++ lib.optional local-database "postgresql.service";
153+
after = ["network.target" "tarmoqchi-config.service"] ++ lib.optional local-database "postgresql.service";
148154
requires = lib.optional local-database "postgresql.service";
149155
wants = ["network-online.target"];
150156
wantedBy = ["multi-user.target"];
@@ -154,7 +160,7 @@ flake: {
154160
User = cfg.user;
155161
Group = cfg.group;
156162
Restart = "always";
157-
ExecStart = "${lib.getBin cfg.package}/bin/server server run ${cfg.dataDir}/config.toml";
163+
ExecStart = "${lib.getBin cfg.package}/bin/tarmoqchi --config=${cfg.dataDir}/config.toml";
158164
ExecReload = "${pkgs.coreutils}/bin/kill -s HUP $MAINPID";
159165
StateDirectory = cfg.user;
160166
StateDirectoryMode = "0750";
@@ -214,13 +220,7 @@ flake: {
214220

215221
## Tests (nixos-rebuilds fails if any test fails)
216222
assertions =
217-
[
218-
{
219-
assertion = (!cfg.database.socketAuth) -> cfg.database.passwordFile != null;
220-
message = "services.tarmoqchi.database.passwordFile must be set when using remote database!";
221-
}
222-
]
223-
++ lib.optional
223+
lib.optional
224224
(cfg.proxy-reverse.enable)
225225
{
226226
assertion = cfg.proxy-reverse.domain != null && cfg.proxy-reverse.domain != "";
@@ -235,12 +235,6 @@ in {
235235
Tarmoqchi, HTTP & TCP tunneling.
236236
'';
237237

238-
address = mkOption {
239-
type = types.str;
240-
default = "127.0.0.1";
241-
description = "Port to use for passing over proxy";
242-
};
243-
244238
port = mkOption {
245239
type = types.int;
246240
default = 39393;
@@ -305,24 +299,6 @@ in {
305299
description = "Database host address. Leave \"127.0.0.1\" if you want local database";
306300
};
307301

308-
socketAuth = mkOption {
309-
type = types.bool;
310-
default =
311-
if local-database
312-
then true
313-
else false;
314-
description = "Use Unix socket authentication for PostgreSQL instead of password authentication when local database wanted.";
315-
};
316-
317-
socket = mkOption {
318-
type = types.nullOr types.path;
319-
default =
320-
if local-database
321-
then "/run/postgresql"
322-
else null;
323-
description = "Path to the PostgreSQL Unix socket.";
324-
};
325-
326302
port = mkOption {
327303
type = types.port;
328304
default = config.services.postgresql.settings.port;

server/default.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ in
99
inherit version;
1010

1111
src = ./.;
12-
mvnHash = "sha256-QUNGJSpunL4XVGZOmCVjQUPlF3FJwfvwMWTBuq08nso=";
12+
mvnHash = "sha256-+hGWYg46ai+IuSxM8MwT4j+BEqOjd6HM3gbgtlkx0Bw=";
1313

1414
nativeBuildInputs = with pkgs; [
1515
makeWrapper
@@ -22,7 +22,7 @@ in
2222
install -Dm644 ./target/server-${version}.jar $out/share/tarmoqchi
2323
2424
makeWrapper ${pkgs.jre}/bin/java $out/bin/tarmoqchi \
25-
--add-flags "-jar $out/share/tarmoqchi/tarmoqchi.jar"
25+
--add-flags "-jar $out/share/tarmoqchi/server-${version}.jar"
2626
2727
runHook postInstall
2828
'';

0 commit comments

Comments
 (0)