1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6 cfg = config.services.u9fs;
7in
8{
9
10 options = {
11
12 services.u9fs = {
13
14 enable = mkOption {
15 type = types.bool;
16 default = false;
17 description = lib.mdDoc "Whether to run the u9fs 9P server for Unix.";
18 };
19
20 listenStreams = mkOption {
21 type = types.listOf types.str;
22 default = [ "564" ];
23 example = [ "192.168.16.1:564" ];
24 description = lib.mdDoc ''
25 Sockets to listen for clients on.
26 See {command}`man 5 systemd.socket` for socket syntax.
27 '';
28 };
29
30 user = mkOption {
31 type = types.str;
32 default = "nobody";
33 description =
34 lib.mdDoc "User to run u9fs under.";
35 };
36
37 extraArgs = mkOption {
38 type = types.str;
39 default = "";
40 example = "-a none";
41 description =
42 lib.mdDoc ''
43 Extra arguments to pass on invocation,
44 see {command}`man 4 u9fs`
45 '';
46 };
47
48 };
49
50 };
51
52 config = mkIf cfg.enable {
53
54 systemd = {
55 sockets.u9fs = {
56 description = "U9fs Listening Socket";
57 wantedBy = [ "sockets.target" ];
58 after = [ "network.target" ];
59 inherit (cfg) listenStreams;
60 socketConfig.Accept = "yes";
61 };
62 services."u9fs@" = {
63 description = "9P Protocol Server";
64 reloadIfChanged = true;
65 requires = [ "u9fs.socket" ];
66 serviceConfig =
67 { ExecStart = "-${pkgs.u9fs}/bin/u9fs ${cfg.extraArgs}";
68 StandardInput = "socket";
69 StandardError = "journal";
70 User = cfg.user;
71 AmbientCapabilities = "cap_setuid cap_setgid";
72 };
73 };
74 };
75
76 };
77
78}