This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

superconfig / 3modules / ksmbd.nix
3.1 kB 113 lines
1{ config, pkgs, lib, ... }: 2 3let 4 cfg = config.services.ksmbd; 5 6 smbToString = x: 7 if builtins.typeOf x == "bool" 8 then lib.boolToString x 9 else toString x; 10 11 shareConfig = name: 12 let share = lib.getAttr name cfg.shares; in 13 "[${name}]\n " + (smbToString ( 14 map 15 (key: "${key} = ${smbToString (lib.getAttr key share)}\n") 16 (lib.attrNames share) 17 )); 18in 19{ 20 options = { 21 services.ksmbd = { 22 enable = lib.mkEnableOption "Enable cifsd kernel server"; 23 24 openFirewall = lib.mkOption { 25 type = lib.types.bool; 26 default = false; 27 description = lib.mdDoc '' 28 Whether to automatically open the necessary ports in the firewall. 29 ''; 30 }; 31 32 securityType = lib.mkOption { 33 type = lib.types.str; 34 default = "user"; 35 description = "Samba security type"; 36 }; 37 38 extraConfig = lib.mkOption { 39 type = lib.types.lines; 40 default = ""; 41 description = '' 42 Additional global section and extra section lines go in here. 43 ''; 44 example = '' 45 guest account = nobody 46 map to guest = bad user 47 ''; 48 }; 49 50 shares = lib.mkOption { 51 default = { }; 52 description = '' 53 A set describing shared resources. 54 See <command>man smb.conf</command> for options. 55 ''; 56 type = lib.types.attrsOf (lib.types.attrsOf lib.types.unspecified); 57 example = lib.literalExample '' 58 { public = 59 { path = "/srv/public"; 60 "read only" = true; 61 browseable = "yes"; 62 "guest ok" = "yes"; 63 comment = "Public samba share."; 64 }; 65 } 66 ''; 67 }; 68 69 users = lib.mkOption { 70 default = [ ]; 71 type = lib.types.listOf (lib.types.submodule { 72 options = { 73 user = lib.mkOption { 74 type = lib.types.str; 75 }; 76 passwordFile = lib.mkOption { 77 type = lib.types.path; 78 }; 79 }; 80 }); 81 }; 82 }; 83 }; 84 config = lib.mkIf cfg.enable { 85 boot.kernelModules = [ "ksmbd" ]; 86 environment.systemPackages = [ pkgs.ksmbd-tools ]; 87 88 environment.etc."ksmbd/ksmbd.conf".text = '' 89 [global] 90 security = ${cfg.securityType} 91 ${cfg.extraConfig} 92 93 ${smbToString (map shareConfig (lib.attrNames cfg.shares))} 94 ''; 95 96 systemd.services.ksmbd = { 97 wantedBy = [ "multi-user.target" ]; 98 after = [ "network.target" ]; 99 path = [ pkgs.ksmbd-tools ]; 100 preStart = builtins.concatStringsSep "\n" 101 (map (it: "ksmbd.adduser -i /run/ksmbd/passwd -a ${it.user} < ${it.passwordFile}") cfg.users); 102 serviceConfig = { 103 Type = "forking"; 104 ExecStart = "${pkgs.ksmbd-tools}/bin/ksmbd.mountd -C /etc/ksmbd/ksmbd.conf -P /run/ksmbd/passwd"; 105 Restart = "always"; 106 PrivateTmp = true; 107 RuntimeDirectory = "ksmbd"; 108 }; 109 }; 110 111 networking.firewall.allowedTCPPorts = lib.mkIf cfg.openFirewall [ 445 ]; 112 }; 113}