summaryrefslogtreecommitdiff
path: root/custom/uucp-mediaserver.nix
blob: 5ed3b5ed91c08e05a83935b058e562bf704365c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
{ config, lib, pkgs, ... }:

with lib;

let
  cfg = config.services.uucp.media-server;

  touchStateFiles = name: ''
    touch ${cfg.queueDir}/${name}.queue
    touch ${cfg.queueDir}/${name}.space
    touch ${cfg.queueDir}/${name}.queuesize
    
    chown ${cfg.owner}:${cfg.group} ${cfg.queueDir}/${name}.queue ${cfg.queueDir}/${name}.space ${cfg.queueDir}/${name}.queuesize

    chmod 660 ${cfg.queueDir}/${name}.queue ${cfg.queueDir}/${name}.space ${cfg.queueDir}/${name}.queuesize
  '';

  scripts = pkgs.callPackage ./uucp-mediaserver/scripts.nix { config = cfg; };
in {
  options = {
    services.uucp.media-server = {
      enable = mkEnableOption "UUCP media server";

      remoteNodes = mkOption {
        type = types.listOf types.str;
        default = [];
        description = ''
          Clients to track
        '';
      };

      queueDir = mkOption {
        type = types.path;
        default = "/var/spool/media";
        description = "Queue directory";
      };

      owner = mkOption {
        type = types.str;
        default = "root";
        description = "Owner of the various queue files";
      };

      group = mkOption {
        type = types.str;
        default = "media";
        description = "Group of the various queue files";
      };
    };
  };

  config = mkIf cfg.enable {
    system.activationScripts."uucp-media-server" = ''
      mkdir -p ${cfg.queueDir}
      chmod 750 ${cfg.queueDir}
      chown ${cfg.owner}:${cfg.group} ${cfg.queueDir}
      
      ${concatStringsSep "\n" (map touchStateFiles cfg.remoteNodes)}
    '';

    environment.systemPackages = [ scripts ];

    services.uucp.commandPath = [ "${scripts}/bin" ];
    services.uucp.remoteNodes = genAttrs cfg.remoteNodes (name: { commands = ["mediaspace.${name}"]; } );
  };
}