commit 1ca165ae69c91ae30e515b3393566f4ce8074756
parent a9edddab3956d32f243fb7b40f07557ad44a4ffe
Author: mtmn <miro@haravara.org>
Date: Fri, 17 Apr 2026 22:01:11 +0200
feat: add corpus users
Diffstat:
8 files changed, 139 insertions(+), 96 deletions(-)
diff --git a/flake.lock b/flake.lock
@@ -30,11 +30,11 @@
"nixpkgs": "nixpkgs"
},
"locked": {
- "lastModified": 1776442559,
- "narHash": "sha256-CUhv54ZsbGOLNpjQkYKSD96YhmPR2ALdTiBxzTacEQc=",
+ "lastModified": 1776457026,
+ "narHash": "sha256-6k5byZX+HtJYmm7L0IBM94yUnv4zJusQOsNdEGjw6fQ=",
"ref": "refs/heads/master",
- "rev": "59d93f48ad7f35305f5a702d845540a444603e40",
- "revCount": 67,
+ "rev": "378fad49448cb11d4970cde6935ad8b840a6a6c1",
+ "revCount": 72,
"type": "git",
"url": "ssh://git@codeberg.org/mtmn/corpus"
},
@@ -182,11 +182,11 @@
]
},
"locked": {
- "lastModified": 1776373306,
- "narHash": "sha256-iAJIzHngGZeLIkjzuuWI6VBsYJ1n89a/Esq0m8R1vjs=",
+ "lastModified": 1776454077,
+ "narHash": "sha256-7zSUFWsU0+jlD7WB3YAxQ84Z/iJurA5hKPm8EfEyGJk=",
"owner": "nix-community",
"repo": "home-manager",
- "rev": "d401492e2acd4fea42f7705a3c266cea739c9c36",
+ "rev": "565e5349208fe7d0831ef959103c9bafbeac0681",
"type": "github"
},
"original": {
@@ -239,11 +239,11 @@
},
"nixpkgs": {
"locked": {
- "lastModified": 1775793324,
- "narHash": "sha256-omax7atcZbol+6HJ2RLpP+ZCFcPa5bZ65Hn71RufeWQ=",
+ "lastModified": 1776255774,
+ "narHash": "sha256-psVTpH6PK3q1htMJpmdz1hLF5pQgEshu7gQWgKO6t6Y=",
"owner": "NixOS",
"repo": "nixpkgs",
- "rev": "9d29d5f667d7467f98efc31881e824fa586c927e",
+ "rev": "566acc07c54dc807f91625bb286cb9b321b5f42a",
"type": "github"
},
"original": {
diff --git a/flake.nix b/flake.nix
@@ -178,9 +178,6 @@
"static"
"miniflux"
"corpus"
- "corpus-pstmn"
- "corpus-robo"
- "corpus-filip"
"napkins"
"listenbrainz-mpd"
"redlib"
diff --git a/hosts/nixaran/configuration.nix b/hosts/nixaran/configuration.nix
Binary files differ.
diff --git a/modules/mixins/corpus/users.dhall b/modules/mixins/corpus/users.dhall
@@ -0,0 +1,52 @@
+let UserConfig =
+ { listenbrainzUser : Optional Text
+ , lastfmUser : Optional Text
+ , databaseFile : Text
+ , coverCacheEnabled : Bool
+ , backupEnabled : Bool
+ , backupIntervalHours : Natural
+ , initialSync : Bool
+ }
+
+let defaults
+ : UserConfig
+ = { listenbrainzUser = None Text
+ , lastfmUser = None Text
+ , databaseFile = "corpus.db"
+ , coverCacheEnabled = True
+ , backupEnabled = False
+ , backupIntervalHours = 1
+ , initialSync = False
+ }
+
+in { users =
+ [ { slug = ""
+ , config =
+ defaults
+ with listenbrainzUser = Some "mtmn"
+ with databaseFile = "corpus.db"
+ with backupEnabled = True
+ }
+ , { slug = "filip"
+ , config =
+ defaults
+ with lastfmUser = Some "bozemoj"
+ with databaseFile = "filip.db"
+ with backupEnabled = True
+ }
+ , { slug = "robo"
+ , config =
+ defaults
+ with lastfmUser = Some "robo_k"
+ with databaseFile = "robo.db"
+ with backupEnabled = True
+ }
+ , { slug = "pstmn"
+ , config =
+ defaults
+ with lastfmUser = Some "post_man"
+ with databaseFile = "pstmn.db"
+ with backupEnabled = True
+ }
+ ]
+ }
diff --git a/modules/mixins/dotfiles/bin/aif2flac b/modules/mixins/dotfiles/bin/aif2f
diff --git a/modules/services/corpus.nix b/modules/services/corpus.nix
@@ -1,5 +1,78 @@
-import ./mk-corpus.nix {
- optionName = "corpus";
- defaultPort = 8321;
- defaultSecretFile = ../../secrets/corpus.age;
+{
+ config,
+ lib,
+ pkgs,
+ inputs,
+ ...
+}: let
+ cfg = config.services.haravara.corpus;
+
+ users =
+ pkgs.runCommand "users.json" {
+ nativeBuildInputs = [pkgs.dhall-json];
+ } ''
+ dhall-to-json --file ${./../mixins/corpus/users.dhall} > $out
+ '';
+in {
+ options.services.haravara.corpus = {
+ enable = lib.mkEnableOption "Corpus - ListenBrainz frontend";
+
+ port = lib.mkOption {
+ type = lib.types.port;
+ default = 8321;
+ };
+
+ domain = lib.mkOption {
+ type = lib.types.str;
+ };
+
+ dataDir = lib.mkOption {
+ type = lib.types.str;
+ default = "/var/lib/corpus";
+ };
+
+ secretFile = lib.mkOption {
+ type = lib.types.path;
+ default = ../../secrets/corpus.age;
+ };
+ };
+
+ config = lib.mkIf cfg.enable {
+ age.secrets.corpus = {
+ file = cfg.secretFile;
+ owner = "corpus";
+ };
+
+ systemd.services.corpus = {
+ description = "Corpus - ListenBrainz frontend";
+ wantedBy = ["multi-user.target"];
+ after = ["network.target"];
+
+ environment = {
+ PORT = toString cfg.port;
+ CORPUS_CONFIG_FILE = "${users}";
+ DATABASE_PATH = cfg.dataDir;
+ };
+
+ serviceConfig = {
+ ExecStart = "${inputs.corpus.packages.${pkgs.stdenv.hostPlatform.system}.default}/bin/corpus-server";
+ EnvironmentFile = config.age.secrets.corpus.path;
+ Restart = "always";
+ User = "corpus";
+ Group = "corpus";
+ StateDirectory = "corpus";
+ WorkingDirectory = cfg.dataDir;
+ };
+ };
+
+ users.users.corpus = {
+ isSystemUser = true;
+ group = "corpus";
+ };
+ users.groups.corpus = {};
+
+ services.caddy.virtualHosts."${cfg.domain}".extraConfig = ''
+ reverse_proxy 127.0.0.1:${toString cfg.port}
+ '';
+ };
}
diff --git a/modules/services/mk-corpus.nix b/modules/services/mk-corpus.nix
@@ -1,79 +0,0 @@
-{
- optionName,
- defaultPort,
- defaultSecretFile,
-}: {
- config,
- lib,
- pkgs,
- inputs,
- ...
-}: let
- cfg = config.services.haravara.${optionName};
-in {
- options.services.haravara.${optionName} = {
- enable = lib.mkEnableOption "Corpus - ListenBrainz frontend";
-
- port = lib.mkOption {
- type = lib.types.port;
- default = defaultPort;
- };
-
- domain = lib.mkOption {
- type = lib.types.str;
- };
-
- dataDir = lib.mkOption {
- type = lib.types.str;
- default = "/var/lib/corpus";
- };
-
- databaseFile = lib.mkOption {
- type = lib.types.str;
- default = "${cfg.dataDir}/corpus.db";
- };
-
- secretFile = lib.mkOption {
- type = lib.types.path;
- default = defaultSecretFile;
- };
- };
-
- config = lib.mkIf cfg.enable {
- age.secrets.${optionName} = {
- file = cfg.secretFile;
- owner = "corpus";
- };
-
- systemd.services.${optionName} = {
- description = "Corpus - ListenBrainz frontend";
- wantedBy = ["multi-user.target"];
- after = ["network.target"];
-
- environment = {
- PORT = toString cfg.port;
- DATABASE_FILE = cfg.databaseFile;
- };
-
- serviceConfig = {
- ExecStart = "${inputs.corpus.packages.${pkgs.stdenv.hostPlatform.system}.default}/bin/corpus-server";
- EnvironmentFile = config.age.secrets.${optionName}.path;
- Restart = "always";
- User = "corpus";
- Group = "corpus";
- StateDirectory = "corpus";
- WorkingDirectory = cfg.dataDir;
- };
- };
-
- users.users.corpus = {
- isSystemUser = true;
- group = "corpus";
- };
- users.groups.corpus = {};
-
- services.caddy.virtualHosts."${cfg.domain}".extraConfig = ''
- reverse_proxy 127.0.0.1:${toString cfg.port}
- '';
- };
-}
diff --git a/secrets/corpus.age b/secrets/corpus.age
Binary files differ.