summaryrefslogtreecommitdiffstats
path: root/makefu/3modules/ps3netsrv.nix
blob: bb2abd9a56e1e3873f9431291f037816b40802f8 (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
{ config, lib, pkgs, ... }:

with import <stockholm/lib>;
let
  cfg = config.makefu.ps3netsrv;

  out = {
    options.makefu.ps3netsrv = api;
    config = lib.mkIf cfg.enable imp;
  };

  api = {
    enable = mkEnableOption "ps3netsrv";

    servedir = mkOption {
      description = "path to serve, must be set";
      type = types.str;
    };

    package = mkOption {
      type = types.package;
      default = pkgs.ps3netsrv;
    };

    user = mkOption {
      description = ''user which will run ps3netsrv'';
      type = types.str;
      default = "ps3netsrv";
    };
  };

  imp = {
    systemd.services.ps3netsrv = {
      description = "ps3netsrv server";
      after = [ "network.target" ];
      wantedBy = [ "multi-user.target" ];
      restartIfChanged = true;
      unitConfig = {
        Documentation = "https://www.arm-blog.com/playing-ps3-games-from-your-nas/" ;
        ConditionPathExists = cfg.servedir;
      };
      serviceConfig = {
        Type = "simple";
        ExecStart = "${cfg.package}/bin/ps3netsrv++ ${shell.escape cfg.servedir}";
        PrivateTmp = true;
        User = "${cfg.user}";
      };
    };

    # TODO only create if user is ps3netsrv
    users.users.ps3netsrv = {
      uid = genid "ps3netsrv";
      isSystemUser = true;
      group = "ps3netsrv";
    };
    users.groups.ps3netsrv.gid = genid "ps3netsrv";
  };
in
out