diff options
| Commit | 1e99bf8f1c33e77c6aa5a5a4d128b71b4a8e53f1 (patch) | |
|---|---|---|
| Author | 2025-07-04 09:21:44 +0300 | |
| Committer | 2025-07-04 09:21:44 +0300 | |
| Files | 4890638ba55b5d7c4ae05b751fe14c8f0b9b1713 | |
| nix-1e99bf8f1c33e77c6aa5a5a4d128b71b4a8e53f1.tar nix-1e99bf8f1c33e77c6aa5a5a4d128b71b4a8e53f1.tar.gz nix-1e99bf8f1c33e77c6aa5a5a4d128b71b4a8e53f1.zip | ||
| Parent | 5a7f3676d1dd5c0792a4c1637aca04c3609b3db6 (diff) | |
feat(machines/marduk): Split configuration into multiple files and make code more generic
3 files changed, 100 insertions, 45 deletions
| -rw-r--r-- | machines/marduk/configuration.nix | 65 | ||||
| -rw-r--r-- | machines/marduk/httpd.nix | 40 | ||||
| -rw-r--r-- | machines/marduk/mail.nix | 40 |
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 = '' - <Directory "${documentRoot}"> - IndexOptions +NameWidth=* +Charset=UTF-8 - </Directory> - ''; - }; - "ftp.int" = rec { - listen = [ { port = 80; } ]; - documentRoot = "/home/ftp"; - extraConfig = '' - <Directory "${documentRoot}"> - IndexOptions +NameWidth=* +Charset=UTF-8 - </Directory> - ''; - }; + 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 = '' + <Directory "${documentRoot}"> + IndexOptions +NameWidth=* +Charset=UTF-8 + </Directory> + ''; + }; + "ftp.${tld}" = rec { + listen = [ { port = 80; } ]; + documentRoot = "/home/ftp"; + extraConfig = '' + <Directory "${documentRoot}"> + IndexOptions +NameWidth=* +Charset=UTF-8 + </Directory> + ''; + }; + }; + }; +} 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"}"; + }; + }; +} |
