2024-03-17 22:13:28 -06:00
|
|
|
{ config, lib, pkgs, timeZone, ... }:
|
|
|
|
let
|
|
|
|
srvConfig = config.serverConfig;
|
|
|
|
in
|
|
|
|
{
|
2024-03-17 22:29:41 -06:00
|
|
|
options.serverConfig= {
|
2024-03-17 22:13:28 -06:00
|
|
|
userName = lib.mkOption {
|
2024-03-18 09:53:08 -06:00
|
|
|
type = lib.types.str;
|
|
|
|
description = "Main username for system";
|
2024-03-17 22:13:28 -06:00
|
|
|
};
|
|
|
|
hostName = lib.mkOption {
|
2024-03-18 09:53:08 -06:00
|
|
|
type = lib.types.str;
|
|
|
|
description = "Hostname for system";
|
2024-03-17 22:13:28 -06:00
|
|
|
};
|
|
|
|
hostId = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
description = "Host ID";
|
|
|
|
};
|
|
|
|
email = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
description = "Email for server box";
|
|
|
|
};
|
|
|
|
sshEnable = lib.mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "Whether to enable ssh server";
|
|
|
|
};
|
|
|
|
nfsEnable = lib.mkOption {
|
|
|
|
default = false;
|
|
|
|
};
|
2024-03-18 09:53:08 -06:00
|
|
|
nfsRoot = lib.mkOption {
|
|
|
|
default = "/nfs_export";
|
|
|
|
type = lib.types.str;
|
|
|
|
};
|
|
|
|
nfsExports = lib.mkOption {
|
|
|
|
default = [];
|
|
|
|
description = "List of file paths provided as strings to the nfs exports";
|
|
|
|
};
|
2024-03-18 12:45:31 -06:00
|
|
|
nfsIpExport = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
|
|
|
description = "Where to export the shares to i.e. 192.168.0.0/24 (export to local network)";
|
|
|
|
};
|
|
|
|
syncthingEnable = lib.mkOption {
|
|
|
|
default = false;
|
|
|
|
description = "Whether to enable syncThing host on this machine";
|
|
|
|
};
|
2024-03-17 22:13:28 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
imports = [
|
|
|
|
./modules/user/main_user.nix
|
|
|
|
];
|
|
|
|
|
2024-03-17 22:16:55 -06:00
|
|
|
config = {
|
|
|
|
# Enable flakes feature
|
|
|
|
nix.settings.experimental-features = [
|
|
|
|
"nix-command" "flakes"
|
|
|
|
];
|
2024-03-17 22:13:28 -06:00
|
|
|
|
2024-03-17 22:16:55 -06:00
|
|
|
boot.loader.systemd-boot.enable = true;
|
|
|
|
boot.loader.efi.canTouchEfiVariables = true;
|
2024-03-17 22:13:28 -06:00
|
|
|
|
2024-03-17 22:16:55 -06:00
|
|
|
networking = {
|
|
|
|
hostId = srvConfig.hostId;
|
|
|
|
hostName = srvConfig.hostName; # Define your hostname.
|
|
|
|
# Pick only one of the below networking options.
|
|
|
|
# networking.wireless.enable = true; # Enables wireless support via wpa_supplicant.
|
|
|
|
networkmanager.enable = true; # Easiest to use and most distros use this by default.
|
|
|
|
};
|
2024-03-17 22:13:28 -06:00
|
|
|
|
2024-03-17 22:16:55 -06:00
|
|
|
time.timeZone = timeZone;
|
2024-03-17 22:13:28 -06:00
|
|
|
|
2024-03-17 22:16:55 -06:00
|
|
|
main_user = {
|
|
|
|
enable = true;
|
|
|
|
userName = srvConfig.userName;
|
|
|
|
isDesktopUser = false;
|
|
|
|
};
|
2024-03-17 22:13:28 -06:00
|
|
|
|
2024-03-17 22:25:47 -06:00
|
|
|
environment.systemPackages = with pkgs; [
|
|
|
|
docker
|
|
|
|
docker-compose
|
2024-03-17 22:55:53 -06:00
|
|
|
zsh
|
2024-03-17 22:25:47 -06:00
|
|
|
];
|
|
|
|
|
2024-03-17 22:55:53 -06:00
|
|
|
programs.zsh.enable = true;
|
|
|
|
|
2024-03-17 22:16:55 -06:00
|
|
|
services.openssh = lib.mkIf srvConfig.sshEnable {
|
|
|
|
enable = true;
|
|
|
|
};
|
2024-03-17 22:13:28 -06:00
|
|
|
|
2024-03-18 12:45:31 -06:00
|
|
|
# nfs options breakdown: link for export options https://linux.die.net/man/5/exports
|
|
|
|
# rw - default read write
|
|
|
|
# sync - wait until requests are saved to disk to respond to clients, safer but slower
|
|
|
|
# no_subtree_check -
|
2024-03-17 22:16:55 -06:00
|
|
|
services.nfs.server = lib.mkIf srvConfig.nfsEnable {
|
|
|
|
enable = true;
|
|
|
|
exports = ''
|
2024-03-18 12:45:31 -06:00
|
|
|
${srvConfig.nfsRoot} ${srvConfig.nfsIpExport}(rw,fsid=root,no_subtree_check)
|
2024-03-18 19:50:59 -06:00
|
|
|
${lib.concatMapStringsSep "\n" (n: "${srvConfig.nfsRoot}${n} ${srvConfig.nfsIpExport}(rw,sync,no_subtree_check,all_squash,anongid=105,anonuid=1005)") srvConfig.nfsExports}
|
2024-03-18 09:53:08 -06:00
|
|
|
'';
|
2024-03-17 22:16:55 -06:00
|
|
|
};
|
2024-03-18 12:45:31 -06:00
|
|
|
# nfs port TODO make dependant on option enabled
|
2024-03-18 12:54:37 -06:00
|
|
|
# 2049 - nfs
|
|
|
|
# 8384 - syncthing
|
2024-03-18 14:05:48 -06:00
|
|
|
networking.firewall.allowedTCPPorts = [ 80 2049 8384 ];
|
2024-03-17 22:13:28 -06:00
|
|
|
|
2024-03-18 19:50:59 -06:00
|
|
|
users.groups.kage = {
|
|
|
|
gid = 105;
|
|
|
|
};
|
2024-03-18 19:45:31 -06:00
|
|
|
users.users.kage = {
|
2024-03-18 19:50:59 -06:00
|
|
|
uid = 1005;
|
2024-03-18 19:45:31 -06:00
|
|
|
isSystemUser = true;
|
|
|
|
initialPassword = "password";
|
|
|
|
description = "user to manage nfs and syncthing tasks";
|
|
|
|
group = "kage";
|
|
|
|
extraGroups = [
|
|
|
|
"users"
|
|
|
|
];
|
|
|
|
};
|
2024-03-18 12:45:31 -06:00
|
|
|
|
|
|
|
services.syncthing = lib.mkIf srvConfig.syncthingEnable {
|
|
|
|
enable = true;
|
2024-03-18 19:45:31 -06:00
|
|
|
user = "kage";
|
|
|
|
group = "users";
|
2024-03-18 12:45:31 -06:00
|
|
|
dataDir = "${srvConfig.nfsRoot}/kage/syncthing";
|
|
|
|
configDir = "${srvConfig.nfsRoot}/kage/.config/syncthing";
|
2024-03-18 12:54:37 -06:00
|
|
|
# overrideDevices = true; # overrides any devices added or deleted through the WebUI
|
|
|
|
# overrideFolders = true; # overrides any folders added or deleted through the WebUI
|
2024-03-18 12:45:31 -06:00
|
|
|
openDefaultPorts = true;
|
2024-03-18 19:45:31 -06:00
|
|
|
relay.enable = true;
|
2024-03-18 14:14:19 -06:00
|
|
|
guiAddress = "0.0.0.0:8384";
|
2024-03-18 12:56:34 -06:00
|
|
|
# settings = {
|
|
|
|
# devices = {
|
|
|
|
# # "supernote" = { id = "DEVICE-ID-GOES-HERE"; };
|
|
|
|
# # "pixel" = { id = "DEVICE-ID-GOES-HERE2"; };
|
|
|
|
# # "winmax" = { id = "id3"; };
|
|
|
|
# # "nix-box" = { id = "id4"; };
|
|
|
|
# };
|
|
|
|
# folders = {
|
|
|
|
# "supernote" = { # Name of folder in Syncthing, also the folder ID
|
|
|
|
# path = "${srvConfig.nfsRoot}/kage/syncthing/supernote"; # Which folder to add to Syncthing
|
|
|
|
# # devices = [ "supernote" "pixel" ]; # Which devices to share the folder with
|
|
|
|
# };
|
|
|
|
# "web" = { # Name of folder in Syncthing, also the folder ID
|
|
|
|
# path = "${srvConfig.nfsRoot}/kage/syncthing/web"; # Which folder to add to Syncthing
|
|
|
|
# # devices = [ "supernote" "pixel" "winmax" "nix-box" ]; # Which devices to share the folder with
|
|
|
|
# };
|
|
|
|
# };
|
|
|
|
# };
|
2024-03-18 12:45:31 -06:00
|
|
|
};
|
2024-03-23 03:43:52 -06:00
|
|
|
|
|
|
|
systemd.timers."pixel-backups" = {
|
|
|
|
wantedBy = [ "timers.target" ];
|
|
|
|
timerConfig = {
|
|
|
|
OnCalendar = "daily";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services."pixel-backups" = {
|
|
|
|
script = ''
|
|
|
|
# Move files older than 90 days to the backups file
|
|
|
|
find /nfs_export/kage/syncthing/pixel_images/ -type f -mtime +90 | xargs -I {} mv {} /nfs_export/kage/Personal_Media/Nate/
|
|
|
|
'';
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
User = "root";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-03-17 22:16:55 -06:00
|
|
|
# networking.firewall.allowedTCPPorts = [ ... ];
|
|
|
|
# networking.firewall.allowedUDPPorts = [ ... ];
|
2024-03-17 22:13:28 -06:00
|
|
|
|
2024-03-17 22:16:55 -06:00
|
|
|
system.stateVersion = "23.11"; # Did you read the comment?
|
|
|
|
};
|
2024-03-17 22:13:28 -06:00
|
|
|
}
|