@@ -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 ;
0 commit comments