2024-01-02 15:57:33 +01:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}: {
|
2023-11-03 22:59:13 +01:00
|
|
|
services.samba-wsdd.enable = true; # make shares visible for windows 10 clients
|
|
|
|
networking.firewall.allowedTCPPorts = [
|
|
|
|
5357 # wsdd
|
|
|
|
];
|
|
|
|
networking.firewall.allowedUDPPorts = [
|
|
|
|
3702 # wsdd
|
|
|
|
];
|
|
|
|
services.samba = {
|
|
|
|
enable = true;
|
|
|
|
securityType = "user";
|
|
|
|
openFirewall = true;
|
2024-01-02 15:57:33 +01:00
|
|
|
extraConfig = lib.concatLines [
|
|
|
|
''
|
|
|
|
logging = systemd
|
|
|
|
log level = 0 auth:2 passdb:2
|
|
|
|
passdb backend = tdbsam:${config.age.secrets.smbpassdb.path}
|
|
|
|
server role = standalone
|
|
|
|
''
|
|
|
|
# Show the server host name in the printer comment box in print manager
|
|
|
|
# and next to the IPC connection in net view.
|
|
|
|
"server string = patricks-tolles-nas"
|
|
|
|
# Set the NetBIOS name by which the Samba server is known.
|
2024-01-11 13:09:16 +01:00
|
|
|
"netbios name = patricks-tolles-nas"
|
2024-01-02 15:57:33 +01:00
|
|
|
# Disable netbios support. We don't need to support browsing since all
|
|
|
|
# clients hardcode the host and share names.
|
|
|
|
"disable netbios = yes"
|
|
|
|
# Deny access to all hosts by default.
|
|
|
|
"hosts deny = 0.0.0.0/0"
|
|
|
|
# Allow access to local network
|
|
|
|
"hosts allow = 192.168.178. 127.0.0.1 10.0.0. localhost"
|
|
|
|
|
|
|
|
"guest account = nobody"
|
|
|
|
"map to guest = bad user"
|
|
|
|
|
|
|
|
# Clients should only connect using the latest SMB3 protocol (e.g., on
|
|
|
|
# clients running Windows 8 and later).
|
|
|
|
"server min protocol = SMB3_11"
|
|
|
|
# Require native SMB transport encryption by default.
|
|
|
|
"server smb encrypt = required"
|
|
|
|
|
|
|
|
# Disable printer sharing. By default Samba shares printers configured
|
|
|
|
# using CUPS.
|
|
|
|
"load printers = no"
|
|
|
|
"printing = bsd"
|
|
|
|
"printcap name = /dev/null"
|
|
|
|
"disable spoolss = yes"
|
|
|
|
"show add printer wizard = no"
|
|
|
|
];
|
|
|
|
shares = let
|
|
|
|
mkShare = {
|
|
|
|
name,
|
|
|
|
user ? "smb",
|
|
|
|
group ? "smb",
|
|
|
|
}: cfg: {
|
|
|
|
"${name}" =
|
|
|
|
{
|
|
|
|
"path" = "/media/smb/${name}";
|
|
|
|
"read only" = "no";
|
|
|
|
"guest ok" = "no";
|
|
|
|
"create mask" = "0640";
|
|
|
|
"directory mask" = "0750";
|
|
|
|
"force user" = "${user}";
|
|
|
|
"force group" = "${group}";
|
|
|
|
"valid users" = "${user} @${group}";
|
|
|
|
"force create mode" = "0660";
|
|
|
|
"force directory mode" = "0770";
|
2024-01-10 15:00:59 +01:00
|
|
|
# Might be necessary for windows user to be able to open thing in smb
|
|
|
|
"acl allow execute always" = "no";
|
2024-01-02 15:57:33 +01:00
|
|
|
}
|
|
|
|
// cfg;
|
2023-11-03 22:59:13 +01:00
|
|
|
};
|
2024-01-02 15:57:33 +01:00
|
|
|
in
|
|
|
|
lib.mkMerge [
|
|
|
|
(mkShare {
|
|
|
|
name = "ggr-data";
|
|
|
|
user = "ggr";
|
|
|
|
group = "ggr";
|
|
|
|
} {})
|
|
|
|
(mkShare {
|
|
|
|
name = "patri-data";
|
|
|
|
user = "patrick";
|
|
|
|
group = "patrick";
|
|
|
|
} {})
|
2024-01-11 13:09:16 +01:00
|
|
|
(mkShare {
|
|
|
|
name = "helen-data";
|
|
|
|
user = "helen";
|
|
|
|
group = "helen";
|
|
|
|
} {})
|
|
|
|
(mkShare {
|
|
|
|
name = "david-data";
|
|
|
|
user = "david";
|
|
|
|
group = "david";
|
|
|
|
} {})
|
|
|
|
(mkShare {
|
|
|
|
name = "family-data";
|
|
|
|
user = "family";
|
|
|
|
group = "family";
|
|
|
|
} {})
|
2024-01-02 15:57:33 +01:00
|
|
|
((mkShare {name = "media";})
|
|
|
|
{
|
|
|
|
"read only" = "yes";
|
2024-01-11 13:09:16 +01:00
|
|
|
"write list" = "@family";
|
2024-01-02 15:57:33 +01:00
|
|
|
})
|
|
|
|
];
|
2023-11-03 22:59:13 +01:00
|
|
|
};
|
2024-01-11 13:09:16 +01:00
|
|
|
# to get this file start a smbd, add users using 'smbpasswd -a <user>'
|
2023-11-05 15:54:29 +01:00
|
|
|
# then export the database using 'pdbedit -e tdbsam:<location>'
|
|
|
|
age.secrets.smbpassdb = {
|
|
|
|
rekeyFile = ../../secrets/smbpassdb.tdb.age;
|
2023-11-03 22:59:13 +01:00
|
|
|
};
|
2024-01-02 15:57:33 +01:00
|
|
|
users = let
|
|
|
|
users = lib.unique (lib.mapAttrsToList (_: val: val."force user") config.services.samba.shares);
|
|
|
|
groups = lib.unique (users ++ (lib.mapAttrsToList (_: val: val."force group") config.services.samba.shares));
|
|
|
|
in {
|
|
|
|
users = lib.mkMerge (lib.flip map users (user: {
|
|
|
|
${user} = {
|
|
|
|
isNormalUser = true;
|
|
|
|
home = "/var/empty";
|
|
|
|
createHome = false;
|
|
|
|
useDefaultShell = false;
|
|
|
|
autoSubUidGidRange = false;
|
|
|
|
group = "${user}";
|
|
|
|
};
|
|
|
|
})
|
|
|
|
++ [
|
|
|
|
{
|
|
|
|
patrick.extraGroups = [
|
|
|
|
"family"
|
|
|
|
];
|
|
|
|
ggr.extraGroups = [
|
|
|
|
"family"
|
|
|
|
];
|
2024-01-11 13:09:16 +01:00
|
|
|
david.extraGroups = [
|
|
|
|
"family"
|
|
|
|
];
|
|
|
|
helen.extraGroups = [
|
|
|
|
"family"
|
|
|
|
];
|
2024-01-02 15:57:33 +01:00
|
|
|
}
|
|
|
|
]);
|
|
|
|
groups = lib.mkMerge (lib.flip map groups (group: {
|
|
|
|
${group} = {
|
|
|
|
};
|
|
|
|
}));
|
2023-11-03 22:59:13 +01:00
|
|
|
};
|
2024-01-02 15:57:33 +01:00
|
|
|
|
|
|
|
environment.persistence."/panzer/persist".directories = lib.flip lib.mapAttrsToList config.services.samba.shares (_: v: {
|
|
|
|
directory = "${v.path}";
|
|
|
|
user = "${v."force user"}";
|
|
|
|
group = "${v."force group"}";
|
|
|
|
mode = "0770";
|
|
|
|
});
|
2023-11-03 22:59:13 +01:00
|
|
|
}
|