From ae0c5392b7dd6d890c877253b0e1b621c1639ded Mon Sep 17 00:00:00 2001 From: Mikhail Klementev Date: Tue, 17 Jan 2023 17:02:34 +0000 Subject: [PATCH] Initial --- .gitignore | 2 + LICENSE | 9 ++ configuration.nix | 207 ++++++++++++++++++++++++++++++++++++++++++++ ldap/go.mod | 16 ++++ ldap/go.sum | 25 ++++++ ldap/ldap.go | 169 ++++++++++++++++++++++++++++++++++++ secrets.nix.example | 44 ++++++++++ 7 files changed, 472 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 configuration.nix create mode 100644 ldap/go.mod create mode 100644 ldap/go.sum create mode 100644 ldap/ldap.go create mode 100644 secrets.nix.example diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..849b2f0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +secrets.nix +hardware-configuration.nix diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..47df30c --- /dev/null +++ b/LICENSE @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) 2023 Mikhail Klementev + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/configuration.nix b/configuration.nix new file mode 100644 index 0000000..75f1edc --- /dev/null +++ b/configuration.nix @@ -0,0 +1,207 @@ +{ config, pkgs, lib, ... }: +let + secrets = import ./secrets.nix; + + ldap = pkgs.buildGoModule rec { + name = "ldap"; + src = ./ldap; + vendorHash = "sha256-HlsVCWs7Q4kBAtRpt3U323tRmgWdQxZlpfMZ/cSlw4Q="; + }; + + image = + "chocobozzz/peertube@" + + "sha256:3bd126fc8b66a6a12593d73f74d0a3ffc7fc3206e5e9ebf39c8a8e0ca5408194"; + + domainName = "v.lor.sh"; + hostName = builtins.replaceStrings [ "." ] [ "-" ] "${domainName}"; +in { + imports = [ ./hardware-configuration.nix ]; + + boot.loader = { + efi.canTouchEfiVariables = true; + grub = { + enable = true; + efiSupport = true; + device = "nodev"; + mirroredBoots = [{ + devices = [ "nodev" ]; + path = "/boot-fallback"; + }]; + }; + }; + + networking = { + hostName = hostName; + hostId = (builtins.substring 0 8 (builtins.readFile "/etc/machine-id")); + + useDHCP = false; + + interfaces.eno1 = { + ipv4 = secrets.ipv4; + ipv6 = secrets.ipv6; + }; + + nameservers = [ "1.1.1.1" ]; + + firewall = { + enable = true; + allowedTCPPorts = [ 80 443 ]; + }; + }; + + users.extraUsers.root.openssh.authorizedKeys.keys = secrets.pubkeys; + + services.openssh.enable = true; + + environment.systemPackages = with pkgs; [ vim htop git tmux ]; + + systemd.services."peertube-ldap" = { + wantedBy = [ "multi-user.target" ]; + after = [ "network.target" ]; + environment = { + AUTH_URL = secrets.peertube.auth.url; + AUTH_SECRET = secrets.peertube.auth.secret; + LDAP_USER = secrets.peertube.ldap.user; + LDAP_PASS = secrets.peertube.ldap.password; + }; + serviceConfig = { + Restart = "always"; + RestartSec = 30; + ExecStart = "${ldap}/bin/ldap"; + User = "peertube"; + }; + }; + + services.caddy = { + enable = true; + virtualHosts."${domainName}".extraConfig = '' + encode gzip + + root * /dev/null + reverse_proxy localhost:9000 + + header { + Strict-Transport-Security "max-age=31536000;" + } + ''; + }; + + system.activationScripts.peertube = '' + mkdir -p /var/lib/peertube/{storage,config} + cat > /var/lib/peertube/config/local.yml <