diff options
Diffstat (limited to 'nix/hosts')
21 files changed, 619 insertions, 20 deletions
diff --git a/nix/hosts/caladan/darwin-configuration.nix b/nix/hosts/caladan/darwin-configuration.nix index c681b35..a181b35 100644 --- a/nix/hosts/caladan/darwin-configuration.nix +++ b/nix/hosts/caladan/darwin-configuration.nix @@ -42,12 +42,14 @@ trusted-users = [ "root" "hydra" "emile" ]; trusted-public-keys = [ - "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=" "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=" + "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=" + "cache.garnix.io:CTFPyKSLcx5RMJKfLo5EEPUObbA78b0YQ2DTCJXqr9g=" ]; substituters = [ "https://cache.nixos.org" "https://nix-community.cachix.org" + "https://cache.garnix.io" ]; experimental-features = [ "nix-command" "flakes" ]; diff --git a/nix/hosts/caladan/home_emile.nix b/nix/hosts/caladan/home_emile.nix index a7009ab..f57daaf 100644 --- a/nix/hosts/caladan/home_emile.nix +++ b/nix/hosts/caladan/home_emile.nix @@ -165,6 +165,7 @@ # c foo cmake + pkg-config # iot hack foo minicom @@ -180,13 +181,18 @@ virt-manager # lisp foo + #unstable.sbcl # sbcl + #clasp-common-lisp + clisp # infrastructure as code foo terraform ansible portmidi + tiny # irc + # blender # ] ++ lib.optionals stdenv.isDarwin [ diff --git a/nix/hosts/corrino/configuration.nix b/nix/hosts/corrino/configuration.nix index d23b6bf..1f054ff 100644 --- a/nix/hosts/corrino/configuration.nix +++ b/nix/hosts/corrino/configuration.nix @@ -25,7 +25,10 @@ in { ./www/hydra.emile.space.nix ./www/netbox.emile.space.nix ./www/grafana.emile.space.nix - ./www/photo.emile.space.nix + + # ./www/photo.emile.space.nix + # ./www/photo + ./www/tickets.emile.space.nix ./www/talks.emile.space.nix ./www/stream.emile.space.nix @@ -34,6 +37,9 @@ in { ./www/sso.emile.space.nix ./www/s3.emile.space.nix + # ./www/irc.emile.space.nix + # ./www/irc + ./www/ctf.emile.space.nix # ./www/magic-hash.emile.space.nix @@ -450,8 +456,12 @@ in { }; }; + virtualisation.podman = { + enable = true; + autoPrune.enable = true; + }; virtualisation = { - docker.enable = true; + # docker.enable = true; libvirtd = { enable = true; qemu = { diff --git a/nix/hosts/corrino/hetzner-dedicated-wipe-and-install-nixos-luks-raid-lvm.sh b/nix/hosts/corrino/hetzner-dedicated-wipe-and-install-nixos-luks-raid-lvm.sh new file mode 100755 index 0000000..de42261 --- /dev/null +++ b/nix/hosts/corrino/hetzner-dedicated-wipe-and-install-nixos-luks-raid-lvm.sh @@ -0,0 +1,347 @@ +#!/usr/bin/env bash + +# Installs NixOS on a Hetzner server, wiping the server. +# +# This is for a specific server configuration; adjust where needed. +# +# Prerequisites: +# * Update the script wherever FIXME is present +# +# Usage: +# ssh root@YOUR_SERVERS_IP bash -s < hetzner-dedicated-wipe-and-install-nixos.sh +# +# When the script is done, make sure to boot the server from HD, not rescue mode again. + +# Explanations: +# +# * Adapted from https://gist.github.com/nh2/78d1c65e33806e7728622dbe748c2b6a +# * Following largely https://nixos.org/nixos/manual/index.html#sec-installing-from-other-distro. +# * **Important:** We boot in legacy-BIOS mode, not UEFI, because that's what Hetzner uses. +# * NVMe devices aren't supported for booting (those require EFI boot) +# * We set a custom `configuration.nix` so that we can connect to the machine afterwards, +# inspired by https://nixos.wiki/wiki/Install_NixOS_on_Hetzner_Online +# * This server has 2 HDDs. +# We put everything on RAID1. +# Storage scheme: `partitions -> RAID -> LVM -> ext4`. +# * A root user with empty password is created, so that you can just login +# as root and press enter when using the Hetzner spider KVM. +# Of course that empty-password login isn't exposed to the Internet. +# Change the password afterwards to avoid anyone with physical access +# being able to login without any authentication. +# * The script reboots at the end. + +NIXOS_VERSION="22.11" + +echo "Enter New Hostname" +HOSTNAME="corrino" + +echo "Enter LUKS Password" +LUKS_PASSWORD="FIXME" + +set -eu +set -o pipefail + +set -x + +# Inspect existing disks +lsblk + +# Undo existing setups to allow running the script multiple times to iterate on it. +# We allow these operations to fail for the case the script runs the first time. +set +e +umount /mnt/boot /mnt/dev /mnt/proc /mnt/run /mnt/sys /mnt +vgchange -an +cryptsetup close luks0 +rm initrd_ssh_host_ecdsa_key +set -e + +# Stop all mdadm arrays that the boot may have activated. +mdadm --stop --scan + +# Prevent mdadm from auto-assembling arrays. +# Otherwise, as soon as we create the partition tables below, it will try to +# re-assemple a previous RAID if any remaining RAID signatures are present, +# before we even get the chance to wipe them. +# From: +# https://unix.stackexchange.com/questions/166688/prevent-debian-from-auto-assembling-raid-at-boot/504035#504035 +# We use `>` because the file may already contain some detected RAID arrays, +# which would take precedence over our `<ignore>`. +echo 'AUTO -all +ARRAY <ignore> UUID=00000000:00000000:00000000:00000000' > /etc/mdadm/mdadm.conf + +# Create partition tables (--script to not ask) +parted --script /dev/nvme0n1 mklabel gpt +parted --script /dev/nvme1n1 mklabel gpt + +# Create partitions (--script to not ask) +# +# We create the 1MB BIOS boot partition at the front. +# +# Note we use "MB" instead of "MiB" because otherwise `--align optimal` has no effect; +# as per documentation https://www.gnu.org/software/parted/manual/html_node/unit.html#unit: +# > Note that as of parted-2.4, when you specify start and/or end values using IEC +# > binary units like "MiB", "GiB", "TiB", etc., parted treats those values as exact +# +# Note: When using `mkpart` on GPT, as per +# https://www.gnu.org/software/parted/manual/html_node/mkpart.html#mkpart +# the first argument to `mkpart` is not a `part-type`, but the GPT partition name: +# ... part-type is one of 'primary', 'extended' or 'logical', and may be specified only with 'msdos' or 'dvh' partition tables. +# A name must be specified for a 'gpt' partition table. +# GPT partition names are limited to 36 UTF-16 chars, see https://en.wikipedia.org/wiki/GUID_Partition_Table#Partition_entries_(LBA_2-33). +parted --script --align optimal /dev/nvme0n1 -- mklabel gpt mkpart 'bios' 1MB 2MB set 1 bios_grub on mkpart 'boot' 2MB 1000MB mkpart 'root' 1000MB '100%' +parted --script --align optimal /dev/nvme1n1 -- mklabel gpt mkpart 'bios' 1MB 2MB set 1 bios_grub on mkpart 'boot' 2MB 1000MB mkpart 'root' 1000MB '100%' + +# Relaod partitions +partprobe + +# Wait for all devices to exist +udevadm settle --timeout=5 --exit-if-exists=/dev/nvme0n1p1 +udevadm settle --timeout=5 --exit-if-exists=/dev/nvme0n1p2 +udevadm settle --timeout=5 --exit-if-exists=/dev/nvme0n1p3 + +udevadm settle --timeout=5 --exit-if-exists=/dev/nvme1n1p1 +udevadm settle --timeout=5 --exit-if-exists=/dev/nvme1n1p2 +udevadm settle --timeout=5 --exit-if-exists=/dev/nvme1n1p3 + +# Wipe any previous RAID signatures +mdadm --zero-superblock --force /dev/nvme0n1p2 +mdadm --zero-superblock --force /dev/nvme0n1p3 +mdadm --zero-superblock --force /dev/nvme1n1p2 +mdadm --zero-superblock --force /dev/nvme1n1p3 + +# Create RAIDs +# Note that during creating and boot-time assembly, mdadm cares about the +# host name, and the existence and contents of `mdadm.conf`! +# This also affects the names appearing in /dev/md/ being different +# before and after reboot in general (but we take extra care here +# to pass explicit names, and set HOMEHOST for the rebooting system further +# down, so that the names appear the same). +# Almost all details of this are explained in +# https://bugzilla.redhat.com/show_bug.cgi?id=606481#c14 +# and the followup comments by Doug Ledford. +#mdadm --create --run --verbose /dev/md0 --level=1 --raid-devices=2 --homehost=lxc11 --name=root0 /dev/nvme0n1p2 /dev/nvme1n1p2 +mdadm --create --run --verbose /dev/md0 --level=1 --raid-devices=2 --homehost=$HOSTNAME --name=md0 /dev/nvme0n1p2 /dev/nvme1n1p2 +mdadm --create --run --verbose /dev/md1 --level=1 --raid-devices=2 --homehost=$HOSTNAME --name=md1 /dev/nvme0n1p3 /dev/nvme1n1p3 + +# Assembling the RAID can result in auto-activation of previously-existing LVM +# groups, preventing the RAID block device wiping below with +# `Device or resource busy`. So disable all VGs first. +vgchange -an + +# Wipe filesystem signatures that might be on the RAID from some +# possibly existing older use of the disks (RAID creation does not do that). +# See https://serverfault.com/questions/911370/why-does-mdadm-zero-superblock-preserve-file-system-information +wipefs -a /dev/md0 +wipefs -a /dev/md1 + +# Disable RAID recovery. We don't want this to slow down machine provisioning +# in the rescue mode. It can run in normal operation after reboot. +echo 0 > /proc/sys/dev/raid/speed_limit_max + +# LUKS +echo "$LUKS_PASSWORD" | cryptsetup luksFormat --type luks2 -h sha512 /dev/md1 +echo "$LUKS_PASSWORD" | cryptsetup luksOpen /dev/md1 luks0 + +# LVM +# PVs +pvcreate /dev/mapper/luks0 +#pvcreate /dev/md0 + +# VGs +#vgcreate vg0 /dev/md0 +vgcreate vg0 /dev/mapper/luks0 + +# LVs (--yes to automatically wipe detected file system signatures) +lvcreate --yes --extents 95%FREE -n root vg0 # 5% slack space + +# Filesystems (-F to not ask on preexisting FS) +mkfs.ext4 -F -L boot /dev/md0 +mkfs.ext4 -F -L root /dev/vg0/root + +# Creating file systems changes their UUIDs. +# Trigger udev so that the entries in /dev/disk/by-uuid get refreshed. +# `nixos-generate-config` depends on those being up-to-date. +# See https://github.com/NixOS/nixpkgs/issues/62444 +udevadm trigger + +# Wait for FS labels to appear +udevadm settle --timeout=5 --exit-if-exists=/dev/disk/by-label/boot +udevadm settle --timeout=5 --exit-if-exists=/dev/disk/by-label/root + +# NixOS pre-installation mounts + +# Mount target root partition +mount /dev/disk/by-label/root /mnt +mkdir /mnt/boot +mount /dev/disk/by-label/boot /mnt/boot + +# Installing nix + +# Installing nix requires `sudo`; the Hetzner rescue mode doesn't have it. +apt-get install -y sudo + +# Allow installing nix as root, see +# https://github.com/NixOS/nix/issues/936#issuecomment-475795730 +mkdir -p /etc/nix +echo "build-users-group =" > /etc/nix/nix.conf + +curl -L https://nixos.org/nix/install | sh +set +u +x # sourcing this may refer to unset variables that we have no control over +. $HOME/.nix-profile/etc/profile.d/nix.sh +set -u -x + +# FIXME Keep in sync with `system.stateVersion` set below! +nix-channel --add https://nixos.org/channels/nixos-$NIXOS_VERSION nixpkgs +nix-channel --update + +# Getting NixOS installation tools +nix-env -iE "_: with import <nixpkgs/nixos> { configuration = {}; }; with config.system.build; [ nixos-generate-config nixos-install nixos-enter manual.manpages ]" + +nixos-generate-config --root /mnt + +# Find the name of the network interface that connects us to the Internet. +# Inspired by https://unix.stackexchange.com/questions/14961/how-to-find-out-which-interface-am-i-using-for-connecting-to-the-internet/302613#302613 +RESCUE_INTERFACE=$(ip route get 8.8.8.8 | grep -Po '(?<=dev )(\S+)') + +# Find what its name will be under NixOS, which uses stable interface names. +# See https://major.io/2015/08/21/understanding-systemds-predictable-network-device-names/#comment-545626 +# NICs for most Hetzner servers are not onboard, which is why we use +# `ID_NET_NAME_PATH`otherwise it would be `ID_NET_NAME_ONBOARD`. +INTERFACE_DEVICE_PATH=$(udevadm info -e | grep -Po "(?<=^P: )(.*${RESCUE_INTERFACE})") +UDEVADM_PROPERTIES_FOR_INTERFACE=$(udevadm info --query=property "--path=$INTERFACE_DEVICE_PATH") +NIXOS_INTERFACE=$(echo "$UDEVADM_PROPERTIES_FOR_INTERFACE" | grep -o -E 'ID_NET_NAME_PATH=\w+' | cut -d= -f2) +echo "Determined NIXOS_INTERFACE as '$NIXOS_INTERFACE'" +# DOESNT WORK on PX server there it was eno1 + +IP_V4=$(ip route get 8.8.8.8 | grep -Po '(?<=src )(\S+)') +echo "Determined IP_V4 as $IP_V4" + +# Determine Internet IPv6 by checking route, and using ::1 +# (because Hetzner rescue mode uses ::2 by default). +# The `ip -6 route get` output on Hetzner looks like: +# # ip -6 route get 2001:4860:4860:0:0:0:0:8888 +# 2001:4860:4860::8888 via fe80::1 dev eth0 src 2a01:4f8:151:62aa::2 metric 1024 pref medium +IP_V6="$(ip route get 2001:4860:4860:0:0:0:0:8888 | head -1 | cut -d' ' -f7 | cut -d: -f1-4)::1" +echo "Determined IP_V6 as $IP_V6" + + +# From https://stackoverflow.com/questions/1204629/how-do-i-get-the-default-gateway-in-linux-given-the-destination/15973156#15973156 +read _ _ DEFAULT_GATEWAY _ < <(ip route list match 0/0); echo "$DEFAULT_GATEWAY" +echo "Determined DEFAULT_GATEWAY as $DEFAULT_GATEWAY" + +# Generate `configuration.nix`. Note that we splice in shell variables. +cat > /mnt/etc/nixos/configuration.nix <<EOF +{ config, pkgs, lib, ... }: +{ + imports = + [ # Include the results of the hardware scan. + ./hardware-configuration.nix + ]; + # Use GRUB2 as the boot loader. + # We don't use systemd-boot because Hetzner uses BIOS legacy boot. + boot.loader.systemd-boot.enable = false; + + boot.loader.grub = { + enable = true; + efiSupport = false; + version = 2; + enableCryptodisk = true; + device = "nodev"; + devices = [ "/dev/nvme0n1" "/dev/nvme1n1"]; + }; + networking.hostName = "$HOSTNAME"; + boot.initrd.kernelModules = [ "dm-snapshot" ]; + boot.initrd.availableKernelModules = [ "cryptd" "aesni_intel" "igb" ];#"FIXME Your network driver" ]; + boot.initrd.network = { + enable = true; + ssh = { + enable = true; + + # ssh port during boot for luks decryption + port = 2222; + authorizedKeys = config.users.users.root.openssh.authorizedKeys.keys; + hostKeys = [ "/initrd_ssh_host_ecdsa_key" ]; + }; + postCommands = '' + echo 'cryptsetup-askpass' >> /root/.profile + ''; + }; + boot.kernelParams = [ "ip=$IP_V4::$DEFAULT_GATEWAY:255.255.255.192:$HOSTNAME:$NIXOS_INTERFACE:off:8.8.8.8:8.8.4.4:" ]; + boot.loader.supportsInitrdSecrets = true; + boot.initrd.luks.forceLuksSupportInInitrd = true; + boot.initrd.luks.devices = { + root = { + preLVM = true; + device = "/dev/md1"; + allowDiscards = true; + }; + }; + + boot.initrd.secrets = { + "/initrd_ssh_host_ecdsa_key" = "/initrd_ssh_host_ecdsa_key"; + }; + # The mdadm RAID1s were created with 'mdadm --create ... --homehost=hetzner', + # but the hostname for each machine may be different, and mdadm's HOMEHOST + # setting defaults to '<system>' (using the system hostname). + # This results mdadm considering such disks as "foreign" as opposed to + # "local", and showing them as e.g. '/dev/md/hetzner:root0' + # instead of '/dev/md/root0'. + # This is mdadm's protection against accidentally putting a RAID disk + # into the wrong machine and corrupting data by accidental sync, see + # https://bugzilla.redhat.com/show_bug.cgi?id=606481#c14 and onward. + # We do not worry about plugging disks into the wrong machine because + # we will never exchange disks between machines, so we tell mdadm to + # ignore the homehost entirely. + environment.etc."mdadm.conf".text = '' + HOMEHOST <ignore> + ''; + # The RAIDs are assembled in stage1, so we need to make the config + # available there. + boot.initrd.services.swraid.mdadmConf = config.environment.etc."mdadm.conf".text; + # Network (Hetzner uses static IP assignments, and we don't use DHCP here) + networking.useDHCP = false; + networking.interfaces."$NIXOS_INTERFACE".ipv4.addresses = [ + { + address = "$IP_V4"; + + # FIXME Lookup for right netmask prefix length within rescu system + prefixLength = 26; + } + ]; + networking.interfaces."$NIXOS_INTERFACE".ipv6.addresses = [ + { + address = "$IP_V6"; + prefixLength = 64; + } + ]; + networking.defaultGateway = "$DEFAULT_GATEWAY"; + networking.defaultGateway6 = { address = "fe80::1"; interface = "$NIXOS_INTERFACE"; }; + networking.nameservers = [ "8.8.8.8" "8.8.4.4" ]; + # Initial empty root password for easy login: + users.users.root.initialHashedPassword = ""; + services.openssh.permitRootLogin = "prohibit-password"; + users.users.root.openssh.authorizedKeys.keys = [ + # FIXME Replace this by your SSH pubkey! + "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPZi43zHEsoWaQomLGaftPE5k0RqVrZyiTtGqZlpWsew" + ]; + services.openssh.enable = true; + + # FIXME + # This value determines the NixOS release with which your system is to be + # compatible, in order to avoid breaking some software such as database + # servers. You should change this only after NixOS release notes say you + # should. + system.stateVersion = "$NIXOS_VERSION"; # Did you read the comment? +} +EOF + +ssh-keygen -t ecdsa -N "" -f initrd_ssh_host_ecdsa_key; +cp initrd_ssh_host_ecdsa_key /mnt/initrd_ssh_host_ecdsa_key; + +# Install NixOS +PATH="$PATH" `which nixos-install` --no-root-passwd --root /mnt --max-jobs 40 + +umount /mnt/boot +umount /mnt + +echo "DONE" diff --git a/nix/hosts/corrino/ports.nix b/nix/hosts/corrino/ports.nix index 6be514d..2d7ba06 100644 --- a/nix/hosts/corrino/ports.nix +++ b/nix/hosts/corrino/ports.nix @@ -2,15 +2,23 @@ emile.ports = { stream_rtmp = 1935; initrd_ssh = 2222; - photo = 2342; + photo = { + photoprism = 2342; + immich = 2343; + }; git = 3000; hydra = 3001; grafana = 3002; md = 3003; gotosocial = 3004; + irc = { + clear = 6667; + ssl = 6697; + }; stream = 8080; netbox = 8001; restic = 8002; + r2wars-web = 8089; ctf = 8338; magic-hash = 8339; tickets = 8349; diff --git a/nix/hosts/corrino/www/ctf.emile.space.nix b/nix/hosts/corrino/www/ctf.emile.space.nix index 1d8b382..6eee75f 100644 --- a/nix/hosts/corrino/www/ctf.emile.space.nix +++ b/nix/hosts/corrino/www/ctf.emile.space.nix @@ -13,7 +13,7 @@ }; virtualisation.oci-containers = { - backend = "docker"; + # backend = "docker"; containers = { "ctfd" = { image = "ctfd/ctfd"; diff --git a/nix/hosts/corrino/www/emile.space.nix b/nix/hosts/corrino/www/emile.space.nix index 9cca880..c39ca31 100644 --- a/nix/hosts/corrino/www/emile.space.nix +++ b/nix/hosts/corrino/www/emile.space.nix @@ -13,6 +13,10 @@ ''; }; + "/@hanemile".extraConfig = '' + return 301 https://social.emile.space/@hanemile; + ''; + #"/.well-known" = { # root = "/var/www/emile.space"; # extraConfig = '' diff --git a/nix/hosts/corrino/www/git/cgit.nix b/nix/hosts/corrino/www/git/cgit.nix index e6983e5..1e63dfc 100644 --- a/nix/hosts/corrino/www/git/cgit.nix +++ b/nix/hosts/corrino/www/git/cgit.nix @@ -72,6 +72,12 @@ section = "Radare2"; owner = "emile"; }; + r2wars-web = { + desc = "The software behind https://r2wa.rs"; + path = "/var/lib/git/repositories/r2wars-web.git"; + section = "Radare2"; + owner = "emile"; + }; r2wars-rs = { desc = "A rust implementation of radare2"; path = "/var/lib/git/repositories/r2wars-rs.git"; @@ -538,7 +544,7 @@ # exposing stuff gitDaemon = { - enable = false; + enable = true; user = "git"; group = "git"; diff --git a/nix/hosts/corrino/www/md.emile.space.nix b/nix/hosts/corrino/www/md.emile.space.nix index 7ad7a94..52b4a53 100644 --- a/nix/hosts/corrino/www/md.emile.space.nix +++ b/nix/hosts/corrino/www/md.emile.space.nix @@ -4,17 +4,9 @@ services.nginx.virtualHosts."md.emile.space" = { forceSSL = true; enableACME = true; - - # TODO(emile): figure out why this doesn't work when enabled, has to do with authelia - # extraConfig = authelia-location; - locations = { "/" = { - # proxyPass = "http://127.0.0.1:3003"; proxyPass = "http://127.0.0.1:${toString config.services.hedgedoc.settings.port}"; - - # TODO(emile): figure out why this doesn't work when enabled, has to do with authelia - # extraConfig = authelia-authrequest; }; }; }; diff --git a/nix/hosts/corrino/www/photo/default.nix b/nix/hosts/corrino/www/photo/default.nix new file mode 100644 index 0000000..dd555e4 --- /dev/null +++ b/nix/hosts/corrino/www/photo/default.nix @@ -0,0 +1,8 @@ +{ ... }: + +{ + imports = [ + ./photoprism.nix + # ./immich.nix + ]; +} diff --git a/nix/hosts/corrino/www/photo.emile.space.nix b/nix/hosts/corrino/www/photo/photoprism.nix index 9c1e97a..c1cbbf8 100644 --- a/nix/hosts/corrino/www/photo.emile.space.nix +++ b/nix/hosts/corrino/www/photo/photoprism.nix @@ -17,7 +17,7 @@ enable = true; address = "127.0.0.1"; - port = config.emile.ports.photo; + port = config.emile.ports.photo.photoprism; passwordFile = config.age.secrets.photoprism_password.path; diff --git a/nix/hosts/corrino/www/r2wa.rs.nix b/nix/hosts/corrino/www/r2wa.rs.nix index f7a0a7e..7da11e1 100644 --- a/nix/hosts/corrino/www/r2wa.rs.nix +++ b/nix/hosts/corrino/www/r2wa.rs.nix @@ -1,16 +1,37 @@ -{ ... }: +{ config, pkgs, ... }: { services.nginx.virtualHosts."r2wa.rs" = { forceSSL = true; enableACME = true; - # kTLS = true; - locations = { "/" = { - return = "301 http://emile.space/blog/2020/r2wars/"; + proxyPass = "http://127.0.0.1:${toString config.emile.ports.r2wars-web}"; }; }; }; + + environment.systemPackages = with pkgs; [ radare2 ]; + + # deploy: + # - push code + # - build in order to get the new hash (nix build .#r2war-sweb) + # - update hash in the package (//nix/pkgs/r2wars-web/default.nix) + # - deploy + + services.emile.r2wars-web = { + enable = true; + + host = "127.0.0.1"; + port = config.emile.ports.r2wars-web; + + # TODO(emile): change these when going live + sessionKey = "insecuretmpkey"; + salt = "insecuresalt"; + + logfilePath = "/var/lib/r2wars/r2wars.log"; + databasePath = "/var/lib/r2wars/main.db"; + sessiondbPath = "/var/lib/r2wars/session.db"; + }; } diff --git a/nix/hosts/corrino/www/social.emile.space.nix b/nix/hosts/corrino/www/social.emile.space.nix index 62e1933..9f9a6f1 100644 --- a/nix/hosts/corrino/www/social.emile.space.nix +++ b/nix/hosts/corrino/www/social.emile.space.nix @@ -91,4 +91,11 @@ }; environmentFile = config.age.secrets.gotosocial_environment_file.path; }; + + systemd.services.gotosocial = { + after = [ "authelia-main.service" ]; + serviceConfig = { + Restart = "on-failure"; + }; + }; } diff --git a/nix/hosts/corrino/www/sso.emile.space.nix b/nix/hosts/corrino/www/sso.emile.space.nix index 0f77197..27988fa 100644 --- a/nix/hosts/corrino/www/sso.emile.space.nix +++ b/nix/hosts/corrino/www/sso.emile.space.nix @@ -192,7 +192,7 @@ in { }; totp = { - disable = false; + disable = true; issuer = "sso.emile.space"; algorithm = "sha1"; digits = 6; diff --git a/nix/hosts/gamont/README.md b/nix/hosts/gamont/README.md new file mode 100644 index 0000000..dc77dc0 --- /dev/null +++ b/nix/hosts/gamont/README.md @@ -0,0 +1,3 @@ +# gamont + +The WIFI Cableā¢ diff --git a/nix/hosts/gamont/configuration.nix b/nix/hosts/gamont/configuration.nix new file mode 100644 index 0000000..4ea1678 --- /dev/null +++ b/nix/hosts/gamont/configuration.nix @@ -0,0 +1,127 @@ +{ config, pkgs, lib, ... }: + +let + user = "nixos"; + password = ""; + SSID = "%p%p%p"; + SSIDpassword = ""; + interface = "wlan0"; + hostname = "gamont"; + keys = [ + "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPZi43zHEsoWaQomLGaftPE5k0RqVrZyiTtGqZlpWsew emile@caladan" + "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEzLZ56SEgwZZ0OusTdSDDhpMlxSg1zPNdRLuxKOfrR5 emile@chusuk" + ]; +in { + + boot = { + kernelPackages = pkgs.linuxKernel.packages.linux_rpi4; + kernel.sysctl = { + "net.ipv4.conf.all.forwarding" = true; + }; + initrd.availableKernelModules = [ "xhci_pci" "usbhid" "usb_storage" ]; + loader = { + grub.enable = false; + generic-extlinux-compatible.enable = true; + }; + }; + + fileSystems = { + "/" = { + device = "/dev/disk/by-label/NIXOS_SD"; + fsType = "ext4"; + options = [ "noatime" ]; + }; + }; + + networking = { + hostName = hostname; + wireless = { + enable = true; + networks."${SSID}".psk = SSIDpassword; + interfaces = [ interface ]; + }; + + firewall = { + allowedTCPPorts = [ 53 ]; + allowedUDPPorts = [ 53 ]; + }; + + interfaces.end0 = { + ipv4.addresses = [ { address = "192.168.1.1"; prefixLength = 24; } ]; + }; + + nftables = { + enable = true; + ruleset = '' + table inet filter { + chain input { + type filter hook input priority 0; + accept + } + + chain output { + type filter hook output priority 0; + accept + } + + chain forward { + type filter hook forward priority 0; + accept + } + } + + table ip nat { + chain postrouting { + type nat hook postrouting priority srcnat; policy accept; + masquerade + } + } + ''; + }; + }; + + environment.systemPackages = with pkgs; [ + helix + vim + dnsmasq + tcpdump + curl + iptables nftables + ]; + + services = { + openssh.enable = true; + dnsmasq = { + enable = true; + settings = { + server = [ + "8.8.8.8" + "8.8.4.4" + ]; + dhcp-authoritative = true; + domain-needed = true; + dhcp-range = [ "192.168.1.10,192.168.1.254" ]; + + interface = [ "end0" ]; + + }; + }; + }; + + users = { + mutableUsers = false; + users."${user}" = { + isNormalUser = true; + password = password; + extraGroups = [ "wheel" ]; + openssh.authorizedKeys.keys = keys; + }; + + users.root = { + openssh.authorizedKeys.keys = keys; + }; + }; + + hardware.enableRedistributableFirmware = true; + system.stateVersion = "23.11"; +} diff --git a/nix/hosts/lampadas/configuration.nix b/nix/hosts/lampadas/configuration.nix index ae3af87..2453a88 100644 --- a/nix/hosts/lampadas/configuration.nix +++ b/nix/hosts/lampadas/configuration.nix @@ -54,6 +54,11 @@ in { networking = { hostName = "lampadas"; firewall.enable = true; + + # iperf + firewall.allowedTCPPorts = [ 5201 ]; + firewall.allowedUDPPorts = [ 5201 ]; + nameservers = [ "8.8.8.8" "8.8.4.4" "1.1.1.1"]; }; diff --git a/nix/hosts/lernaeus/configuration.nix b/nix/hosts/lernaeus/configuration.nix index 9522b76..cfbc35f 100644 --- a/nix/hosts/lernaeus/configuration.nix +++ b/nix/hosts/lernaeus/configuration.nix @@ -44,6 +44,10 @@ in { networking = { hostName = "lernaeus"; firewall.enable = true; + + # iperf + firewall.allowedTCPPorts = [ 5201 ]; + firewall.allowedUDPPorts = [ 5201 ]; }; time.timeZone = "Europe/Berlin"; diff --git a/nix/hosts/pi1/result b/nix/hosts/pi1/result new file mode 120000 index 0000000..8da9c2f --- /dev/null +++ b/nix/hosts/pi1/result @@ -0,0 +1 @@ +/nix/store/k4i56ilirmnfdg0izgpq40hwz45x2lmw-nixos-sd-image-23.05pre482756.12ba1a5f90b-armv6l-linux.img-armv6l-unknown-linux-gnueabihf \ No newline at end of file diff --git a/nix/hosts/pi2/default.nix b/nix/hosts/pi2/default.nix new file mode 100644 index 0000000..939027f --- /dev/null +++ b/nix/hosts/pi2/default.nix @@ -0,0 +1,47 @@ +# build the sd image for the pi using +# ; nix-build '<nixpkgs/nixos>' -A config.system.build.sdImage -I nixos-config='./default.nix' + +# after booting +# ; nix-channel --list +# ; nix-channel --remove nixos +# ; nix-channel --add https://channels.nixos.org/nixos-unstable nixos +# ; nix-channel --update nixos +# (this takes quite some time) +# ; nixos-rebuild switch + +{ lib, pkgs, ... }: + +{ + imports = [ + <nixpkgs/nixos/modules/installer/sd-card/sd-image-raspberrypi.nix> + # <nixpkgs/nixos/modules/installer/sd-card/sd-image-armv7l-multiplatform.nix> + # <nixpkgs/nixos/modules/installer/sd-card/sd-image-aarch64-installer.nix> + + # For nixpkgs cache + # <nixpkgs/nixos/modules/installer/cd-dvd/channel.nix> + ]; + + users.users = { + emile = { + isNormalUser = true; + hashedPassword = "$y$j9T$gKt6Iovrn.SAkMxnTCqqV1$55.sKRrjWTbe7Z6Xi17G0e3G7GbAGc65YXtX9zD5AR3"; + extraGroups = [ "wheel" ]; + }; + }; + + nixpkgs = { + # crossSystem = lib.systems.examples.raspberryPi; + crossSystem = lib.systems.examples.armv7l-hf-multiplatform; + # localSystem = { system = "x86_64-linux"; }; + localSystem = { system = "aarch64-darwin"; }; + overlays = [ + (final: super: { + # Due to https://github.com/NixOS/nixpkgs/issues/154163#issuecomment-1350599022 + makeModulesClosure = x: + super.makeModulesClosure (x // { allowMissing = true; }); + }) + ]; + }; + system.stateVersion = "24.05"; +} + diff --git a/nix/hosts/pi2/result b/nix/hosts/pi2/result new file mode 120000 index 0000000..8da9c2f --- /dev/null +++ b/nix/hosts/pi2/result @@ -0,0 +1 @@ +/nix/store/k4i56ilirmnfdg0izgpq40hwz45x2lmw-nixos-sd-image-23.05pre482756.12ba1a5f90b-armv6l-linux.img-armv6l-unknown-linux-gnueabihf \ No newline at end of file |