From 656816ed9af6277bbeb1c5e74471bace3a78e5be Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Mon, 16 Nov 2020 11:47:36 -0500 Subject: get build working and capitalize more files --- Biz/Cloud/Chat.nix | 100 +++++++++++++++++++++++++++++++++++++++++++++++ Biz/Cloud/Git.nix | 17 ++++++++ Biz/Cloud/Hardware.nix | 8 ++++ Biz/Cloud/Mail.nix | 43 ++++++++++++++++++++ Biz/Cloud/Networking.nix | 32 +++++++++++++++ Biz/Cloud/Web.nix | 41 +++++++++++++++++++ Biz/Cloud/Znc.nix | 66 +++++++++++++++++++++++++++++++ Biz/Cloud/chat.nix | 100 ----------------------------------------------- Biz/Cloud/git.nix | 17 -------- Biz/Cloud/hardware.nix | 8 ---- Biz/Cloud/mail.nix | 43 -------------------- Biz/Cloud/networking.nix | 32 --------------- Biz/Cloud/web.nix | 41 ------------------- Biz/Cloud/znc.nix | 66 ------------------------------- 14 files changed, 307 insertions(+), 307 deletions(-) create mode 100644 Biz/Cloud/Chat.nix create mode 100644 Biz/Cloud/Git.nix create mode 100644 Biz/Cloud/Hardware.nix create mode 100644 Biz/Cloud/Mail.nix create mode 100644 Biz/Cloud/Networking.nix create mode 100644 Biz/Cloud/Web.nix create mode 100644 Biz/Cloud/Znc.nix delete mode 100644 Biz/Cloud/chat.nix delete mode 100644 Biz/Cloud/git.nix delete mode 100644 Biz/Cloud/hardware.nix delete mode 100644 Biz/Cloud/mail.nix delete mode 100644 Biz/Cloud/networking.nix delete mode 100644 Biz/Cloud/web.nix delete mode 100644 Biz/Cloud/znc.nix (limited to 'Biz') diff --git a/Biz/Cloud/Chat.nix b/Biz/Cloud/Chat.nix new file mode 100644 index 0000000..bc97973 --- /dev/null +++ b/Biz/Cloud/Chat.nix @@ -0,0 +1,100 @@ +{ config, pkgs, ... }: +# +# a homeserver for matrix.org. +# +# - nixos manual: https://nixos.org/nixos/manual/index.html#module-services-matrix +# +# to create new users: +# +# nix run nixpkgs.matrix-synapse +# register_new_matrix_user -k http://localhost: +# +let + fqdn = "matrix.${config.networking.domain}"; + element = "chat.${config.networking.domain}"; + matrix_port = 8448; +in { + # matrix-synapse server. for what the settings mean, see: + # https://nixos.org/nixos/manual/index.html#module-services-matrix + # + services.matrix-synapse = { + enable = true; + server_name = config.networking.domain; + registration_shared_secret = "AkGRWSQLga3RoKRFnHhKoeCEIeZzu31y4TRzMRkMyRbBnETkVTSxilf24qySLzQn"; + listeners = [ + { + port = matrix_port; + bind_address = "::1"; + type = "http"; + tls = false; + x_forwarded = true; + resources = [ + { + names = [ "client" "federation" ]; + compress = false; + } + ]; + } + ]; + }; + # matrix needs a database + # + services.postgresql.enable = true; + # web proxy for the matrix server + # + services.nginx = { + enable = true; + recommendedTlsSettings = true; + recommendedOptimisation = true; + recommendedGzipSettings = true; + recommendedProxySettings = true; + virtualHosts = { + # route to matrix-synapse + "${config.networking.domain}" = { + locations."= /.well-known/matrix/server".extraConfig = + let + server = { "m.server" = "${fqdn}:443"; }; + in '' + add_header Content-Type application/json; + return 200 '${builtins.toJSON server}'; + ''; + locations."= /.well-known/matrix/client".extraConfig = + let + client = { + "m.homeserver" = { "base_url" = "https://${fqdn}"; } ; + "m.identity_server" = { "base_url" = "https://vector.im"; }; + }; + in '' + add_header Content-Type application/json; + add_header Access-Control-Allow-Origin *; + return 200 '${builtins.toJSON client}'; + ''; + }; + # reverse proxy for matrix client-server and server-server communication + "${fqdn}" = { + enableACME = true; + forceSSL = true; + locations."/".extraConfig = '' + return 404; + ''; + locations."/_matrix" = { + proxyPass = "http://[::1]:${toString matrix_port}"; + }; + }; + }; + }; + # matrix client, available at chat.simatime.com + # + # note that element and matrix-synapse must be on separate fqdn's to + # protect from XSS attacks: + # https://github.com/vector-im/element-web#important-security-note + # + services.nginx.virtualHosts."${element}" = { + enableACME = true; + forceSSL = true; + serverAliases = [ + "chat.${config.networking.domain}" + ]; + root = pkgs.element-web; + }; +} diff --git a/Biz/Cloud/Git.nix b/Biz/Cloud/Git.nix new file mode 100644 index 0000000..6104ced --- /dev/null +++ b/Biz/Cloud/Git.nix @@ -0,0 +1,17 @@ +{ pkgs, ... }: + +{ + services = { + gitolite = { + enable = true; + enableGitAnnex = true; + dataDir = "/srv/git"; + user = "git"; + group = "git"; + extraGitoliteRc = '' + $RC{SITE_INFO} = 'a computer is a bicycle for the mind.'; + ''; + adminPubkey = builtins.readFile ../Keys/Ben.pub; + }; + }; +} diff --git a/Biz/Cloud/Hardware.nix b/Biz/Cloud/Hardware.nix new file mode 100644 index 0000000..20eab30 --- /dev/null +++ b/Biz/Cloud/Hardware.nix @@ -0,0 +1,8 @@ +{ ... }: +{ + boot.loader.grub.device = "/dev/vda"; + fileSystems."/" = { device = "/dev/vda1"; fsType = "ext4"; }; + swapDevices = [ + { device = "/swapfile"; } # 4GB + ]; +} diff --git a/Biz/Cloud/Mail.nix b/Biz/Cloud/Mail.nix new file mode 100644 index 0000000..81bddc2 --- /dev/null +++ b/Biz/Cloud/Mail.nix @@ -0,0 +1,43 @@ +{ ... }: + +{ + mailserver = { + enable = true; + monitoring = { + enable = false; + alertAddress = "bsima@me.com"; + }; + fqdn = "simatime.com"; + domains = [ "simatime.com" "bsima.me" ]; + certificateScheme = 3; # let's encrypt + enableImap = true; + enablePop3 = true; + enableImapSsl = true; + enablePop3Ssl = true; + enableManageSieve = true; + virusScanning = false; # ur on ur own + localDnsResolver = true; + + loginAccounts = { + "ben@simatime.com" = { + hashedPassword = "$6$Xr180W0PqprtaFB0$9S/Ug1Yz11CaWO7UdVJxQLZWfRUE3/rarB0driXkXALugEeQDLIjG2STGQBLU23//JtK3Mz8Kwsvg1/Zo0vD2/"; + aliases = [ + # my default email + "ben@bsima.me" + # admin stuff + "postmaster@simatime.com" + "abuse@simatime.com" + ]; + catchAll = [ "simatime.com" "bsima.me" ]; + quota = "5G"; + }; + "nick@simatime.com" = { + hashedPassword = "$6$31P/Mg8k8Pezy1e$Fn1tDyssf.1EgxmLYFsQpSq6RP4wbEvP/UlBlXQhyKA9FnmFtJteXsbJM1naa8Kyylo8vZM9zmeoSthHS1slA1"; + aliases = [ + "nicolai@simatime.com" + ]; + quota = "1G"; + }; + }; + }; +} diff --git a/Biz/Cloud/Networking.nix b/Biz/Cloud/Networking.nix new file mode 100644 index 0000000..b259d86 --- /dev/null +++ b/Biz/Cloud/Networking.nix @@ -0,0 +1,32 @@ +{ lib, config, ... }: + +{ + networking = { + firewall = { + allowedTCPPorts = [ 22 80 443 ]; + }; + nameservers = [ + "67.207.67.2" + "67.207.67.3" + ]; + defaultGateway = "159.89.128.1"; + defaultGateway6 = "2604:a880:2:d0::1"; + dhcpcd.enable = false; + usePredictableInterfaceNames = lib.mkForce true; + interfaces = { + eth0 = { + ipv4.addresses = [ + { address="159.89.128.69"; prefixLength=20; } + { address="10.46.0.6"; prefixLength=16; } + ]; + ipv6.addresses = [ + { address="2604:a880:2:d0::35:c001"; prefixLength = 64; } + { address="fe80::e899:c0ff:fe9c:e194"; prefixLength = 64; } + ]; + }; + }; + }; + services.udev.extraRules = '' + ATTR{address}=="ea:99:c0:9c:e1:94", NAME="eth0" + ''; +} diff --git a/Biz/Cloud/Web.nix b/Biz/Cloud/Web.nix new file mode 100644 index 0000000..acd5c2f --- /dev/null +++ b/Biz/Cloud/Web.nix @@ -0,0 +1,41 @@ +{ ... }: + +let + bensIp = "24.140.84.23"; +in +{ + services = { + nginx = { + enable = true; + recommendedGzipSettings = true; + recommendedOptimisation = true; + recommendedProxySettings = true; + recommendedTlsSettings = true; + virtualHosts = { + "bsima.me".root = "/home/ben/public_html/"; + "www.bsima.me".root = "/home/ben/public_html/"; + "simatime.com".locations."/".root = "/srv/www/"; + "firefoxsync.simatime.com".locations."/".proxyPass = "http://localhost:5001"; + "hero.simatime.com".locations."/".proxyPass = "http://${bensIp}:3001"; + "tv.simatime.com".locations."/".proxyPass = "http://${bensIp}:8096"; # emby runs on port 8096 + "deluge.simatime.com".locations."/".proxyPass = "http://${bensIp}:8112"; + + "notebook.simatime.com".locations = { + "/" = { + proxyPass = "http://${bensIp}:3099"; + proxyWebsockets = true; + extraConfig = '' + proxy_buffering off; + proxy_read_timeout 86400; + + ''; + }; + "/(api/kernels/[^/]+/channels|terminals/websocket)/" = { + proxyPass = "http://${bensIp}:3099"; + proxyWebsockets = true; + }; + }; + }; + }; + }; +} diff --git a/Biz/Cloud/Znc.nix b/Biz/Cloud/Znc.nix new file mode 100644 index 0000000..9b1a28d --- /dev/null +++ b/Biz/Cloud/Znc.nix @@ -0,0 +1,66 @@ +/* + +N.B.: generate znc passwords with 'nix-shell -p znc --command "znc --makepass"' + +- https://wiki.znc.in/Configuration + +*/ + +{ ... }: + +{ + services = { + znc = { + enable = true; + mutable = false; + useLegacyConfig = false; + openFirewall = true; + config = { + LoadModule = [ "adminlog" ]; + User.bsima = { + Admin = true; + Nick = "bsima"; + AltNick = "bsima1"; + LoadModule = [ "chansaver" "controlpanel" "log" ]; + Network.freenode = { + Server = "chat.freenode.net +6697"; + LoadModule = [ "simple_away" "nickserv" "sasl" ]; + Chan = { + "#ai" = {}; + "#biz" = { Modes = "+Sp"; }; + "#bsima" = { Modes = "+Sp"; }; + "##categorytheory" = { Detached = true; }; + "#clojure" = { Detached = true; }; + "#coq" = { Detached = true; }; + "#emacs" = { Detached = true; }; + "#guile" = { Detached = true; }; + "#guix" = { Detached = true; }; + "#haskell" = {}; + "#haskell-miso" = { Detached = true; }; + "#hledger" = {}; + "#hnix" = { Detached = true; }; + "#home-manager" = { Detached = true; }; + "#ledger" = {}; + "#nix-darwin" = { Detached = true; }; + "#nixos" = {}; + "#org-mode" = {}; + "#scheme" = { Detached = true; }; + "#servant" = { Detached = true; }; + "#sr.ht" = { Detached = true; }; + "#xmonad" = { Detached = true; }; + }; + }; + Network.efnet = { + Server = "irc.efnet.info +6697"; + LoadModule = [ "simple_away" ]; + }; + Pass.password = { + Method = "sha256"; + Hash = "bead16d806e7bf5cbbc31d572b20f01e2b253eb60e2497ce465df56306becd02"; + Salt = "/GhmBMc+E6b7qd8muFEe"; + }; + }; + }; + }; + }; +} diff --git a/Biz/Cloud/chat.nix b/Biz/Cloud/chat.nix deleted file mode 100644 index e23b73e..0000000 --- a/Biz/Cloud/chat.nix +++ /dev/null @@ -1,100 +0,0 @@ -{ config, pkgs, ... }: -# -# a homeserver for matrix.org. -# -# - nixos manual: https://nixos.org/nixos/manual/index.html#module-services-matrix -# -# to create new users: -# -# nix run nixpkgs.matrix-synapse -# register_new_matrix_user -k http://localhost: -# -let - fqdn = "matrix.${config.networking.domain}"; - riot = "chat.${config.networking.domain}"; - matrix_port = 8448; -in { - # matrix-synapse server. for what the settings mean, see: - # https://nixos.org/nixos/manual/index.html#module-services-matrix - # - services.matrix-synapse = { - enable = true; - server_name = config.networking.domain; - registration_shared_secret = "AkGRWSQLga3RoKRFnHhKoeCEIeZzu31y4TRzMRkMyRbBnETkVTSxilf24qySLzQn"; - listeners = [ - { - port = matrix_port; - bind_address = "::1"; - type = "http"; - tls = false; - x_forwarded = true; - resources = [ - { - names = [ "client" "federation" ]; - compress = false; - } - ]; - } - ]; - }; - # matrix needs a database - # - services.postgresql.enable = true; - # web proxy for the matrix server - # - services.nginx = { - enable = true; - recommendedTlsSettings = true; - recommendedOptimisation = true; - recommendedGzipSettings = true; - recommendedProxySettings = true; - virtualHosts = { - # route to matrix-synapse - "${config.networking.domain}" = { - locations."= /.well-known/matrix/server".extraConfig = - let - server = { "m.server" = "${fqdn}:443"; }; - in '' - add_header Content-Type application/json; - return 200 '${builtins.toJSON server}'; - ''; - locations."= /.well-known/matrix/client".extraConfig = - let - client = { - "m.homeserver" = { "base_url" = "https://${fqdn}"; } ; - "m.identity_server" = { "base_url" = "https://vector.im"; }; - }; - in '' - add_header Content-Type application/json; - add_header Access-Control-Allow-Origin *; - return 200 '${builtins.toJSON client}'; - ''; - }; - # reverse proxy for matrix client-server and server-server communication - "${fqdn}" = { - enableACME = true; - forceSSL = true; - locations."/".extraConfig = '' - return 404; - ''; - locations."/_matrix" = { - proxyPass = "http://[::1]:${toString matrix_port}"; - }; - }; - }; - }; - # riot client, available at chat.simatime.com - # - # note that riot and matrix-synapse must be on separate fqdn's to - # protect from XSS attacks: - # https://github.com/vector-im/riot-web#important-security-note - # - services.nginx.virtualHosts."${riot}" = { - enableACME = true; - forceSSL = true; - serverAliases = [ - "chat.${config.networking.domain}" - ]; - root = pkgs.riot-web; - }; -} diff --git a/Biz/Cloud/git.nix b/Biz/Cloud/git.nix deleted file mode 100644 index 6104ced..0000000 --- a/Biz/Cloud/git.nix +++ /dev/null @@ -1,17 +0,0 @@ -{ pkgs, ... }: - -{ - services = { - gitolite = { - enable = true; - enableGitAnnex = true; - dataDir = "/srv/git"; - user = "git"; - group = "git"; - extraGitoliteRc = '' - $RC{SITE_INFO} = 'a computer is a bicycle for the mind.'; - ''; - adminPubkey = builtins.readFile ../Keys/Ben.pub; - }; - }; -} diff --git a/Biz/Cloud/hardware.nix b/Biz/Cloud/hardware.nix deleted file mode 100644 index 20eab30..0000000 --- a/Biz/Cloud/hardware.nix +++ /dev/null @@ -1,8 +0,0 @@ -{ ... }: -{ - boot.loader.grub.device = "/dev/vda"; - fileSystems."/" = { device = "/dev/vda1"; fsType = "ext4"; }; - swapDevices = [ - { device = "/swapfile"; } # 4GB - ]; -} diff --git a/Biz/Cloud/mail.nix b/Biz/Cloud/mail.nix deleted file mode 100644 index 81bddc2..0000000 --- a/Biz/Cloud/mail.nix +++ /dev/null @@ -1,43 +0,0 @@ -{ ... }: - -{ - mailserver = { - enable = true; - monitoring = { - enable = false; - alertAddress = "bsima@me.com"; - }; - fqdn = "simatime.com"; - domains = [ "simatime.com" "bsima.me" ]; - certificateScheme = 3; # let's encrypt - enableImap = true; - enablePop3 = true; - enableImapSsl = true; - enablePop3Ssl = true; - enableManageSieve = true; - virusScanning = false; # ur on ur own - localDnsResolver = true; - - loginAccounts = { - "ben@simatime.com" = { - hashedPassword = "$6$Xr180W0PqprtaFB0$9S/Ug1Yz11CaWO7UdVJxQLZWfRUE3/rarB0driXkXALugEeQDLIjG2STGQBLU23//JtK3Mz8Kwsvg1/Zo0vD2/"; - aliases = [ - # my default email - "ben@bsima.me" - # admin stuff - "postmaster@simatime.com" - "abuse@simatime.com" - ]; - catchAll = [ "simatime.com" "bsima.me" ]; - quota = "5G"; - }; - "nick@simatime.com" = { - hashedPassword = "$6$31P/Mg8k8Pezy1e$Fn1tDyssf.1EgxmLYFsQpSq6RP4wbEvP/UlBlXQhyKA9FnmFtJteXsbJM1naa8Kyylo8vZM9zmeoSthHS1slA1"; - aliases = [ - "nicolai@simatime.com" - ]; - quota = "1G"; - }; - }; - }; -} diff --git a/Biz/Cloud/networking.nix b/Biz/Cloud/networking.nix deleted file mode 100644 index b259d86..0000000 --- a/Biz/Cloud/networking.nix +++ /dev/null @@ -1,32 +0,0 @@ -{ lib, config, ... }: - -{ - networking = { - firewall = { - allowedTCPPorts = [ 22 80 443 ]; - }; - nameservers = [ - "67.207.67.2" - "67.207.67.3" - ]; - defaultGateway = "159.89.128.1"; - defaultGateway6 = "2604:a880:2:d0::1"; - dhcpcd.enable = false; - usePredictableInterfaceNames = lib.mkForce true; - interfaces = { - eth0 = { - ipv4.addresses = [ - { address="159.89.128.69"; prefixLength=20; } - { address="10.46.0.6"; prefixLength=16; } - ]; - ipv6.addresses = [ - { address="2604:a880:2:d0::35:c001"; prefixLength = 64; } - { address="fe80::e899:c0ff:fe9c:e194"; prefixLength = 64; } - ]; - }; - }; - }; - services.udev.extraRules = '' - ATTR{address}=="ea:99:c0:9c:e1:94", NAME="eth0" - ''; -} diff --git a/Biz/Cloud/web.nix b/Biz/Cloud/web.nix deleted file mode 100644 index acd5c2f..0000000 --- a/Biz/Cloud/web.nix +++ /dev/null @@ -1,41 +0,0 @@ -{ ... }: - -let - bensIp = "24.140.84.23"; -in -{ - services = { - nginx = { - enable = true; - recommendedGzipSettings = true; - recommendedOptimisation = true; - recommendedProxySettings = true; - recommendedTlsSettings = true; - virtualHosts = { - "bsima.me".root = "/home/ben/public_html/"; - "www.bsima.me".root = "/home/ben/public_html/"; - "simatime.com".locations."/".root = "/srv/www/"; - "firefoxsync.simatime.com".locations."/".proxyPass = "http://localhost:5001"; - "hero.simatime.com".locations."/".proxyPass = "http://${bensIp}:3001"; - "tv.simatime.com".locations."/".proxyPass = "http://${bensIp}:8096"; # emby runs on port 8096 - "deluge.simatime.com".locations."/".proxyPass = "http://${bensIp}:8112"; - - "notebook.simatime.com".locations = { - "/" = { - proxyPass = "http://${bensIp}:3099"; - proxyWebsockets = true; - extraConfig = '' - proxy_buffering off; - proxy_read_timeout 86400; - - ''; - }; - "/(api/kernels/[^/]+/channels|terminals/websocket)/" = { - proxyPass = "http://${bensIp}:3099"; - proxyWebsockets = true; - }; - }; - }; - }; - }; -} diff --git a/Biz/Cloud/znc.nix b/Biz/Cloud/znc.nix deleted file mode 100644 index 9b1a28d..0000000 --- a/Biz/Cloud/znc.nix +++ /dev/null @@ -1,66 +0,0 @@ -/* - -N.B.: generate znc passwords with 'nix-shell -p znc --command "znc --makepass"' - -- https://wiki.znc.in/Configuration - -*/ - -{ ... }: - -{ - services = { - znc = { - enable = true; - mutable = false; - useLegacyConfig = false; - openFirewall = true; - config = { - LoadModule = [ "adminlog" ]; - User.bsima = { - Admin = true; - Nick = "bsima"; - AltNick = "bsima1"; - LoadModule = [ "chansaver" "controlpanel" "log" ]; - Network.freenode = { - Server = "chat.freenode.net +6697"; - LoadModule = [ "simple_away" "nickserv" "sasl" ]; - Chan = { - "#ai" = {}; - "#biz" = { Modes = "+Sp"; }; - "#bsima" = { Modes = "+Sp"; }; - "##categorytheory" = { Detached = true; }; - "#clojure" = { Detached = true; }; - "#coq" = { Detached = true; }; - "#emacs" = { Detached = true; }; - "#guile" = { Detached = true; }; - "#guix" = { Detached = true; }; - "#haskell" = {}; - "#haskell-miso" = { Detached = true; }; - "#hledger" = {}; - "#hnix" = { Detached = true; }; - "#home-manager" = { Detached = true; }; - "#ledger" = {}; - "#nix-darwin" = { Detached = true; }; - "#nixos" = {}; - "#org-mode" = {}; - "#scheme" = { Detached = true; }; - "#servant" = { Detached = true; }; - "#sr.ht" = { Detached = true; }; - "#xmonad" = { Detached = true; }; - }; - }; - Network.efnet = { - Server = "irc.efnet.info +6697"; - LoadModule = [ "simple_away" ]; - }; - Pass.password = { - Method = "sha256"; - Hash = "bead16d806e7bf5cbbc31d572b20f01e2b253eb60e2497ce465df56306becd02"; - Salt = "/GhmBMc+E6b7qd8muFEe"; - }; - }; - }; - }; - }; -} -- cgit v1.2.3