1{
2 config,
3 lib,
4 pkgs,
5 ...
6}:
7let
8 cfg = config.services.mame;
9 mame = "mame${lib.optionalString pkgs.stdenv.hostPlatform.is64bit "64"}";
10in
11{
12 options = {
13 services.mame = {
14 enable = lib.mkOption {
15 type = lib.types.bool;
16 default = false;
17 description = ''
18 Whether to setup TUN/TAP Ethernet interface for MAME emulator.
19 '';
20 };
21 user = lib.mkOption {
22 type = lib.types.str;
23 description = ''
24 User from which you run MAME binary.
25 '';
26 };
27 hostAddr = lib.mkOption {
28 type = lib.types.str;
29 description = ''
30 IP address of the host system. Usually an address of the main network
31 adapter or the adapter through which you get an internet connection.
32 '';
33 example = "192.168.31.156";
34 };
35 emuAddr = lib.mkOption {
36 type = lib.types.str;
37 description = ''
38 IP address of the guest system. The same you set inside guest OS under
39 MAME. Should be on the same subnet as {option}`services.mame.hostAddr`.
40 '';
41 example = "192.168.31.155";
42 };
43 };
44 };
45
46 config = lib.mkIf cfg.enable {
47 environment.systemPackages = [ pkgs.mame ];
48
49 security.wrappers."${mame}" = {
50 owner = "root";
51 group = "root";
52 capabilities = "cap_net_admin,cap_net_raw+eip";
53 source = "${pkgs.mame}/bin/${mame}";
54 };
55
56 systemd.services.mame = {
57 description = "MAME TUN/TAP Ethernet interface";
58 after = [ "network.target" ];
59 wantedBy = [ "multi-user.target" ];
60 path = [ pkgs.iproute2 ];
61 serviceConfig = {
62 Type = "oneshot";
63 RemainAfterExit = true;
64 ExecStart = "${pkgs.mame}/bin/taputil.sh -c ${cfg.user} ${cfg.emuAddr} ${cfg.hostAddr} -";
65 ExecStop = "${pkgs.mame}/bin/taputil.sh -d ${cfg.user}";
66 };
67 };
68 };
69
70 meta.maintainers = [ ];
71}