From 1e99bf8f1c33e77c6aa5a5a4d128b71b4a8e53f1 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Fri, 4 Jul 2025 09:21:44 +0300 Subject: feat(machines/marduk): Split configuration into multiple files and make code more generic --- machines/marduk/configuration.nix | 65 ++++++++++++--------------------------- machines/marduk/httpd.nix | 40 ++++++++++++++++++++++++ machines/marduk/mail.nix | 40 ++++++++++++++++++++++++ 3 files changed, 100 insertions(+), 45 deletions(-) create mode 100644 machines/marduk/httpd.nix create mode 100644 machines/marduk/mail.nix diff --git a/machines/marduk/configuration.nix b/machines/marduk/configuration.nix index 7a72ffd..d9dfc23 100644 --- a/machines/marduk/configuration.nix +++ b/machines/marduk/configuration.nix @@ -1,53 +1,28 @@ -{ pkgs, ... }: { - services.dnsmasq.settings.address = [ - "/server.int/ftp.int/samba.int/mail.int/192.168.0.10" +# This is device is meant to be a home, LOCAL ONLY server! +# The configurations you will find are woefully insecure and hard-coded. +{ lib, ... }: { + imports = [ + ./httpd.nix + ./mail.nix ]; - services.httpd = { - virtualHosts = { - "server.int" = { - listen = [ { port = 80; } ]; - documentRoot = "/var/www/server"; - locations."/server-status".extraConfig = '' - SetHandler server-status - ''; - }; - - #== File servers ==# - - "samba.int" = rec { - listen = [ { port = 80; } ]; - documentRoot = "/NetworkDirectory"; - extraConfig = '' - - IndexOptions +NameWidth=* +Charset=UTF-8 - - ''; - }; - "ftp.int" = rec { - listen = [ { port = 80; } ]; - documentRoot = "/home/ftp"; - extraConfig = '' - - IndexOptions +NameWidth=* +Charset=UTF-8 - - ''; - }; + options = { + constants = lib.mkOption { + type = lib.types.attrs; }; }; - services.maddy = { - localDomains = [ "mail.int" ]; - - ensureAccounts = [ - "john@mail.int" - "yorgus@mail.int" - ]; - ensureCredentials = { - # Do not use this in production. This will make passwords world-readable - # in the Nix store - "john@mail.int".passwordFile = "${pkgs.writeText "postmaster" "john"}"; - "yorgus@mail.int".passwordFile = "${pkgs.writeText "postmaster" "yorgus"}"; + config = { + constants = { + # I've currently set this IP in my router configuration. + # It would be better to write a proper static IP NixOS config, but its + # fine like that. + ip = "192.168.0.10"; + # This is actually a fantastic TLD. Very few sites use it, you may + # consider it as an abbreviation of "internal" and is one of the + # "original" gTLDs, introduced in 1988, so every device will always + # work with it. + tld = "int"; }; }; } diff --git a/machines/marduk/httpd.nix b/machines/marduk/httpd.nix new file mode 100644 index 0000000..eb6d8af --- /dev/null +++ b/machines/marduk/httpd.nix @@ -0,0 +1,40 @@ +{ config, ... }: let + inherit (config.constants) ip tld; +in { + services.dnsmasq.settings.address = [ + "/server.${tld}/ftp.${tld}/samba.${tld}/${ip}" + ]; + + services.httpd = { + virtualHosts = { + "server.${tld}" = { + listen = [ { port = 80; } ]; + documentRoot = "/var/www/server"; + locations."/server-status".extraConfig = '' + SetHandler server-status + ''; + }; + + #== File servers ==# + + "samba.${tld}" = rec { + listen = [ { port = 80; } ]; + documentRoot = "/NetworkDirectory"; + extraConfig = '' + + IndexOptions +NameWidth=* +Charset=UTF-8 + + ''; + }; + "ftp.${tld}" = rec { + listen = [ { port = 80; } ]; + documentRoot = "/home/ftp"; + extraConfig = '' + + IndexOptions +NameWidth=* +Charset=UTF-8 + + ''; + }; + }; + }; +} diff --git a/machines/marduk/mail.nix b/machines/marduk/mail.nix new file mode 100644 index 0000000..928be56 --- /dev/null +++ b/machines/marduk/mail.nix @@ -0,0 +1,40 @@ +# This mail server is meant to be LOCAL/INTERNAL ONLY! +# It is woefully insecure, but the plan is to be used only between devices +# on my home network, so its ok. +# +# Configuring internal mail clients: +# INCOMING SERVER +# Protocol : IMAP +# Hostname : mail.int +# Port : 143 +# Connection security : None +# Authentication method: Normal Password +# Username : NAME@mail.int +# OUTGOING SERVER (SMTP) +# Hostname : mail.int +# Port : 587 +# Connection security : None +# Authentication method: Normal Password +# Username : NAME@mail.int +{ pkgs, config, ... }: let + mailDomain = "mail." + config.constants.tld; +in { + services.dnsmasq.settings.address = [ + "/${mailDomain}/${config.constants.ip}" + ]; + + services.maddy = { + localDomains = [ mailDomain ]; + + ensureAccounts = [ + "john@${mailDomain}" + "yorgus@${mailDomain}" + ]; + ensureCredentials = { + # Do not use this in production. This will make passwords world-readable + # in the Nix store + "john@${mailDomain}".passwordFile = "${pkgs.writeText "postmaster" "john"}"; + "yorgus@${mailDomain}".passwordFile = "${pkgs.writeText "postmaster" "yorgus"}"; + }; + }; +} -- cgit v1.3.1-26-gb76a