Separate host-specific samba and disk health config

This commit is contained in:
Yan Lin 2025-09-09 11:54:43 +02:00
parent 16cd2e5cbf
commit 617ab047a9
3 changed files with 182 additions and 58 deletions

View file

@ -4,11 +4,11 @@
./disk-config.nix ./disk-config.nix
./containers.nix # Host-specific container definitions ./containers.nix # Host-specific container definitions
./proxy.nix # Host-specific Traefik dynamic configuration ./proxy.nix # Host-specific Traefik dynamic configuration
./disk-health.nix # Host-specific disk health monitoring
../../../modules/tailscale.nix ../../../modules/tailscale.nix
../../../modules/podman.nix ../../../modules/podman.nix
../../../modules/traefik.nix ../../../modules/traefik.nix
../../../modules/samba.nix ../../../modules/samba.nix
../../../modules/disk-health.nix
../../../modules/borg.nix ../../../modules/borg.nix
]; ];
@ -222,6 +222,29 @@
# Enable experimental nix features # Enable experimental nix features
nix.settings.experimental-features = [ "nix-command" "flakes" ]; nix.settings.experimental-features = [ "nix-command" "flakes" ];
# Samba file sharing configuration
services.samba-custom = {
enable = true;
serverString = "hs NAS Server";
workgroup = "WORKGROUP";
shares = {
Media = {
path = "/mnt/storage/Media";
comment = "Media Storage";
browseable = true;
readOnly = false;
guestOk = false;
createMask = "0644";
directoryMask = "0755";
forceUser = "yanlin";
forceGroup = "users";
validUsers = [ "yanlin" ];
};
};
enableWSDD = true;
openFirewall = false;
};
# Borg backup configuration # Borg backup configuration
services.borgbackup-custom = { services.borgbackup-custom = {
enable = true; enable = true;

View file

@ -1,63 +1,164 @@
{ config, pkgs, lib, ... }: { config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.samba-custom;
in
{ {
# Enable Samba service options.services.samba-custom = {
services.samba = { enable = mkEnableOption "Samba file sharing service";
enable = true;
workgroup = mkOption {
# Enable SMB protocol versions type = types.str;
package = pkgs.samba4Full; default = "WORKGROUP";
description = "SMB workgroup name";
# Modern Samba configuration using settings };
settings = {
global = { serverString = mkOption {
# Server identification type = types.str;
workgroup = "WORKGROUP"; default = "NixOS Samba Server";
"server string" = "hs NAS Server"; description = "Server description string";
};
# Security settings
security = "user"; shares = mkOption {
"map to guest" = "never"; type = types.attrsOf (types.submodule {
options = {
# Performance optimizations path = mkOption {
"socket options" = "TCP_NODELAY IPTOS_LOWDELAY SO_RCVBUF=524288 SO_SNDBUF=524288"; type = types.str;
deadtime = "30"; description = "Path to the shared directory";
"use sendfile" = "yes"; };
# Logging comment = mkOption {
"log file" = "/var/log/samba/log.%m"; type = types.str;
"max log size" = "1000"; default = "";
"log level" = "0"; description = "Share description comment";
};
# Disable printer sharing
"load printers" = "no"; browseable = mkOption {
printing = "bsd"; type = types.bool;
"printcap name" = "/dev/null"; default = true;
"disable spoolss" = "yes"; description = "Whether share is browseable";
}; };
# Define shares readOnly = mkOption {
Media = { type = types.bool;
path = "/mnt/storage/Media"; default = false;
browseable = "yes"; description = "Whether share is read-only";
"read only" = "no"; };
"guest ok" = "no";
"create mask" = "0644"; guestOk = mkOption {
"directory mask" = "0755"; type = types.bool;
"force user" = "yanlin"; default = false;
"force group" = "users"; description = "Allow guest access";
"valid users" = "yanlin"; };
comment = "Media Storage";
}; createMask = mkOption {
type = types.str;
default = "0644";
description = "File creation mask";
};
directoryMask = mkOption {
type = types.str;
default = "0755";
description = "Directory creation mask";
};
forceUser = mkOption {
type = types.nullOr types.str;
default = null;
description = "Force files to be owned by this user";
};
forceGroup = mkOption {
type = types.nullOr types.str;
default = null;
description = "Force files to be owned by this group";
};
validUsers = mkOption {
type = types.listOf types.str;
default = [];
description = "List of valid users for this share";
};
};
});
default = {};
description = "Samba share definitions";
};
enableWSDD = mkOption {
type = types.bool;
default = true;
description = "Enable Web Service Discovery (WSD) for SMB discovery";
};
openFirewall = mkOption {
type = types.bool;
default = false;
description = "Open firewall ports for Samba";
}; };
}; };
# Enable SMB discovery config = mkIf cfg.enable {
services.samba-wsdd = { # Enable Samba service
enable = true; services.samba = {
openFirewall = false; # Keep firewall closed as requested enable = true;
# Enable SMB protocol versions
package = pkgs.samba4Full;
# Modern Samba configuration using settings
settings = {
global = {
# Server identification
workgroup = cfg.workgroup;
"server string" = cfg.serverString;
# Security settings
security = "user";
"map to guest" = "never";
# Performance optimizations
"socket options" = "TCP_NODELAY IPTOS_LOWDELAY SO_RCVBUF=524288 SO_SNDBUF=524288";
deadtime = "30";
"use sendfile" = "yes";
# Logging
"log file" = "/var/log/samba/log.%m";
"max log size" = "1000";
"log level" = "0";
# Disable printer sharing
"load printers" = "no";
printing = "bsd";
"printcap name" = "/dev/null";
"disable spoolss" = "yes";
};
# Generate share configurations
} // (mapAttrs (name: share: {
path = share.path;
browseable = if share.browseable then "yes" else "no";
"read only" = if share.readOnly then "yes" else "no";
"guest ok" = if share.guestOk then "yes" else "no";
"create mask" = share.createMask;
"directory mask" = share.directoryMask;
"valid users" = concatStringsSep " " share.validUsers;
comment = share.comment;
} // (optionalAttrs (share.forceUser != null) {
"force user" = share.forceUser;
}) // (optionalAttrs (share.forceGroup != null) {
"force group" = share.forceGroup;
})) cfg.shares);
};
# Enable SMB discovery
services.samba-wsdd = mkIf cfg.enableWSDD {
enable = true;
openFirewall = cfg.openFirewall;
};
}; };
# Configure SMB users - requires manual setup after deployment
# Run: sudo smbpasswd -a yanlin
} }