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 = "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 = '' 25 Sockets to listen for clients on. 26 See <command>man 5 systemd.socket</command> for socket syntax. 27 ''; 28 }; 29 30 extraArgs = mkOption { 31 type = types.str; 32 default = ""; 33 example = "-a none -u nobody"; 34 description = 35 '' 36 Extra arguments to pass on invocation, 37 see <command>man 4 u9fs</command> 38 ''; 39 }; 40 41 fsroot = mkOption { 42 type = types.path; 43 default = "/"; 44 example = "/srv"; 45 description = "File system root to serve to clients."; 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 inherit (cfg) listenStreams; 59 socketConfig.Accept = "yes"; 60 }; 61 services."u9fs@" = { 62 description = "9P Protocol Server"; 63 reloadIfChanged = true; 64 requires = [ "u9fs.socket" ]; 65 serviceConfig = 66 { ExecStart = "-${pkgs.u9fs}/bin/u9fs ${cfg.extraArgs} ${cfg.fsroot}"; 67 StandardInput = "socket"; 68 StandardError = "journal"; 69 }; 70 }; 71 }; 72 73 }; 74 75}