diff --git a/about/research-artifacts.md b/about/research-artifacts.md index 866e3bb..e570f27 100644 --- a/about/research-artifacts.md +++ b/about/research-artifacts.md @@ -6,7 +6,7 @@ author: Chora Studio title: Research Artifacts description: A brief introduction to research artifacts. created: 2026-11-15 -updated: 2026-11-16 +updated: 2026-11-18 --- # Research Artifacts @@ -23,9 +23,9 @@ The immediate subdirectory (`artifacts`) is also a Git repository, so changes to The second repository (`website`) is the source code for a website (`https://chora.studio`) and it also has a remote repository (`https://github.com/chora-studio/website`). The first repository (`artifacts`) is a submodule (`artifacts`) in the second repository (`website`), so when changes are pushed from the first repository (`artifacts`), the submodule (`artifacts`) must pull those changes before the code in the second repository (`website`) is compiled. - The source code for the website is written in a way that all markdown files within the Git submodule (`artifacts`) are compiled as web pages when the source code is compiled. The compiled source code is pushed to a branch on the remote repository that automatically deploys the website including all the compiled research artifacts in the form of web pages. The source code also includes an [index page](../) for the research artifacts. + The source code for the website is written in a way that all markdown files within the Git submodule (`artifacts`) are compiled as web pages when the source code is compiled. The compiled source code is pushed to a branch on the remote repository that automatically deploys the website including all the compiled research artifacts in the form of web pages. The source code also compiles an [index page](../) for the research artifacts. - So back from the start, the research artifacts are written as markdown files (a widely supported and portable format), changes to those files are tracked with Git and pushed to a remote repository (tracking changes are important for several reasons), and then those changes are pulled into a submodule in another repository and compiled and deployed as web pages. + So back from the start, the research artifacts are written as markdown files (a widely supported and portable format), changes to those files are tracked with Git and pushed to a remote repository (tracking changes is important for several reasons), and then those changes are pulled into a submodule in another repository and compiled and deployed as web pages. ## Feeding The Artifacts diff --git a/tutorials/self-hosted-servers.md b/tutorials/self-hosted-servers.md new file mode 100644 index 0000000..b7b502f --- /dev/null +++ b/tutorials/self-hosted-servers.md @@ -0,0 +1,277 @@ +--- +type: artifact +category: tutorial +status: active +author: Chora Studio +title: Self-Hosted Servers +description: A tutorial on self-hosted servers. +created: 2026-11-18 +updated: 2026-11-18 +--- + +# Self-Hosted Servers + +This is a tutorial for a self-hosted server. This is an **experimental** setup that is still being tested and is **not production ready**. + +## Prerequisites + +#### Software + +- Nix + +#### Hardware + +- Raspberry Pi 4 Model B +- SD Card (San Disk recommended) + +#### Services + +- Cloudflare (with a purchased domain) + +## Installing Nixos + +Insert SD card into computer and proceed with the following steps. + +#### 1. Download the latest SD card image + +``` +https://hydra.nixos.org/job/nixos/release-25.11/nixos.sd_image.aarch64-linux +``` + +#### 2. Decompress the downloaded SD card image + +``` +nix-shell -p zstd --run "unzstd .img.zst" +``` + +#### 3. Write the downloaded image to the SD card + +``` +sudo dd if=.img of=/dev/mmcblk0 bs=10MB oflag=dsync status=progress +``` + +## Setting Up Nixos + +Insert SD card into Raspberry Pi and proceed with the following steps. + +#### 1. Connect with WiFi (or ethernet) + +``` +nmtui +``` + +#### 2. Generate Nixos configuration files + +``` +sudo nixos-generate-config +``` + +#### 3. Update Nixos configuration file + +``` +nano /etc/nixos/configuration.nix +``` + +```nix +{ config, lib, pkgs, ... }: + +{ + imports = [ ./hardware-configuration.nix ]; + + boot.loader.grub.enable = false; + boot.loader.generic-extlinux-compatible.enable = true; + + networking = { + hostName = "raspberrypi"; + firewall = { + allowedTCPPorts = [ 22 ]; + }; + networkmanager = { + enable = true; + wifi.powersave = false; + }; + }; + + users.users.user = { + isNormalUser = true; + extraGroups = [ "wheel" "networkmanager" ]; + initialPassword = "password"; + }; + + services.openssh = { + enable = true; + openFirewall = true; + }; + + system.stateVersion = "25.11"; +} +``` + +#### 4. Rebuild and reboot + +``` +nixos-rebuild switch +``` + +``` +reboot +``` + +## SSH Access and Security + +Start from computer and proceed with Raspberry Pi (following step 3). + +#### 1. Generate SSH key (if none) + +``` +ssh-keygen -t ed25519 +``` + +#### 2. Copy SSH key to Raspberry Pi + +``` +ssh-copy-id user@ +``` + +#### 3. Test SSH with password authentication + +``` +ssh user@ +``` + +#### 4. Disable SSH password authentication + +```nix + services.openssh = { + enable = true; + openFirewall = true; + settings = { + PermitRootLogin = "no"; + PasswordAuthentication = false; + }; + }; +``` + +#### 5. Change to more secure password + +``` +passwd +``` + +#### 6. Rebuild and reboot + +``` +sudo nixos-rebuild switch +``` + +``` +sudo reboot +``` + +## Add Cloudflared and Caddy + +Proceed with Cloudflare website and Raspberry Pi. + +#### 1. Set up Cloudflare tunnel + +... + +#### 2. Update Nixos configuration + +```nix + imports = [ + ./hardware-configuration.nix + ./website-configuration.nix + ]; +``` + +```nix + users.groups.cloudflared = { }; + users.users.cloudflared = { + group = "cloudflared"; + isSystemUser = true; + }; +``` + +```nix + services.cloudflared = { + enable = true; + tunnels.example = { + credentialsFile = "/etc/cloudflared/credentials.json"; + ingress = { + "example.com" = "http://localhost:8000"; + }; + default = "http_status:404"; + }; + }; +``` + +```nix +{ config, pkgs, ... }: + +let + caddyConfig = pkgs.writeText "Caddyfile" '' + :8000 { + root * /home/user/website/dist + encode gzip zstd + try_files {path} {path}/index.html {path}.html {path}/ /index.html + file_server + } + ''; +in +{ + systemd.services.website = { + description = "website"; + after = [ "network.target" ]; + wants = [ "network.target" ]; + serviceConfig = { + ExecStart = "${pkgs.caddy}/bin/caddy run --config ${caddyConfig} --adapter caddyfile"; + Restart = "always"; + RestartSec = "5"; + }; + }; +} +``` + +#### 3. Test Cloudflare tunnel + +... + +## Add Forgejo + +Proceed with Raspberry Pi. + +#### 1. Update NixOS configuration + +```nix + ingress = { + "example.com" = "http://localhost:8000"; + "git.example.com" = "http://localhost:3000"; + }; +``` + +```nix + services.forgejo = { + enable = true; + database.type = "sqlite3"; + settings.server.DOMAIN = "git.example.com"; + settings.server.ROOT_URL = "https://git.example.com/"; + settings.server.DISABLE_SSH = true; + settings.service.DISABLE_REGISTRATION = true; + settings.security.REVERSE_PROXY_TRUSTED_PROXIES = "127.0.0.1/32"; + }; +``` + +#### 2. Create Admin User + +``` +sudo -u forgejo FORGEJO_WORK_DIR=/var/lib/forgejo forgejo admin user create --username user --email user@example.com --password password +``` + +#### 3. Test Forgejo + +... + +## References + +- https://nixos.wiki/wiki/NixOS_on_ARM#Installation