nix

Log | Files | Refs | README | LICENSE

mstream.nix (2413B)


      1 {
      2   config,
      3   lib,
      4   haravara,
      5   ...
      6 }: let
      7   cfg = config.services.haravara.mstream;
      8 in {
      9   options.services.haravara.mstream = {
     10     enable = lib.mkEnableOption "mStream music streaming server";
     11 
     12     port = lib.mkOption {
     13       type = lib.types.port;
     14       default = 3000;
     15       description = "Host port to expose mStream on (container listens on 3000)";
     16     };
     17 
     18     domain = lib.mkOption {
     19       type = lib.types.str;
     20       description = "Domain for the mStream instance";
     21     };
     22 
     23     musicDir = lib.mkOption {
     24       type = lib.types.str;
     25       default = "/srv/mstream";
     26       description = ''
     27         Shared music library on the host. Mounted read-write because mStream
     28         writes uploaded tracks here. Created and owned by the mstream user.
     29       '';
     30     };
     31 
     32     dataDir = lib.mkOption {
     33       type = lib.types.str;
     34       default = "/var/lib/haravara/mstream";
     35       description = "Directory for mStream state";
     36     };
     37 
     38     uid = lib.mkOption {
     39       type = lib.types.int;
     40       default = 992;
     41       description = "uid for the mstream user";
     42     };
     43 
     44     gid = lib.mkOption {
     45       type = lib.types.int;
     46       default = 992;
     47       description = "gid for the mstream group";
     48     };
     49 
     50     authLabel = haravara.authLabelOption;
     51   };
     52 
     53   config = lib.mkIf cfg.enable {
     54     virtualisation.oci-containers = {
     55       backend = "podman";
     56 
     57       containers.mstream = {
     58         image = "lscr.io/linuxserver/mstream@sha256:bede502eb4717fc2f25a7ec917d9f4bf63fce5bf18cbaca46aced1ddf8e8d2c3";
     59         ports = ["127.0.0.1:${toString cfg.port}:3000"];
     60         volumes = [
     61           "${cfg.dataDir}:/config"
     62           # rshared so the geesefs FUSE mount is visible inside the container
     63           "${cfg.musicDir}:/music:rshared"
     64         ];
     65         environment = {
     66           PUID = toString cfg.uid;
     67           PGID = toString cfg.gid;
     68           TZ = config.time.timeZone;
     69         };
     70       };
     71     };
     72 
     73     # musicDir is a geesefs mount managed elsewhere; only create the state dir.
     74     systemd.tmpfiles.rules = [
     75       "d ${cfg.dataDir} 0750 mstream mstream -"
     76     ];
     77 
     78     users = {
     79       users.mstream = {
     80         isSystemUser = true;
     81         group = "mstream";
     82         inherit (cfg) uid;
     83       };
     84       groups.mstream = {inherit (cfg) gid;};
     85     };
     86 
     87     services.caddy.virtualHosts."${cfg.domain}".extraConfig = ''
     88       ${haravara.mkAuthImport cfg.authLabel}
     89       reverse_proxy 127.0.0.1:${toString cfg.port}
     90     '';
     91   };
     92 }