summaryrefslogtreecommitdiff
path: root/custom/uucp-mediaserver.nix
blob: 6ac22738e92aafbf705390cab7c5e6224f8ee99a (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
{ 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
  '';
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 = [ (pkgs.callPackage ./uucp-mediaserver/scripts.nix { config = cfg; }) ];
  };
}