From cd4a68b513eb125e0f202f152eee46395d597033 Mon Sep 17 00:00:00 2001 From: mjallen18 Date: Sun, 25 Feb 2024 18:21:21 -0600 Subject: [PATCH] more organization, or maybe disorganization... --- flake.nix | 8 +- hosts/default.nix | 62 ++++++++++++++ hosts/desktop/configuration.nix | 43 +--------- hosts/nas/configuration.nix | 70 ++++++++-------- hosts/pi4/configuration.nix | 4 +- modules/apps/collabora/default.nix | 25 ++++++ .../apps/collabora/options.nix | 22 +---- .../apps/dashy/default.nix | 0 .../apps/jellyfin/default.nix | 59 +------------ modules/apps/jellyfin/options.nix | 58 +++++++++++++ modules/apps/jellyseerr/default.nix | 25 ++++++ .../apps/jellyseerr/options.nix | 24 +----- modules/apps/mariadb/default.nix | 29 +++++++ .../apps/mariadb/options.nix | 27 +----- modules/apps/nextcloud/default.nix | 26 ++++++ .../apps/nextcloud/options.nix | 26 +----- modules/apps/radarr/default.nix | 27 ++++++ .../apps/radarr/options.nix | 25 +----- modules/apps/sabnzbd/default.nix | 29 +++++++ .../apps/sabnzbd/options.nix | 26 +----- modules/apps/sonarr/default.nix | 27 ++++++ .../apps/sonarr/options.nix | 25 +----- modules/apps/swag/default.nix | 35 ++++++++ .../swag.nix => modules/apps/swag/options.nix | 33 +------- modules/default.nix | 16 ++++ modules/samba/default.nix | 67 +++++++++++++++ modules/samba/options.nix | 70 ++++++++++++++++ nas-apps/nas-apps.nix | 16 ---- nas-apps/vscode.nix | 20 ----- nas-samba/samba.nix | 83 ------------------- 30 files changed, 560 insertions(+), 447 deletions(-) create mode 100644 hosts/default.nix create mode 100644 modules/apps/collabora/default.nix rename nas-apps/collabora.nix => modules/apps/collabora/options.nix (61%) rename nas-apps/dashy.nix => modules/apps/dashy/default.nix (100%) rename nas-apps/jellyfin.nix => modules/apps/jellyfin/default.nix (66%) create mode 100644 modules/apps/jellyfin/options.nix create mode 100644 modules/apps/jellyseerr/default.nix rename nas-apps/jellyseerr.nix => modules/apps/jellyseerr/options.nix (64%) create mode 100644 modules/apps/mariadb/default.nix rename nas-apps/mariadb.nix => modules/apps/mariadb/options.nix (64%) create mode 100644 modules/apps/nextcloud/default.nix rename nas-apps/nextcloud.nix => modules/apps/nextcloud/options.nix (65%) create mode 100644 modules/apps/radarr/default.nix rename nas-apps/radarr.nix => modules/apps/radarr/options.nix (65%) create mode 100644 modules/apps/sabnzbd/default.nix rename nas-apps/sabnzbd.nix => modules/apps/sabnzbd/options.nix (66%) create mode 100644 modules/apps/sonarr/default.nix rename nas-apps/sonarr.nix => modules/apps/sonarr/options.nix (65%) create mode 100644 modules/apps/swag/default.nix rename nas-apps/swag.nix => modules/apps/swag/options.nix (61%) create mode 100644 modules/default.nix create mode 100644 modules/samba/default.nix create mode 100644 modules/samba/options.nix delete mode 100644 nas-apps/nas-apps.nix delete mode 100644 nas-apps/vscode.nix delete mode 100644 nas-samba/samba.nix diff --git a/flake.nix b/flake.nix index 73b7dc8..fe1617a 100644 --- a/flake.nix +++ b/flake.nix @@ -30,13 +30,13 @@ lanzaboote.nixosModules.lanzaboote kde.nixosModules.plasma6 nix-flatpak.nixosModules.nix-flatpak - ./configuration.nix - ./impermanence.nix + ./hosts/desktop/configuration.nix + ./hosts/desktop/impermanence.nix home-manager.nixosModules.home-manager { home-manager.useGlobalPkgs = true; home-manager.useUserPackages = true; - home-manager.users.matt = import ./home.nix; + home-manager.users.matt = import ./hosts/desktop/home.nix; } ]; }; @@ -46,7 +46,7 @@ system = "aarch64-linux"; modules = [ nixos-hardware.nixosModules.raspberry-pi-4 - ./configuration-pi4.nix + ./hosts/pi4/configuration.nix ]; }; }; diff --git a/hosts/default.nix b/hosts/default.nix new file mode 100644 index 0000000..6bef595 --- /dev/null +++ b/hosts/default.nix @@ -0,0 +1,62 @@ +{ config, lib, pkgs, ... }: +let + timezone = "America/Chicago"; +in +{ + imports = + [ + ../modules + ]; + + # Enable nix flakes and nix-command tools + nix.settings.experimental-features = [ "nix-command" "flakes" ]; + + # Hardware configs + hardware = { + # Bluetooth + bluetooth.enable = true; + + # Enable all firmware + enableAllFirmware = true; + + # Disable pulse audio in favor of pipewire + pulseaudio.enable = false; + }; + + # Services configs + services = { + openssh.enable = true; + + # Enable firmware updates + fwupd.enable = true; + + # Enable CUPS to print documents. + printing.enable = true; + + # configure pipewire + pipewire = { + enable = true; + alsa.enable = true; + alsa.support32Bit = true; + pulse.enable = true; + }; + }; + + # Time config + time = { + # Set your time zone. + timeZone = timezone; + }; + + boot = { + # Enable AppImage + binfmt.registrations.appimage = { + wrapInterpreterInShell = false; + interpreter = "${pkgs.appimage-run}/bin/appimage-run"; + recognitionType = "magic"; + offset = 0; + mask = ''\xff\xff\xff\xff\x00\x00\x00\x00\xff\xff\xff''; + magicOrExtension = ''\x7fELF....AI\x02''; + }; + }; +} \ No newline at end of file diff --git a/hosts/desktop/configuration.nix b/hosts/desktop/configuration.nix index 85b6ef6..4521a8e 100644 --- a/hosts/desktop/configuration.nix +++ b/hosts/desktop/configuration.nix @@ -7,7 +7,6 @@ let user = "matt"; password = "$y$j9T$EkPXmsmIMFFZ.WRrBYCxS1$P0kwo6e4.WM5DsqUcEqWC3MrZp5KfCjxffraMFZWu06"; hostname = "matt-nixos"; - timezone = "America/Chicago"; # discover-wrapper is needed as of 1/24/24 since PackageKit does not work correctly so this removes error messages. discover-wrapped = pkgs.symlinkJoin { @@ -23,12 +22,10 @@ in imports = [ # Include the results of the hardware scan. ./hardware-configuration.nix - ./cachix/cachix.nix + ../../cachix/cachix.nix + ../default.nix ]; - # Enable nix flakes and nix-command tools - nix.settings.experimental-features = [ "nix-command" "flakes" ]; - # Configure bootloader with lanzaboot and secureboot boot = { loader = { @@ -65,34 +62,15 @@ in # Network option required using sysctl to let Ubisoft Connect work as of 7-12-2023 kernel.sysctl."net.ipv4.tcp_mtu_probing" = 1; - - # Enable AppImage - binfmt.registrations.appimage = { - wrapInterpreterInShell = false; - interpreter = "${pkgs.appimage-run}/bin/appimage-run"; - recognitionType = "magic"; - offset = 0; - mask = ''\xff\xff\xff\xff\x00\x00\x00\x00\xff\xff\xff''; - magicOrExtension = ''\x7fELF....AI\x02''; - }; }; # Hardware configs hardware = { - # Bluetooth - bluetooth.enable = true; - # Xbox controllers xpadneo.enable = true; # Steam udev rules for remote play steam-hardware.enable = true; - - # Enable all firmware - enableAllFirmware = true; - - # Disable pulse audio in favor of pipewire - pulseaudio.enable = false; opengl.enable = true; # Enables support for 32bit libs that steam uses @@ -101,9 +79,6 @@ in # Services configs services = { - # Enable firmware updates - fwupd.enable = true; - # Enable the X11 windowing system. xserver = { enable = true; @@ -115,17 +90,6 @@ in }; desktopManager.plasma6.enable = true; }; - - # Enable CUPS to print documents. - printing.enable = true; - - # configure pipewire - pipewire = { - enable = true; - alsa.enable = true; - alsa.support32Bit = true; - pulse.enable = true; - }; # enable auto discovery of printers avahi = { @@ -161,6 +125,7 @@ in fi ''; wantedBy = [ "multi-user.target" ]; + after = [ "NetworkManager.target" ]; }; # Networking configs @@ -173,8 +138,6 @@ in # Time config time = { - # Set your time zone. - timeZone = timezone; hardwareClockInLocalTime = true; }; diff --git a/hosts/nas/configuration.nix b/hosts/nas/configuration.nix index 5770947..ed2a982 100644 --- a/hosts/nas/configuration.nix +++ b/hosts/nas/configuration.nix @@ -7,19 +7,14 @@ let user = "admin"; password = "$y$j9T$EkPXmsmIMFFZ.WRrBYCxS1$P0kwo6e4.WM5DsqUcEqWC3MrZp5KfCjxffraMFZWu06"; hostname = "jallen-nas"; - timezone = "America/Chicago"; in { imports = [ # Include the results of the hardware scan. ./hardware-configuration.nix - ../../nas-samba/samba.nix - ../../nas-apps/nas-apps.nix + ../default.nix ]; - # Enable nix flakes and nix-command tools - nix.settings.experimental-features = [ "nix-command" "flakes" ]; - nas-apps = { jellyfin.enable = true; @@ -44,6 +39,38 @@ in swag.enable = true; }; + nas-samba = { + enable = true; + hostsAllow = "10.0.1."; + enableTimeMachine = true; + timeMachinePath = "/mnt/mainpool/TimeMachine"; + + shares = { + "3d_printer" = { + public = true; + sharePath = "/mnt/mainpool/3d_printer"; + }; + Backup = { + public = true; + sharePath = "/mnt/mainpool/Backup"; + }; + Documents = { + public = true; + sharePath = "/mnt/mainpool/Documents"; + }; + isos = { + public = true; + sharePath = "/mnt/mainpool/isos"; + }; + TimeMachine = { + public = true; + sharePath = "/mnt/mainpool/TimeMachine"; + enableTimeMachine = true; + timeMachineMaxSize = "1T"; + }; + }; + }; + # Configure bootloader with lanzaboot and secureboot boot = { loader = { @@ -76,15 +103,6 @@ in # Hardware configs hardware = { - # Bluetooth - bluetooth.enable = true; - - # Enable all firmware - enableAllFirmware = true; - - # Disable pulse audio in favor of pipewire - pulseaudio.enable = false; - # Nvidia nvidia = { package = config.boot.kernelPackages.nvidiaPackages.beta; @@ -123,11 +141,6 @@ in # Services configs services = { - openssh.enable = true; - - # Enable firmware updates - fwupd.enable = true; - # Enable the X11 windowing system. xserver = { enable = true; @@ -142,17 +155,6 @@ in }; desktopManager.plasma5.enable = true; }; - - # Enable CUPS to print documents. - printing.enable = true; - - # configure pipewire - pipewire = { - enable = true; - alsa.enable = true; - alsa.support32Bit = true; - pulse.enable = true; - }; # Set to enable Flatpak flatpak.enable = false; @@ -237,12 +239,6 @@ in }; }; - # Time config - time = { - # Set your time zone. - timeZone = timezone; - }; - # Configure environment environment = { # List packages installed in system profile. To search, run: diff --git a/hosts/pi4/configuration.nix b/hosts/pi4/configuration.nix index f411158..5d487b4 100644 --- a/hosts/pi4/configuration.nix +++ b/hosts/pi4/configuration.nix @@ -15,7 +15,7 @@ let in { imports = [ # Include the results of the hardware scan. - ./hardware-configuration-pi4.nix + ./hardware-configuration.nix ./docker-pi4.nix ]; @@ -32,7 +32,7 @@ in { }; # Set your time zone. - time.timeZone = "America/Chicago"; + time.timeZone = timezone; networking = { hostName = hostname; diff --git a/modules/apps/collabora/default.nix b/modules/apps/collabora/default.nix new file mode 100644 index 0000000..4511412 --- /dev/null +++ b/modules/apps/collabora/default.nix @@ -0,0 +1,25 @@ +{ lib, pkgs, config, ... }: +with lib; +let + cfg = config.nas-apps.collabora; +in { + imports = [ + ./options.nix + ]; + + config = mkIf cfg.enable { + virtualisation.oci-containers.containers."${cfg.name}" = { + autoStart = cfg.autoStart; + image = cfg.image; + ports = [ "${cfg.port}:9980" ]; + volumes = [ + # ... + ]; + environment = { + PUID = cfg.puid; + PGID = cfg.pgid; + TZ = cfg.timeZone; + }; + }; + }; +} diff --git a/nas-apps/collabora.nix b/modules/apps/collabora/options.nix similarity index 61% rename from nas-apps/collabora.nix rename to modules/apps/collabora/options.nix index 83e1c0e..abcf2e5 100644 --- a/nas-apps/collabora.nix +++ b/modules/apps/collabora/options.nix @@ -1,8 +1,6 @@ -{ lib, pkgs, config, ... }: +{ lib, ... }: with lib; -let - cfg = config.nas-apps.collabora; -in { +{ options.nas-apps.collabora = { enable = mkEnableOption "collabora docker service"; @@ -42,20 +40,4 @@ in { }; }; - - config = mkIf cfg.enable { - virtualisation.oci-containers.containers."${cfg.name}" = { - autoStart = cfg.autoStart; - image = cfg.image; - ports = [ "${cfg.port}:9980" ]; - volumes = [ - # ... - ]; - environment = { - PUID = cfg.puid; - PGID = cfg.pgid; - TZ = cfg.timeZone; - }; - }; - }; } diff --git a/nas-apps/dashy.nix b/modules/apps/dashy/default.nix similarity index 100% rename from nas-apps/dashy.nix rename to modules/apps/dashy/default.nix diff --git a/nas-apps/jellyfin.nix b/modules/apps/jellyfin/default.nix similarity index 66% rename from nas-apps/jellyfin.nix rename to modules/apps/jellyfin/default.nix index 7cdb846..6d08dbc 100644 --- a/nas-apps/jellyfin.nix +++ b/modules/apps/jellyfin/default.nix @@ -3,61 +3,10 @@ with lib; let cfg = config.nas-apps.jellyfin; in { - options.nas-apps.jellyfin = { - enable = mkEnableOption "jellyfin docker service"; - - autoStart = mkOption { - type = types.bool; - default = true; - }; - - port = mkOption { - type = types.str; - default = "8096"; - }; - - name = mkOption { - type = types.str; - default = "jellyfin"; - }; - - image = mkOption { - type = types.str; - default = "lscr.io/linuxserver/jellyfin"; - }; - - configPath = mkOption { - type = types.str; - default = "/mnt/ssd/nix-app-data/jellyfin"; - }; - - moviesPath = mkOption { - type = types.str; - default = "/mnt/mainpool/Movies"; - }; - - tvPath = mkOption { - type = types.str; - default = "/mnt/mainpool/Tv"; - }; - - puid = mkOption { - type = types.str; - default = "911"; - }; - - pgid = mkOption { - type = types.str; - default = "1000"; - }; - - timeZone = mkOption { - type = types.str; - default = "America/Chicago"; - }; - - }; - + imports = [ + ./options.nix + ]; + config = mkIf cfg.enable { systemd.services.jellyfin-nvidia-docker = { diff --git a/modules/apps/jellyfin/options.nix b/modules/apps/jellyfin/options.nix new file mode 100644 index 0000000..74ced54 --- /dev/null +++ b/modules/apps/jellyfin/options.nix @@ -0,0 +1,58 @@ +{ lib, ... }: +with lib; +{ + options.nas-apps.jellyfin = { + enable = mkEnableOption "jellyfin docker service"; + + autoStart = mkOption { + type = types.bool; + default = true; + }; + + port = mkOption { + type = types.str; + default = "8096"; + }; + + name = mkOption { + type = types.str; + default = "jellyfin"; + }; + + image = mkOption { + type = types.str; + default = "lscr.io/linuxserver/jellyfin"; + }; + + configPath = mkOption { + type = types.str; + default = "/mnt/ssd/nix-app-data/jellyfin"; + }; + + moviesPath = mkOption { + type = types.str; + default = "/mnt/mainpool/Movies"; + }; + + tvPath = mkOption { + type = types.str; + default = "/mnt/mainpool/Tv"; + }; + + puid = mkOption { + type = types.str; + default = "911"; + }; + + pgid = mkOption { + type = types.str; + default = "1000"; + }; + + timeZone = mkOption { + type = types.str; + default = "America/Chicago"; + }; + + }; +} \ No newline at end of file diff --git a/modules/apps/jellyseerr/default.nix b/modules/apps/jellyseerr/default.nix new file mode 100644 index 0000000..d41a704 --- /dev/null +++ b/modules/apps/jellyseerr/default.nix @@ -0,0 +1,25 @@ +{ lib, pkgs, config, ... }: +with lib; +let + cfg = config.nas-apps.jellyseerr; +in { + imports = [ + ./options.nix + ]; + + config = mkIf cfg.enable { + virtualisation.oci-containers.containers."${cfg.name}" = { + autoStart = cfg.autoStart; + image = cfg.image; + ports = [ "${cfg.port}:5055" ]; + volumes = [ + "${cfg.configPath}:/config" + ]; + environment = { + PUID = cfg.puid; + PGID = cfg.pgid; + TZ = cfg.timeZone; + }; + }; + }; +} diff --git a/nas-apps/jellyseerr.nix b/modules/apps/jellyseerr/options.nix similarity index 64% rename from nas-apps/jellyseerr.nix rename to modules/apps/jellyseerr/options.nix index 39cf566..879fc89 100644 --- a/nas-apps/jellyseerr.nix +++ b/modules/apps/jellyseerr/options.nix @@ -1,8 +1,6 @@ -{ lib, pkgs, config, ... }: +{ lib, ... }: with lib; -let - cfg = config.nas-apps.jellyseerr; -in { +{ options.nas-apps.jellyseerr = { enable = mkEnableOption "jellyseerr docker service"; @@ -47,20 +45,4 @@ in { }; }; - - config = mkIf cfg.enable { - virtualisation.oci-containers.containers."${cfg.name}" = { - autoStart = cfg.autoStart; - image = cfg.image; - ports = [ "${cfg.port}:5055" ]; - volumes = [ - "${cfg.configPath}:/config" - ]; - environment = { - PUID = cfg.puid; - PGID = cfg.pgid; - TZ = cfg.timeZone; - }; - }; - }; -} +} \ No newline at end of file diff --git a/modules/apps/mariadb/default.nix b/modules/apps/mariadb/default.nix new file mode 100644 index 0000000..de7d519 --- /dev/null +++ b/modules/apps/mariadb/default.nix @@ -0,0 +1,29 @@ +{ lib, pkgs, config, ... }: +with lib; +let + cfg = config.nas-apps.mariadb; +in { + imports = [ + ./options.nix + ]; + + config = mkIf cfg.enable { + virtualisation.oci-containers.containers."${cfg.name}" = { + autoStart = cfg.autoStart; + image = cfg.image; + ports = [ "${cfg.port}:3306" ]; + volumes = [ + "${cfg.configPath}:/config" + ]; + environment = { + PUID = cfg.puid; + PGID = cfg.pgid; + TZ = cfg.timeZone; + MYSQL_ROOT_PASSWORD = cfg.rootPassword; + MYSQL_DATABASE = cfg.databaseName; + MYSQL_USER = cfg.databaseUser; + MYSQL_PASSWORD = cfg.databasePassword; + }; + }; + }; +} diff --git a/nas-apps/mariadb.nix b/modules/apps/mariadb/options.nix similarity index 64% rename from nas-apps/mariadb.nix rename to modules/apps/mariadb/options.nix index 65b64a6..cd1b808 100644 --- a/nas-apps/mariadb.nix +++ b/modules/apps/mariadb/options.nix @@ -1,8 +1,6 @@ -{ lib, pkgs, config, ... }: +{ lib, ... }: with lib; -let - cfg = config.nas-apps.mariadb; -in { +{ options.nas-apps.mariadb = { enable = mkEnableOption "mariadb docker service"; @@ -65,26 +63,5 @@ in { type = types.str; default = "BogieDudie1"; }; - - }; - - config = mkIf cfg.enable { - virtualisation.oci-containers.containers."${cfg.name}" = { - autoStart = cfg.autoStart; - image = cfg.image; - ports = [ "${cfg.port}:3306" ]; - volumes = [ - "${cfg.configPath}:/config" - ]; - environment = { - PUID = cfg.puid; - PGID = cfg.pgid; - TZ = cfg.timeZone; - MYSQL_ROOT_PASSWORD = cfg.rootPassword; - MYSQL_DATABASE = cfg.databaseName; - MYSQL_USER = cfg.databaseUser; - MYSQL_PASSWORD = cfg.databasePassword; - }; - }; }; } diff --git a/modules/apps/nextcloud/default.nix b/modules/apps/nextcloud/default.nix new file mode 100644 index 0000000..ae02580 --- /dev/null +++ b/modules/apps/nextcloud/default.nix @@ -0,0 +1,26 @@ +{ lib, pkgs, config, ... }: +with lib; +let + cfg = config.nas-apps.nextcloud; +in { + imports = [ + ./options.nix + ]; + + config = mkIf cfg.enable { + virtualisation.oci-containers.containers."${cfg.name}" = { + autoStart = cfg.autoStart; + image = cfg.image; + ports = [ "${cfg.httpPort}:80" "${cfg.httpsPort}:443" ]; + volumes = [ + "${cfg.configPath}:/config" + "${cfg.dataPath}:/data" + ]; + environment = { + PUID = cfg.puid; + PGID = cfg.pgid; + TZ = cfg.timeZone; + }; + }; + }; +} diff --git a/nas-apps/nextcloud.nix b/modules/apps/nextcloud/options.nix similarity index 65% rename from nas-apps/nextcloud.nix rename to modules/apps/nextcloud/options.nix index ef0d669..902e188 100644 --- a/nas-apps/nextcloud.nix +++ b/modules/apps/nextcloud/options.nix @@ -1,8 +1,6 @@ -{ lib, pkgs, config, ... }: +{ lib, ... }: with lib; -let - cfg = config.nas-apps.nextcloud; -in { +{ options.nas-apps.nextcloud = { enable = mkEnableOption "nextcloud docker service"; @@ -55,23 +53,5 @@ in { type = types.str; default = "America/Chicago"; }; - }; - - config = mkIf cfg.enable { - virtualisation.oci-containers.containers."${cfg.name}" = { - autoStart = cfg.autoStart; - image = cfg.image; - ports = [ "${cfg.httpPort}:80" "${cfg.httpsPort}:443" ]; - volumes = [ - "${cfg.configPath}:/config" - "${cfg.dataPath}:/data" - ]; - environment = { - PUID = cfg.puid; - PGID = cfg.pgid; - TZ = cfg.timeZone; - }; - }; - }; -} +} \ No newline at end of file diff --git a/modules/apps/radarr/default.nix b/modules/apps/radarr/default.nix new file mode 100644 index 0000000..186bb27 --- /dev/null +++ b/modules/apps/radarr/default.nix @@ -0,0 +1,27 @@ +{ lib, pkgs, config, ... }: +with lib; +let + cfg = config.nas-apps.radarr; +in { + imports = [ + ./options.nix + ]; + + config = mkIf cfg.enable { + virtualisation.oci-containers.containers."${cfg.name}" = { + autoStart = cfg.autoStart; + image = cfg.image; + ports = [ "${cfg.port}:7878" ]; + volumes = [ + "${cfg.configPath}:/config" + "${cfg.moviesPath}:/movies" + "${cfg.downloadsPath}:/downloads" + ]; + environment = { + PUID = cfg.puid; + PGID = cfg.pgid; + TZ = cfg.timeZone; + }; + }; + }; +} diff --git a/nas-apps/radarr.nix b/modules/apps/radarr/options.nix similarity index 65% rename from nas-apps/radarr.nix rename to modules/apps/radarr/options.nix index 2c6beed..1dbf029 100644 --- a/nas-apps/radarr.nix +++ b/modules/apps/radarr/options.nix @@ -1,8 +1,6 @@ -{ lib, pkgs, config, ... }: +{ lib, ... }: with lib; -let - cfg = config.nas-apps.radarr; -in { +{ options.nas-apps.radarr = { enable = mkEnableOption "radarr docker service"; @@ -55,24 +53,5 @@ in { type = types.str; default = "America/Chicago"; }; - - }; - - config = mkIf cfg.enable { - virtualisation.oci-containers.containers."${cfg.name}" = { - autoStart = cfg.autoStart; - image = cfg.image; - ports = [ "${cfg.port}:7878" ]; - volumes = [ - "${cfg.configPath}:/config" - "${cfg.moviesPath}:/movies" - "${cfg.downloadsPath}:/downloads" - ]; - environment = { - PUID = cfg.puid; - PGID = cfg.pgid; - TZ = cfg.timeZone; - }; - }; }; } diff --git a/modules/apps/sabnzbd/default.nix b/modules/apps/sabnzbd/default.nix new file mode 100644 index 0000000..82de91d --- /dev/null +++ b/modules/apps/sabnzbd/default.nix @@ -0,0 +1,29 @@ +{ lib, pkgs, config, ... }: +with lib; +let + cfg = config.nas-apps.sabnzbd; +in { + imports = [ + ./options.nix + ]; + + config = mkIf cfg.enable { + virtualisation.oci-containers.containers."${cfg.name}" = { + autoStart = cfg.autoStart; + image = cfg.image; + ports = [ "${cfg.port}:8080" ]; + volumes = [ + "${cfg.configPath}:/config" + "${cfg.moviesPath}:/movies" + "${cfg.tvPath}:/tv" + "${cfg.downloadsPath}:/downloads" + "${cfg.downloadsIncompletePath}:/downloads-incomplete" + ]; + environment = { + PUID = cfg.puid; + PGID = cfg.pgid; + TZ = cfg.timeZone; + }; + }; + }; +} diff --git a/nas-apps/sabnzbd.nix b/modules/apps/sabnzbd/options.nix similarity index 66% rename from nas-apps/sabnzbd.nix rename to modules/apps/sabnzbd/options.nix index 67d298d..6e93cd6 100644 --- a/nas-apps/sabnzbd.nix +++ b/modules/apps/sabnzbd/options.nix @@ -1,8 +1,6 @@ -{ lib, pkgs, config, ... }: +{ lib, ... }: with lib; -let - cfg = config.nas-apps.sabnzbd; -in { +{ options.nas-apps.sabnzbd = { enable = mkEnableOption "sabnzbd docker service"; @@ -67,24 +65,4 @@ in { }; }; - - config = mkIf cfg.enable { - virtualisation.oci-containers.containers."${cfg.name}" = { - autoStart = cfg.autoStart; - image = cfg.image; - ports = [ "${cfg.port}:8080" ]; - volumes = [ - "${cfg.configPath}:/config" - "${cfg.moviesPath}:/movies" - "${cfg.tvPath}:/tv" - "${cfg.downloadsPath}:/downloads" - "${cfg.downloadsIncompletePath}:/downloads-incomplete" - ]; - environment = { - PUID = cfg.puid; - PGID = cfg.pgid; - TZ = cfg.timeZone; - }; - }; - }; } diff --git a/modules/apps/sonarr/default.nix b/modules/apps/sonarr/default.nix new file mode 100644 index 0000000..85a3c77 --- /dev/null +++ b/modules/apps/sonarr/default.nix @@ -0,0 +1,27 @@ +{ lib, pkgs, config, ... }: +with lib; +let + cfg = config.nas-apps.sonarr; +in { + imports = [ + ./options.nix + ]; + + config = mkIf cfg.enable { + virtualisation.oci-containers.containers."${cfg.name}" = { + autoStart = cfg.autoStart; + image = cfg.image; + ports = [ "${cfg.port}:8989" ]; + volumes = [ + "${cfg.configPath}:/config" + "${cfg.tvPath}:/tv" + "${cfg.downloadsPath}:/downloads" + ]; + environment = { + PUID = cfg.puid; + PGID = cfg.pgid; + TZ = cfg.timeZone; + }; + }; + }; +} diff --git a/nas-apps/sonarr.nix b/modules/apps/sonarr/options.nix similarity index 65% rename from nas-apps/sonarr.nix rename to modules/apps/sonarr/options.nix index ae81b28..8ee984c 100644 --- a/nas-apps/sonarr.nix +++ b/modules/apps/sonarr/options.nix @@ -1,8 +1,6 @@ -{ lib, pkgs, config, ... }: +{lib, ... }: with lib; -let - cfg = config.nas-apps.sonarr; -in { +{ options.nas-apps.sonarr = { enable = mkEnableOption "sonarr docker service"; @@ -55,24 +53,5 @@ in { type = types.str; default = "America/Chicago"; }; - - }; - - config = mkIf cfg.enable { - virtualisation.oci-containers.containers."${cfg.name}" = { - autoStart = cfg.autoStart; - image = cfg.image; - ports = [ "${cfg.port}:8989" ]; - volumes = [ - "${cfg.configPath}:/config" - "${cfg.tvPath}:/tv" - "${cfg.downloadsPath}:/downloads" - ]; - environment = { - PUID = cfg.puid; - PGID = cfg.pgid; - TZ = cfg.timeZone; - }; - }; }; } diff --git a/modules/apps/swag/default.nix b/modules/apps/swag/default.nix new file mode 100644 index 0000000..c6fc1b0 --- /dev/null +++ b/modules/apps/swag/default.nix @@ -0,0 +1,35 @@ +{ lib, pkgs, config, ... }: +with lib; +let + cfg = config.nas-apps.swag; +in { + imports = [ + ./options.nix + ]; + + config = mkIf cfg.enable { + + networking.firewall = { + allowedTCPPorts = [ cfg.httpPort cfg.httpsPort ]; + allowedUDPPorts = [ cfg.httpPort cfg.httpsPort ]; + }; + + virtualisation.oci-containers.containers."${cfg.name}" = { + autoStart = cfg.autoStart; + image = cfg.image; + ports = [ "${toString cfg.httpPort}:80" "${toString cfg.httpsPort}:443" ]; + volumes = [ + "${cfg.configPath}:/config" + ]; + environment = { + PUID = cfg.puid; + PGID = cfg.pgid; + TZ = cfg.timeZone; + EMAIL = cfg.email; + URL = cfg.url; + VALIDATION = cfg.validation; + SUBDOMAINS = cfg.subdomains; + }; + }; + }; +} diff --git a/nas-apps/swag.nix b/modules/apps/swag/options.nix similarity index 61% rename from nas-apps/swag.nix rename to modules/apps/swag/options.nix index 858d07b..16edc52 100644 --- a/nas-apps/swag.nix +++ b/modules/apps/swag/options.nix @@ -1,8 +1,6 @@ -{ lib, pkgs, config, ... }: +{lib, ... }: with lib; -let - cfg = config.nas-apps.swag; -in { +{ options.nas-apps.swag = { enable = mkEnableOption "swag docker service"; @@ -70,32 +68,5 @@ in { type = types.str; default = "jellyfin,hass,cloud,office,jellyseerr"; }; - - }; - - config = mkIf cfg.enable { - - networking.firewall = { - allowedTCPPorts = [ cfg.httpPort cfg.httpsPort ]; - allowedUDPPorts = [ cfg.httpPort cfg.httpsPort ]; - }; - - virtualisation.oci-containers.containers."${cfg.name}" = { - autoStart = cfg.autoStart; - image = cfg.image; - ports = [ "${toString cfg.httpPort}:80" "${toString cfg.httpsPort}:443" ]; - volumes = [ - "${cfg.configPath}:/config" - ]; - environment = { - PUID = cfg.puid; - PGID = cfg.pgid; - TZ = cfg.timeZone; - EMAIL = cfg.email; - URL = cfg.url; - VALIDATION = cfg.validation; - SUBDOMAINS = cfg.subdomains; - }; - }; }; } diff --git a/modules/default.nix b/modules/default.nix new file mode 100644 index 0000000..2274051 --- /dev/null +++ b/modules/default.nix @@ -0,0 +1,16 @@ +{ ... }: +{ + imports = [ + ./samba + ./apps/collabora + ./apps/dashy + ./apps/jellyfin + ./apps/jellyseerr + ./apps/mariadb + ./apps/nextcloud + ./apps/radarr + ./apps/sabnzbd + ./apps/sonarr + ./apps/swag + ]; +} \ No newline at end of file diff --git a/modules/samba/default.nix b/modules/samba/default.nix new file mode 100644 index 0000000..961a8e7 --- /dev/null +++ b/modules/samba/default.nix @@ -0,0 +1,67 @@ +{ lib, pkgs, config, ... }: +with lib; +let + cfg = config.nas-samba; +in { + imports = [ + ./options.nix + ]; + + config = mkIf cfg.enable { + # make shares visible for Windows clients + services.samba-wsdd = { + enable = true; + openFirewall = true; + }; + + services.netatalk = { + enable = cfg.enableTimeMachine; + settings = { + time-machine = { + path = cfg.timeMachinePath; + "valid users" = "whoever"; + "time machine" = cfg.enableTimeMachine; + }; + }; + }; + + services.samba = { + enable = true; + securityType = "user"; + openFirewall = true; + extraConfig = '' + workgroup = WORKGROUP + server string = smbnix + netbios name = smbnix + security = user + #use sendfile = yes + #max protocol = smb2 + # note: localhost is the ipv6 localhost ::1 + hosts allow = ${cfg.hostsAllow} 127.0.0.1 localhost + hosts deny = 0.0.0.0/0 + guest account = nobody + map to guest = bad user + ''; + shares = + let + make = name: share: nameValuePair "${name}" + { + path = share.sharePath; + public = if share.enableTimeMachine then false else share.public; + private = if !share.public || share.enableTimeMachine then "yes" else "no"; + browseable = if share.browseable then "yes" else "no"; + writable = "yes"; + "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; + "fruit:aapl" = if share.enableTimeMachine then "yes" else "no"; + "fruit:time machine" = if share.enableTimeMachine then "yes" else "no"; + "vfs objects" = "catia fruit streams_xattr"; + "fruit:time machine max size" = share.timeMachineMaxSize; + }; + in + mapAttrs' make cfg.shares; + }; + }; +} diff --git a/modules/samba/options.nix b/modules/samba/options.nix new file mode 100644 index 0000000..c3cd04f --- /dev/null +++ b/modules/samba/options.nix @@ -0,0 +1,70 @@ +{ lib, ... }: +with lib; +{ + options.nas-samba = { + enable = mkEnableOption "nas samba service"; + + autoStart = mkOption { + type = types.bool; + default = true; + }; + enableTimeMachine = mkOption { + type = types.bool; + default = false; + }; + timeMachinePath = mkOption { + type = types.str; + default = ""; + }; + hostsAllow = mkOption { + type = types.str; + default = ""; + }; + + shares = mkOption { + type = types.attrsOf (types.submodule + { + options = { + public = mkOption { + type = types.bool; + default = false; + }; + sharePath = mkOption { + type = types.str; + default = ""; + }; + readOnly = mkOption { + type = types.bool; + default = false; + }; + browseable = mkOption { + type = types.bool; + default = true; + }; + guestOk = mkOption { + type = types.bool; + default = true; + }; + createMask = mkOption { + type = types.str; + default = "0644"; + }; + directoryMask = mkOption { + type = types.str; + default = "0755"; + }; + enableTimeMachine = mkOption { + type = types.bool; + default = false; + }; + timeMachineMaxSize = mkOption { + type = types.str; + default = "0K"; + }; + }; + } + ); + default = { }; + }; + }; +} diff --git a/nas-apps/nas-apps.nix b/nas-apps/nas-apps.nix deleted file mode 100644 index 50669d4..0000000 --- a/nas-apps/nas-apps.nix +++ /dev/null @@ -1,16 +0,0 @@ -{ ... }: -{ - imports = - [ - ./swag.nix - ./jellyfin.nix - ./sonarr.nix - ./radarr.nix - ./sabnzbd.nix - ./mariadb.nix - ./nextcloud.nix - ./collabora.nix - ./jellyseerr.nix - # ./dashy.nix - ]; -} \ No newline at end of file diff --git a/nas-apps/vscode.nix b/nas-apps/vscode.nix deleted file mode 100644 index 8e1e7a7..0000000 --- a/nas-apps/vscode.nix +++ /dev/null @@ -1,20 +0,0 @@ -{ config, pkgs, ... }: -{ - environment.systemPackages = with pkgs; [ - (vscode-with-extensions.override { - vscodeExtensions = with vscode-extensions; [ - bbenoist.nix - ms-python.python - ms-azuretools.vscode-docker - ms-vscode-remote.remote-ssh - ] ++ pkgs.vscode-utils.extensionsFromVscodeMarketplace [ - { - name = "remote-ssh-edit"; - publisher = "ms-vscode-remote"; - version = "0.47.2"; - sha256 = "1hp6gjh4xp2m1xlm1jsdzxw9d8frkiidhph6nvl24d0h8z34w49g"; - } - ]; - }) - ]; -} diff --git a/nas-samba/samba.nix b/nas-samba/samba.nix deleted file mode 100644 index 2d8c976..0000000 --- a/nas-samba/samba.nix +++ /dev/null @@ -1,83 +0,0 @@ -{ config, ... }: -{ - # make shares visible for Windows clients - services.samba-wsdd = { - enable = true; - openFirewall = true; - }; - - services.samba = { - enable = true; - securityType = "user"; - openFirewall = true; - extraConfig = '' - workgroup = WORKGROUP - server string = smbnix - netbios name = smbnix - security = user - #use sendfile = yes - #max protocol = smb2 - # note: localhost is the ipv6 localhost ::1 - hosts allow = 10.0.1. 127.0.0.1 localhost - hosts deny = 0.0.0.0/0 - guest account = nobody - map to guest = bad user - ''; - shares = { - "3d_printer" = { - path = "/mnt/mainpool/3d_printer"; - browseable = "yes"; - "read only" = "no"; - "guest ok" = "yes"; - "create mask" = "0644"; - "directory mask" = "0755"; - }; - Backup = { - path = "/mnt/mainpool/Backup"; - browseable = "yes"; - "read only" = "no"; - "guest ok" = "yes"; - "create mask" = "0644"; - "directory mask" = "0755"; - }; - Documents = { - path = "/mnt/mainpool/Documents"; - browseable = "yes"; - "read only" = "no"; - "guest ok" = "yes"; - "create mask" = "0644"; - "directory mask" = "0755"; - }; - isos = { - path = "/mnt/mainpool/isos"; - browseable = "yes"; - "read only" = "no"; - "guest ok" = "yes"; - "create mask" = "0644"; - "directory mask" = "0755"; - }; - TimeMachine = { - path = "/mnt/mainpool/TimeMachine"; - public = "no"; - private = "yes"; - browseable = "yes"; - writable = "yes"; - "fruit:aapl" = "yes"; - "fruit:time machine" = "yes"; - "vfs objects" = "catia fruit streams_xattr"; - "fruit:time machine max size" = "1T"; - }; - }; - }; - - services.netatalk = { - enable = true; - settings = { - time-machine = { - path = "/mnt/mainpool/TimeMachine"; - "valid users" = "whoever"; - "time machine" = true; - }; - }; - }; -}