2023-09-12 13:31:46 +03:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
2023-09-12 16:08:08 +03:00
|
|
|
myData,
|
2023-09-12 13:31:46 +03:00
|
|
|
...
|
2023-09-17 22:12:46 +03:00
|
|
|
}: let
|
|
|
|
cfg = config.mj.services.jakstpub;
|
|
|
|
subnets = myData.subnets;
|
|
|
|
in {
|
2023-09-12 13:31:46 +03:00
|
|
|
options.mj.services.jakstpub = with lib.types; {
|
|
|
|
enable = lib.mkEnableOption "Enable jakstpub";
|
|
|
|
dataDir = lib.mkOption {type = path;};
|
|
|
|
# RequiresMountsFor is used by upstream, hacking with the unit
|
|
|
|
requires = lib.mkOption {type = listOf str;};
|
|
|
|
uidgid = lib.mkOption {type = int;};
|
2023-09-12 23:18:46 +03:00
|
|
|
hostname = lib.mkOption {type = str;};
|
2023-09-12 13:31:46 +03:00
|
|
|
};
|
|
|
|
|
2023-09-17 22:12:46 +03:00
|
|
|
config = lib.mkIf cfg.enable {
|
|
|
|
services.caddy = {
|
|
|
|
enable = true;
|
2023-09-17 22:16:11 +03:00
|
|
|
virtualHosts.":80".extraConfig = with myData.subnets; ''
|
2023-09-17 22:12:46 +03:00
|
|
|
root * ${cfg.dataDir}
|
2023-09-17 22:16:11 +03:00
|
|
|
@denied not remote_ip ${vno1.cidr} ${vno3.cidr} ${tailscale.cidr}
|
2023-09-17 22:31:12 +03:00
|
|
|
file_server browse {
|
|
|
|
hide .stfolder
|
|
|
|
}
|
2023-09-17 22:12:46 +03:00
|
|
|
encode gzip
|
|
|
|
'';
|
|
|
|
};
|
2023-09-12 13:31:46 +03:00
|
|
|
|
2023-09-17 22:12:46 +03:00
|
|
|
services.samba = {
|
|
|
|
# https://wiki.samba.org/index.php/Setting_up_Samba_as_a_Standalone_Server
|
|
|
|
enable = true;
|
|
|
|
securityType = "user";
|
|
|
|
enableNmbd = false;
|
|
|
|
enableWinbindd = false;
|
|
|
|
extraConfig = ''
|
|
|
|
map to guest = Bad User
|
|
|
|
guest account = jakstpub
|
|
|
|
server role = standalone server
|
|
|
|
'';
|
|
|
|
shares = {
|
|
|
|
public = {
|
|
|
|
path = cfg.dataDir;
|
|
|
|
writeable = "yes";
|
|
|
|
public = "yes";
|
|
|
|
"guest ok" = "yes";
|
|
|
|
"read only" = "no";
|
|
|
|
"create mask" = "0664";
|
|
|
|
"directory mask" = "0775";
|
|
|
|
"force user" = "jakstpub";
|
|
|
|
"force group" = "jakstpub";
|
|
|
|
};
|
2023-09-12 23:18:46 +03:00
|
|
|
};
|
2023-09-17 22:12:46 +03:00
|
|
|
};
|
2023-09-12 23:10:59 +03:00
|
|
|
|
2023-09-17 22:12:46 +03:00
|
|
|
services.samba-wsdd = {
|
|
|
|
enable = true;
|
|
|
|
hostname = cfg.hostname;
|
|
|
|
};
|
2023-09-12 13:31:46 +03:00
|
|
|
|
2023-09-17 22:12:46 +03:00
|
|
|
users.users.jakstpub = {
|
|
|
|
description = "Jakstys Public";
|
|
|
|
home = "/var/empty";
|
|
|
|
useDefaultShell = true;
|
|
|
|
group = "jakstpub";
|
|
|
|
isSystemUser = true;
|
|
|
|
createHome = false;
|
|
|
|
uid = cfg.uidgid;
|
|
|
|
};
|
2023-09-12 13:31:46 +03:00
|
|
|
|
2023-09-17 22:12:46 +03:00
|
|
|
users.groups.jakstpub.gid = cfg.uidgid;
|
2023-09-12 13:31:46 +03:00
|
|
|
|
2023-09-17 22:12:46 +03:00
|
|
|
systemd.services.samba-smbd = {
|
|
|
|
unitConfig.Requires = cfg.requires;
|
2023-09-12 13:31:46 +03:00
|
|
|
};
|
2023-09-17 22:12:46 +03:00
|
|
|
|
|
|
|
mj.services.friendlyport.ports = [
|
|
|
|
{
|
|
|
|
subnets = with myData.subnets; [tailscale.cidr vno1.cidr vno3.cidr];
|
|
|
|
tcp = [
|
|
|
|
80 # caddy above
|
|
|
|
139 # smbd
|
|
|
|
445 # smbd
|
|
|
|
5357 # wsdd
|
|
|
|
];
|
|
|
|
udp = [3702]; # wsdd
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
2023-09-12 13:31:46 +03:00
|
|
|
}
|