From ff96343ed093a9b005506e6d6fafdae802f60894 Mon Sep 17 00:00:00 2001 From: tobinio Date: Mon, 31 Aug 2026 14:24:59 +0200 Subject: [PATCH] modrinth-statistics nix based --- flake.lock | 50 ++++++++++++++++--- flake.nix | 1 + hosts/homeserver/secrets.yaml | 7 ++- .../services/modrinth-statistics.compose.yml | 12 ----- .../services/modrinth-statistics.nix | 50 ++++++++++++++++--- 5 files changed, 90 insertions(+), 30 deletions(-) delete mode 100644 hosts/homeserver/services/modrinth-statistics.compose.yml diff --git a/flake.lock b/flake.lock index 5a92fdf..0aabebc 100644 --- a/flake.lock +++ b/flake.lock @@ -36,6 +36,25 @@ "url": "https://tangled.org/tobinio.dev/light-control" } }, + "modrinth-statistics": { + "inputs": { + "nixpkgs": "nixpkgs_3" + }, + "locked": { + "lastModified": 1788178587, + "narHash": "sha256-dAWoCuvi0CMFdDOnGZoJ4qYAMUHQ2MydCvHEA6UKz9M=", + "ref": "refs/tags/v4.0.1", + "rev": "2b0388a1cb3fde23c80736bd3ef086dfb53e5eac", + "revCount": 265, + "type": "git", + "url": "https://tangled.org/tobinio.dev/modrinth-statistics" + }, + "original": { + "ref": "refs/tags/v4.0.1", + "type": "git", + "url": "https://tangled.org/tobinio.dev/modrinth-statistics" + } + }, "nixpkgs": { "locked": { "lastModified": 1785858998, @@ -101,6 +120,22 @@ } }, "nixpkgs_3": { + "locked": { + "lastModified": 1788039129, + "narHash": "sha256-pa4Q0qErvCvzCaaUph7Sm37RhR4xvPrYI8Lgz6k85+A=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "d2f67949798825fe853f7c5d0492b8bf016d3f88", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_4": { "locked": { "lastModified": 1787498568, "narHash": "sha256-9i/VTdusq/+NM/tz+J1Re+ojkMB8MBf0QshnYfzHz30=", @@ -116,7 +151,7 @@ "type": "github" } }, - "nixpkgs_4": { + "nixpkgs_5": { "locked": { "lastModified": 1787135253, "narHash": "sha256-RD2kNWCG+Bjo6h+JVjWVNntZs2GtRoeY2xHjts/FNkA=", @@ -136,6 +171,7 @@ "inputs": { "hydration-notifier": "hydration-notifier", "lightcontrol": "lightcontrol", + "modrinth-statistics": "modrinth-statistics", "nixpkgs-stable": "nixpkgs-stable", "nixpkgs-unstable": "nixpkgs-unstable", "sops-nix": "sops-nix", @@ -166,14 +202,14 @@ }, "system-screen": { "inputs": { - "nixpkgs": "nixpkgs_3" + "nixpkgs": "nixpkgs_4" }, "locked": { - "lastModified": 1787850270, - "narHash": "sha256-uIpTfhLcpGHtVRXrVGbws/3eIwH3Ch/8b+ZbBuqK/ZA=", + "lastModified": 1787911919, + "narHash": "sha256-C6tpLyXsLLoEpXWUh/hJO17COZ9oVNUvSVx2iJIh2w0=", "ref": "refs/heads/main", - "rev": "c9ffc9d8f056d437ff2195fe676893f501b40af9", - "revCount": 15, + "rev": "8328d561302c233002c440302d5f71d70bfe3e81", + "revCount": 17, "type": "git", "url": "https://tangled.org/tobinio.dev/system-screen" }, @@ -184,7 +220,7 @@ }, "taskline": { "inputs": { - "nixpkgs": "nixpkgs_4" + "nixpkgs": "nixpkgs_5" }, "locked": { "lastModified": 1787321226, diff --git a/flake.nix b/flake.nix index 534bd15..8c63ad7 100644 --- a/flake.nix +++ b/flake.nix @@ -12,6 +12,7 @@ lightcontrol.url = "git+https://tangled.org/tobinio.dev/light-control"; taskline.url = "git+https://tangled.org/tobinio.dev/task-line?ref=refs/tags/v3.0.0"; + modrinth-statistics.url = "git+https://tangled.org/tobinio.dev/modrinth-statistics?ref=refs/tags/v4.0.1"; zen-browser = { url = "github:youwen5/zen-browser-flake"; diff --git a/hosts/homeserver/secrets.yaml b/hosts/homeserver/secrets.yaml index f8af96a..f1c0ac0 100644 --- a/hosts/homeserver/secrets.yaml +++ b/hosts/homeserver/secrets.yaml @@ -14,7 +14,6 @@ nextcloud_admin_password: ENC[AES256_GCM,data:VHcdwclX/F7awXAT8wWXfmGLWnbrB7Ac,i #ENC[AES256_GCM,data:KYJNIEZMTQ==,iv:MbTQlzlTX7i4TB2hnvkts3kJ+xwdgiFLB2LSzAbexAs=,tag:kg6UIdDfPXY8skaex0JSvA==,type:comment] restic_password: ENC[AES256_GCM,data:KOkaDvfS45O6xpS1JU4=,iv:LxeovfjYsHLkmXV8fIKvbOWttAz7CBRXxwwcMaGJ2lA=,tag:V7PcE4EXqsobEx+biliDYA==,type:str] #ENC[AES256_GCM,data:NQOKvwrNwTKCtwVc1FDOLyUtx5I=,iv:zjvWQIt+XQrZ2JWTXCjt748wuFRbvbVhmM8de93NJks=,tag:tLeaeVA9o8QnSWffmmctDg==,type:comment] -nuxt_db_url: ENC[AES256_GCM,data:LNTjBUDD64kC1GQLyWsBKVn6qXBFJEocK4xggDOme6i3J6uP8bvy6JR+165uncvuL5+iAMJCcW1hi3ZoXJmZ3vS30SYC7IJgxGk5FxpudfzmaUIIObFxuUWCTKC2,iv:Ag0NvQ8KE1dsxcuJVHdGoA7+FhnCZUlENxjfNfRlgfA=,tag:OaKUrx1WAHz4L2dU0nS7jg==,type:str] nuxt_public_umami_id: ENC[AES256_GCM,data:UUb+hfuq2dm88bxgHpD00BHSajdYoxO9kCGZIRwZAmKdZUrd,iv:CJpNJHpOkYP6bCFxC8b9W0/ghP+UUnzLXI8xOt/cp1I=,tag:L4dRS7a3vkO3ab6eN3CpfA==,type:str] sops: age: @@ -27,7 +26,7 @@ sops: ymzV/vprvtzMGSPZLLwURHKO8PZBZ7VV8zL/wGSxFcposVnLwo5qFQ== -----END AGE ENCRYPTED FILE----- recipient: age185ejn50rqg7tnzcrkp5f9w7p6vf4ex3k9k472xlyvpenanrgnv4q6kyx9n - lastmodified: "2026-08-01T08:12:24Z" - mac: ENC[AES256_GCM,data:ko2xEWGxq+noXSRLZfp6NnUlCzeCqbLtuc9e/AO4jWrLx8TgINi7s7DTZ209kF3FGOkSKTvqUaI1HWho7JmxNOIfotUje53U/3ESu7LpbI8xU6c7HDx/sTDhlSirNKsdrT9SSN0QDYtijGKm7F25jdzZn6NUGcaL8l2fu3uO0pU=,iv:veNpM5TGLXfLpzfSyAeTObT4q3msX9nomG6BKFjyoVU=,tag:B2FqODqkTttL/UnLzG+1TQ==,type:str] + lastmodified: "2026-08-31T12:22:36Z" + mac: ENC[AES256_GCM,data:7HaVZVPaNUzJJFgUOUmeW7rvoaNW6EyQcgR+I2MSnKDUF2I5l1oJ4xfNK06kjtJkfRnzNjCrh7HvvZGGoA09CSJK/s0MrC4q3l3+iDRgJgND4qJhnKIB/9EGhRNjeY2zat79dUHJULcr6QhazHTDBT6pmzJM0D6G4IbjMiSvjKo=,iv:lUCJOCxeIM0/8CzICIC6G99xia6mPMjH35ORWFlvkZY=,tag:xKZNAf5Xjdsehm/WmSXIWA==,type:str] unencrypted_suffix: _unencrypted - version: 3.13.2 + version: 3.13.3 diff --git a/hosts/homeserver/services/modrinth-statistics.compose.yml b/hosts/homeserver/services/modrinth-statistics.compose.yml deleted file mode 100644 index e1c45b9..0000000 --- a/hosts/homeserver/services/modrinth-statistics.compose.yml +++ /dev/null @@ -1,12 +0,0 @@ -services: - modrinth-statistics: - image: atcr.io/tobinio.dev/modrinth-statistics:v3.0.0 - restart: unless-stopped - ports: - - 3002:3000 - env_file: - - /run/secrets/rendered/modrinth-statistics.env - volumes: - - /srv/apps/modrinth-statistics/data:/app/.data - extra_hosts: - - host.docker.internal:host-gateway diff --git a/hosts/homeserver/services/modrinth-statistics.nix b/hosts/homeserver/services/modrinth-statistics.nix index f5e01bb..5afb5c2 100644 --- a/hosts/homeserver/services/modrinth-statistics.nix +++ b/hosts/homeserver/services/modrinth-statistics.nix @@ -1,16 +1,52 @@ -{ config, ... }: +{ config, pkgs, inputs, ... }: { sops.secrets = { nuxt_public_umami_id = { }; - nuxt_db_url = { }; }; - sops.templates."modrinth-statistics.env" = { - content = '' + sops.templates."modrinth-statistics.env".content = '' NUXT_PUBLIC_UMAMI_ID=${config.sops.placeholder.nuxt_public_umami_id} - NUXT_DB_URL=${config.sops.placeholder.nuxt_db_url} ''; - group = "env-secrets"; - mode = "0440"; + + users.users.modrinth-statistics = { + isSystemUser = true; + group = "modrinth-statistics"; + }; + users.groups.modrinth-statistics = {}; + + + systemd.services.modrinth-statistics= { + description = "Modrinth Statistics"; + after = [ "network.target" "postgresql.service" ]; + wantedBy = [ "multi-user.target" ]; + + environment = { + PORT = "3002"; + HOST = "0.0.0.0"; + NUXT_DB_URL = "postgresql://modrinth-statistics@localhost/modrinth-statistics?host=/run/postgresql"; + NUXT_METADATA_BASE = "/srv/apps/modrinth-statistics/data/metadata"; + }; + + serviceConfig = { + ExecStart = "${pkgs.nodejs_24}/bin/node ${inputs.modrinth-statistics.packages.${pkgs.system}.default}/server/index.mjs"; + + WorkingDirectory = "${inputs.modrinth-statistics.packages.${pkgs.system}.default}"; + + User = "modrinth-statistics"; + + EnvironmentFile = config.sops.templates."modrinth-statistics.env".path; + + Restart = "always"; + RestartSec = 5; + + ProtectSystem = "strict"; + ProtectHome = true; + NoNewPrivileges = true; + PrivateTmp = true; + + ReadWritePaths = [ + "/srv/apps/modrinth-statistics" + ]; + }; }; } -- 2.51.2