[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-108604":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":8,"htmlUrl":8,"language":9,"languages":8,"totalLinesOfCode":8,"stars":10,"forks":11,"watchers":12,"openIssues":13,"contributorsCount":13,"subscribersCount":13,"size":13,"stars1d":12,"stars7d":14,"stars30d":15,"stars90d":13,"forks30d":13,"starsTrendScore":16,"compositeScore":17,"rankGlobal":8,"rankLanguage":8,"license":18,"archived":19,"fork":19,"defaultBranch":20,"hasWiki":19,"hasPages":19,"topics":21,"createdAt":8,"pushedAt":22,"updatedAt":23,"readmeContent":24,"aiSummary":25,"trendingCount":13,"starSnapshotCount":13,"syncStatus":26,"lastSyncTime":27,"discoverSource":28},108604,"nixos-vps","dreamsofcode-io\u002Fnixos-vps","dreamsofcode-io",null,"Python",140,15,1,0,10,65,3,54.11,"MIT License",false,"main",[],"2026-11-04 17:21:22","2026-11-23 11:20:51","# NixOS VPS\n\nA starting configuration for a NixOS VPS, with optional Tailscale and Cloudflare Tunnel integration.\n\n## Table of contents\n\n1. [Quick start](#quick-start)\n2. [Setup](#setup)\n3. [Deploying a service](#deploying-a-service)\n4. [Managing secrets](#managing-secrets)\n5. [Enabling Tailscale](#enabling-tailscale)\n6. [Cloudflare Tunnel](#cloudflare-tunnel)\n7. [Local building on macOS](#local-building-on-macos)\n8. [Building on a separate machine](#building-on-a-separate-machine)\n9. [Trusted builds](#trusted-builds)\n\n## Quick start\n\nThis assumes a provisioned **x86_64 NixOS VPS matching the Hostinger template**,\nroot SSH access, and [Nix, Git, Bash, and an editor](#requirements) on your local\nmachine. Replace `x.x.x.x` with the VPS's public IP address. Run these commands\nlocally from the repository directory.\n\n### 1. Clone and prepare your tools\n\n```sh\ngit clone https:\u002F\u002Fgithub.com\u002Fdreamsofcode-io\u002Fnixos-vps.git\ncd nixos-vps\n```\n\nStart a shell containing just, and use it for the remaining commands:\n\n```sh\nnix shell nixpkgs#just\n```\n\nSelect an editor installed on your machine:\n\n```sh\nexport EDITOR=nano\n```\n\nCheck root access and verify the host\nfingerprint against your provider's console:\n\n```sh\nssh root@x.x.x.x true\n```\n\n### 2. Set your admin credentials\n\nGenerate a password hash, then edit the settings:\n\n```sh\nnix run nixpkgs#mkpasswd -- --method=yescrypt\n\"$EDITOR\" settings.nix\n```\n\nAdd your SSH **public** key to `sshKeys` and paste the generated hash into\n`hashedPassword`. Keep `hostname` as `vps`, public access enabled, and both\noptional services disabled for this first deployment. Remember the password:\nit is used for sudo. See [Prepare your configuration](#2-prepare-your-configuration).\n\n### 3. Create the encrypted secrets store\n\n```sh\njust bootstrap vps root@x.x.x.x\ngit add secrets\u002Fvps.json\n```\n\nClose the editor with the empty JSON object if you have no secrets yet. Back up\nthe local age key outside the repository as described in [Bootstrap secrets](#3-bootstrap-secrets).\n\n### 4. Choose a builder and deploy\n\nKeep a root SSH session open in another terminal until you have verified the\nnew admin login. The first deployment disables new root SSH logins and creates\nthe configured admin account.\n\nFor native x86_64 Linux, or a local Nix installation with a configured\n`x86_64-linux` builder:\n\n```sh\njust deploy root@x.x.x.x\n```\n\nFor macOS or ARM Linux without a configured Linux builder, use a separate\nx86_64 Linux machine with Nix and SSH access. Replace `zenbox` with that\nmachine's SSH address:\n\n```sh\njust deploy root@x.x.x.x vps zenbox\n```\n\nYou can instead set up a [local macOS Linux VM](#local-building-on-macos).\n\n### 5. Verify admin access and reboot\n\n```sh\nssh admin@x.x.x.x 'whoami; hostname'\n```\n\nThe command should print `admin` and `vps`. Once that succeeds, reboot:\n\n```sh\nssh -t admin@x.x.x.x 'sudo reboot'\n```\n\nOnce the VPS restarts, reconnect and check it:\n\n```sh\nssh admin@x.x.x.x 'uname -r; systemctl --failed --no-pager'\n```\n\nSetup is complete when admin SSH works and no failed units are listed.\nContinue with [Deploying a service](#deploying-a-service) for Docker or systemd\nexamples, or [Managing secrets](#managing-secrets) for application credentials.\nFor later deployments, use `admin` and keep the third builder argument if you\nselected a separate machine.\n\n## Setup\n\n### Requirements\n\nOn your local machine, you need:\n\n- **Nix**, with `nix-command` and `flakes` enabled. Nix can be installed on any\n  standard Linux distribution; your local machine does not need to run NixOS.\n  On **macOS**, follow the\n  [Lix installation instructions](https:\u002F\u002Flix.systems\u002Finstall\u002F). Lix provides\n  the `nix` command used throughout this guide.\n- **just**, to run the bootstrap and deployment recipes. With Nix installed,\n  start a shell containing it:\n\n  ```sh\n  nix shell nixpkgs#just\n  ```\n\n  Run the guide's commands from that shell.\n- **Git**, **Bash**, and an **SSH client**, plus SSH access to your VPS.\n- A terminal editor available through `EDITOR` or `SOPS_EDITOR` for managing\n  secrets. For example:\n\n  ```sh\n  export EDITOR=nano\n  ```\n\nCheck that Nix and just are available:\n\n```sh\nnix --version\njust --version\n```\n\nThe bootstrap recipe obtains SOPS and the age tools through Nix; you do not\nneed to install them separately. Deployment builds through your local Nix\ninstallation by default. This flake targets `x86_64-linux`: native x86_64 Linux\ncan build directly; macOS or ARM Linux needs a suitable Linux VM, emulation,\nor a configured Nix builder. To build on a separate Linux machine instead,\npass its SSH address as the third deployment argument:\n\n```sh\njust deploy admin@vps vps zenbox\n```\n\nSee [Building on a separate machine](#building-on-a-separate-machine).\n\n### 1. Obtain a NixOS instance\n\nYou need a VPS running NixOS. For the Hostinger VPS used in the video, visit\n[hostinger.com\u002Fdreamsofcode](https:\u002F\u002Fhostinger.com\u002Fdreamsofcode) and select NixOS\nas the operating system when provisioning your server.\n\nUse coupon code `DREAMSOFCODE` at checkout for 10% off.\n\nOnce the server is ready, note its public IP address and confirm that you can\nconnect using the SSH credentials configured during provisioning.\n\nThe included `vps_configuration.nix` targets the Hostinger NixOS template on\nan x86_64 VPS. If you use another provider, adapt the boot, storage, and network\nsettings to match your instance before deploying this configuration.\n\n### 2. Prepare your configuration\n\nClone the repository on your local machine:\n\n```sh\ngit clone https:\u002F\u002Fgithub.com\u002Fdreamsofcode-io\u002Fnixos-vps.git\ncd nixos-vps\n```\n\nRun the remaining commands from this directory unless noted otherwise.\n\nEdit `settings.nix` before deploying. This is the main place to configure your server:\n\n- Add your public SSH key to `sshKeys`. For example, copy the contents of\n  `~\u002F.ssh\u002Fid_ed25519.pub` into a quoted entry in that list. Use your public\n  key (`.pub`), never your private key. The list starts empty; add your key\n  before deploying so you can log in as `admin`.\n- Generate an admin password hash:\n\n  ```sh\n  nix run nixpkgs#mkpasswd -- --method=yescrypt\n  ```\n\n  Put the result in `hashedPassword`. Do not leave it empty. You will use this\n  password for sudo; SSH login uses your key.\n- Set `hostname`. The examples below use `\"vps\"`.\n- Keep public access until you have confirmed that Tailscale is connected and\n  you can SSH through it:\n\n  ```nix\n  access = \"public\";\n  ```\n\nThe build fails unless the admin account has both a non-empty password hash and\nat least one non-empty SSH public key. Whitespace-only values and the locked\npassword markers `!`, `!!`, and `*` do not satisfy these requirements.\n\n### 3. Bootstrap secrets\n\nBootstrap an encrypted secrets file for every VPS before its first deployment,\neven if you are not enabling Tailscale or Cloudflare Tunnel yet:\n\n```sh\njust bootstrap vps root@x.x.x.x\n```\n\nReplace `x.x.x.x` with your VPS's public IP address. Use an account that already\nexists on the server; `root` is shown for an initial deployment. If `admin`\nalready exists, use `admin@x.x.x.x` instead. Verify the SSH host fingerprint\nwhen connecting for the first time.\n\nThe first argument is `hostname` from `settings.nix`. Bootstrap uses it to\nname `secrets\u002Fvps.json`; it does not evaluate the NixOS configuration.\n\nThe command creates or reuses a local age key at\n`${XDG_CONFIG_HOME:-~\u002F.config}\u002Fsops\u002Fage\u002Fkeys.txt` (or `SOPS_AGE_KEY_FILE`, if set),\nreads the VPS's public SSH host key, and opens SOPS in your editor. New secrets\nfiles are encrypted for both your local age key and the VPS host key. Keep a\nbackup of your local private age key outside this repository.\n\nNew files start as an empty JSON object:\n\n```json\n{}\n```\n\nLeave it empty if you do not have secrets to add yet, or add JSON entries for\nyour applications. Close the editor to finish; making no changes is valid.\n\nIf you are enabling an optional service now, add its credentials too:\n\n- `tailscale-auth-key`: your Tailscale auth key as a JSON string.\n- `cloudflared-\u003Ctunnel-uuid>.json`: the tunnel credentials JSON encoded as a\n  JSON string, with `\u003Ctunnel-uuid>` matching `cloudflared.tunnelId` in `settings.nix`.\n\nSave and close the editor. Enable optional services using the\n[Tailscale](#enabling-tailscale) or [Cloudflare Tunnel](#cloudflare-tunnel)\ninstructions when needed. Stage the encrypted file so the Git-backed flake\nincludes it:\n\n```sh\ngit add secrets\u002Fvps.json\n```\n\nRunning bootstrap again edits the existing file without changing its encryption\nrecipients. Keep this file as the server's secrets store and add credentials as\nyou deploy services; see [Managing secrets](#managing-secrets).\n\n### 4. Deploy\n\nFor the first deployment, use the provisioned root account:\n\n```sh\njust deploy root@x.x.x.x\n```\n\nIf using a separate builder, pass its address as the third argument:\n\n```sh\njust deploy root@x.x.x.x vps zenbox\n```\n\nThis builds the `vps` flake configuration, copies its runtime closure to the\nVPS, and activates it there. Local building is the default. Keep the builder\nargument on every deployment if you selected a separate machine. The flake\nconfiguration name stays `vps` even if you change `hostname` in `settings.nix`.\n\nThe first deployment creates `admin` and disables new root SSH logins. Keep an\nexisting root session open in another terminal and verify the new account:\n\n```sh\nssh admin@x.x.x.x 'whoami; hostname'\n```\n\nOnce admin access works, use it for subsequent deployments:\n\n```sh\njust deploy admin@x.x.x.x\n```\n\nActivation prompts for the admin sudo password. The transfer uses `ssh-ng` and\ncache substitution to reduce copying over SSH. The configuration trusts `admin`\nto import the selected builder's unsigned outputs; see [Trusted builds](#trusted-builds).\nActivation runs the VPS's own `nixos-rebuild` with `--no-reexec` and the already-built\nsystem path.\n\nAfter the first deployment, reboot the VPS to boot into the newly installed\nkernel. Deployment activates the configuration, but the running kernel does\nnot change until a reboot. Once you have verified SSH access as `admin`, run:\n\n```sh\nssh -t admin@x.x.x.x 'sudo reboot'\n```\n\nThe SSH connection will close. Wait for the instance to restart, then reconnect:\n\n```sh\nssh admin@x.x.x.x 'uname -r; systemctl --failed --no-pager'\n```\n\nUse the Tailscale address instead if public SSH access is disabled. Reboot\nafter future kernel updates as well to start using the updated kernel.\n\n### Adding another server\n\nCreate a separate settings file:\n\n```sh\nmkdir -p hosts\ncp settings.nix hosts\u002Fvps2.nix\n```\n\nEdit `hosts\u002Fvps2.nix` and set its hostname to `vps2`. Customize the SSH keys,\npassword hash, and services for that server. Add this entry to\n`nixosConfigurations` in `flake.nix`:\n\n```nix\nvps2 = mkVps (import .\u002Fhosts\u002Fvps2.nix) [];\n```\n\nBootstrap the new server's secrets, stage both new files, and deploy using its\nprovisioned account:\n\n```sh\njust bootstrap vps2 root@NEW_VPS_IP\ngit add hosts\u002Fvps2.nix secrets\u002Fvps2.json\njust deploy root@NEW_VPS_IP vps2\n```\n\nReplace `NEW_VPS_IP` with the new server's IP, and include your builder as the\nthird deployment argument if needed. Verify admin access and reboot as in the\nfirst-server instructions. Subsequent deployments use:\n\n```sh\njust deploy admin@NEW_VPS_IP vps2\n```\n\nStage any new Nix modules or encrypted secrets files before deploying. Builds\ninclude changes to tracked files even when they have not yet been committed.\n\n## Deploying a service\n\nAfter setup, define services in Nix and use the deployment recipe to apply changes.\nHere is where each part belongs:\n\n| Path | Purpose |\n| --- | --- |\n| `settings.nix` | Hostname, admin access, and optional-service switches |\n| `configuration.nix` | Imports modules and configures the base system |\n| `modules\u002Fcontainers.nix` | Docker or Podman container definitions; already imported |\n| `services\u002F` | Automatically imported application and optional-service modules |\n| `modules\u002F` | Automatically imported base-system modules |\n| `secrets\u002F\u003Chostname>.json` | Encrypted application and service credentials |\n\n`configuration.nix` imports `services\u002F` and `modules\u002F` through their\n`default.nix` files. They automatically discover sibling `.nix` files and\nsubdirectories containing a `default.nix`, in filename order. Each directory's\nown `default.nix` is excluded from discovery.\n\nPut application modules in `services\u002F` and shared system modules in `modules\u002F`.\nNew modules must be staged in Git before deployment; no imports-list edit is\nneeded. Every discovered module is evaluated, so optional services should use\nan enable option to control whether they run. To keep a file out of discovery,\nmove it outside these directories or use a non-`.nix` extension.\n\n`services\u002F` already contains the Tailscale and Cloudflare modules. Container\ndefinitions can also live here if you prefer one file per application. The\nDocker example below uses the existing `modules\u002Fcontainers.nix`; the systemd\nexample adds a module in `services\u002F`.\n\nThe examples below are alternatives: each runs a web server on\n`127.0.0.1:8080`. Choose one, or assign different ports if using both.\n\n### Docker\n\nReplace the contents of `modules\u002Fcontainers.nix` with:\n\n```nix\n{ ... }: {\n  virtualisation.oci-containers = {\n    backend = \"docker\";\n    containers.web = {\n      image = \"nginx:stable\";\n      ports = [\"127.0.0.1:8080:80\"];\n    };\n  };\n}\n```\n\nNixOS enables Docker and creates `docker-web.service` to run the container.\nFor your own application, replace the image and container port, and add persistent\nvolumes if it stores data. To use Podman instead, change the backend:\n\n```nix\nvirtualisation.oci-containers.backend = \"podman\";\n```\n\nIts unit is named `podman-web.service`.\n\n### systemd\n\nFor a process running directly on the host, create `services\u002Fexample-web.nix`:\n\n```nix\n{ pkgs, ... }: {\n  systemd.services.example-web = {\n    description = \"Example web server\";\n    wantedBy = [\"multi-user.target\"];\n    after = [\"network.target\"];\n    serviceConfig = {\n      ExecStart = \"${pkgs.python3}\u002Fbin\u002Fpython -m http.server 8080 --bind 127.0.0.1\";\n      DynamicUser = true;\n      StateDirectory = \"example-web\";\n      WorkingDirectory = \"\u002Fvar\u002Flib\u002Fexample-web\";\n      Restart = \"on-failure\";\n    };\n  };\n}\n```\n\nThe module is discovered automatically. Stage the new file so the Git-backed\nflake can include it:\n\n```sh\ngit add services\u002Fexample-web.nix\n```\n\nReplace the example command with your application's executable and arguments.\nPrefer a built-in NixOS service module when your application has one; it usually\nhandles users, directories, and service configuration for you. Those options\ncan also live in an automatically discovered module under `services\u002F`.\n\n### Apply and inspect changes\n\nAfter editing the container definition or staging your new service module,\ndeploy from your local machine:\n\n```sh\njust deploy admin@x.x.x.x\n```\n\nIf you selected a separate builder during setup, use this instead:\n\n```sh\njust deploy admin@x.x.x.x vps zenbox\n```\n\nAfter deployment, test the server:\n\n```sh\nssh admin@x.x.x.x 'curl http:\u002F\u002F127.0.0.1:8080'\n```\n\nThe Docker example returns the nginx welcome page; the systemd example returns\na directory listing. Both should return an HTTP response.\n\nTo inspect the Docker example on the VPS:\n\n```sh\nsudo systemctl status docker-web.service\nsudo journalctl -u docker-web.service -n 50 --no-pager\n```\n\nUse `example-web.service` for the systemd example. Both examples listen only on\nlocalhost. To reach them from your local machine during development:\n\n```sh\nssh -L 8080:127.0.0.1:8080 admin@x.x.x.x\n```\n\nOpen `http:\u002F\u002F127.0.0.1:8080` locally while that connection is open. To publish the\napplication, follow [Cloudflare Tunnel](#cloudflare-tunnel). Add application\ncredentials using [Managing secrets](#managing-secrets).\n\n### Update or remove a service\n\nTo update a container, change its image tag or digest and deploy again. To update\na host service, change its module or package input and deploy again. Editing\nfiles locally does not change the running VPS until you deploy.\n\nTo remove a container, remove its definition from `modules\u002Fcontainers.nix`. To\nremove an application module, delete its file from `services\u002F` and stage the\ndeletion. Deploy again to stop and remove the service. Existing data is governed\nby its storage configuration; container volumes and systemd state directories\nare not deleted by removing the module.\n\n## Managing secrets\n\nSetup creates `secrets\u002F\u003Chostname>.json`, encrypted for your local age key and the\nVPS's SSH host key. Keep application passwords, API tokens, and service\ncredentials here. Nix contains secret names and runtime paths; secret values\nstay in SOPS until they are decrypted on the VPS.\n\n### Add or edit secrets\n\nReopen the server's secrets file using the same bootstrap command:\n\n```sh\njust bootstrap vps admin@x.x.x.x\n```\n\nUse your configured hostname and current SSH address, including the Tailscale\naddress if public access is disabled. Add entries without removing existing\nones. For example:\n\n```json\n{\n  \"api-key\": \"YOUR_APPLICATION_API_KEY\",\n  \"app-env\": \"API_KEY=YOUR_APPLICATION_API_KEY\\n\"\n}\n```\n\nThese illustrate two ways to supply credentials; use the format your application\nexpects. SOPS encrypts the values when you save. Only the encrypted file belongs\nin Git; do not put plaintext credentials in Nix files or container `environment`.\n\n### Give a service access to a secret\n\nFor an existing systemd service called `my-app`, add this inside the module body\nin `configuration.nix` (which already accepts `config`):\n\n```nix\nsops.secrets.api-key = {\n  restartUnits = [\"my-app.service\"];\n};\n\nsystemd.services.my-app.serviceConfig.LoadCredential =\n  \"api-key:${config.sops.secrets.api-key.path}\";\n```\n\nSOPS decrypts the value to `\u002Frun\u002Fsecrets\u002Fapi-key`, readable only by root by\ndefault. systemd gives the service its own credential file at\n`$CREDENTIALS_DIRECTORY\u002Fapi-key`. Configure the application to read that file;\n`LoadCredential` does not create an environment variable containing the value.\nThe service restarts when the secret changes.\n\nFor an existing Docker container called `my-app`, use the `app-env` entry as an\nenvironment file. Declare it in `configuration.nix`:\n\n```nix\nsops.secrets.app-env = {\n  restartUnits = [\"docker-my-app.service\"];\n};\n\nvirtualisation.oci-containers.containers.my-app.environmentFiles = [\n  config.sops.secrets.app-env.path\n];\n```\n\nThe container must already have an image configured in `modules\u002Fcontainers.nix`. Docker\nloads the decrypted file as environment variables when it starts the container.\nFor Podman, use `podman-my-app.service` in `restartUnits` instead.\n\nStage the encrypted file and deploy to apply new declarations or changed values:\n\n```sh\ngit add secrets\u002Fvps.json\njust deploy admin@x.x.x.x\n```\n\n### Keep access to your secrets\n\nBack up `${XDG_CONFIG_HOME:-~\u002F.config}\u002Fsops\u002Fage\u002Fkeys.txt` (or your custom\n`SOPS_AGE_KEY_FILE`) outside the repository. It lets you edit and recover secrets\nif the VPS is lost. An encrypted secrets file alone is not enough to recover them.\nBootstrap preserves existing encryption recipients; replacing the VPS or changing\nkeys requires explicitly updating recipients with SOPS. When rotating a service\ncredential, update its value in the editor, save, and deploy again.\n\n## Enabling Tailscale\n\nTailscale is optional. The examples below assume setup is complete and you can\nSSH as `admin`. Replace `vps` with your configured hostname when editing secrets.\n\nInstall Tailscale on your local machine and connect it to your tailnet. Create\nan auth key in the [Tailscale admin console](https:\u002F\u002Flogin.tailscale.com\u002Fadmin\u002Fsettings\u002Fkeys).\nFor one persistent VPS, use a non-ephemeral, single-use key. See\n[Tailscale's auth key documentation](https:\u002F\u002Ftailscale.com\u002Fdocs\u002Ffeatures\u002Faccess-control\u002Fauth-keys)\nfor key options and device approval requirements.\n\nOpen your encrypted secrets file:\n\n```sh\njust bootstrap vps admin@x.x.x.x\n```\n\nAdd the auth key as a top-level JSON entry, preserving any existing secrets:\n\n```json\n{\n  \"tailscale-auth-key\": \"YOUR_TAILSCALE_AUTH_KEY\"\n}\n```\n\nIn `settings.nix`, change the existing settings to:\n\n```nix\ntailscale.enable = true;\naccess = \"public\";\n```\n\nStage the encrypted file and deploy:\n\n```sh\ngit add secrets\u002Fvps.json\njust deploy admin@x.x.x.x\nssh admin@x.x.x.x 'tailscale status; tailscale ip -4'\n```\n\nApprove the device in the Tailscale console if your tailnet requires it. From\nyour local machine, test SSH using the returned Tailscale IP:\n\n```sh\nssh admin@100.x.y.z\n```\n\nThis uses ordinary OpenSSH over Tailscale and the public key in `settings.nix`;\nit does not enable Tailscale SSH. Your tailnet policy must allow the connection.\n\nAfter this works, restrict access in `settings.nix`:\n\n```nix\naccess = \"tailscale\";\n```\n\nDeploy through the Tailscale IP:\n\n```sh\njust deploy admin@100.x.y.z\n```\n\nOpen a new SSH connection through Tailscale to verify access. Future deploy and\nbootstrap commands should use the Tailscale address, or the server's MagicDNS\nname if enabled. This mode closes public host-service ports and trusts the\nTailscale interface; it does not restrict forwarded container traffic or\nprevent Cloudflare Tunnel from publishing an application.\n\n## Cloudflare Tunnel\n\nCloudflare Tunnel is optional and can be enabled after setup.\n\nThis module uses a **locally managed tunnel** with a credentials JSON file,\nnot a dashboard-managed tunnel token. You need a domain on Cloudflare. Follow\n[Cloudflare's locally managed tunnel guide](https:\u002F\u002Fdevelopers.cloudflare.com\u002Fcloudflare-one\u002Fnetworks\u002Fconnectors\u002Fcloudflare-tunnel\u002Fdo-more-with-tunnels\u002Flocal-management\u002Fcreate-local-tunnel\u002F)\nto authorize your account and create a tunnel. On your local machine:\n\n```sh\nnix shell nixpkgs#cloudflared nixpkgs#jq\ncloudflared tunnel login\ncloudflared tunnel create vps\n```\n\nRecord the tunnel UUID and credentials file path printed by the command.\nEncode that file as a JSON string for SOPS (replace the example path):\n\n```sh\njq -Rs . \"$HOME\u002F.cloudflared\u002FTUNNEL_UUID.json\"\n```\n\nOpen your encrypted secrets file:\n\n```sh\njust bootstrap vps admin@x.x.x.x\n```\n\nAdd a top-level entry named `cloudflared-TUNNEL_UUID.json`, replacing\n`TUNNEL_UUID` with the real UUID.\nPaste the entire quoted output from `jq` as its value. Preserve existing\nentries. Only the SOPS-encrypted file belongs in Git; keep the original tunnel\ncredentials and account certificate outside the repository.\n\nUpdate the existing block in `settings.nix`:\n\n```nix\ncloudflared = {\n  enable = true;\n  tunnelId = \"TUNNEL_UUID\";\n};\n```\n\nAdd a route inside the module body in `configuration.nix`, using the same UUID:\n\n```nix\nservices.cloudflared.tunnels.\"TUNNEL_UUID\".ingress = {\n  \"app.example.com\" = \"http:\u002F\u002F127.0.0.1:8080\";\n};\n```\n\nReplace the hostname and upstream address with your application. It must\nalready be running on the VPS at that address. Without ingress routes, the\ntunnel's default response is HTTP 404.\n\nCreate the DNS route from your local machine:\n\n```sh\ncloudflared tunnel route dns TUNNEL_UUID app.example.com\n```\n\nStage the encrypted secrets and deploy using your current SSH address:\n\n```sh\ngit add secrets\u002Fvps.json\njust deploy admin@x.x.x.x\n```\n\nUse the Tailscale address instead if you have restricted host access. Visit\n`https:\u002F\u002Fapp.example.com` to check the application. This publishes the app;\nconfigure application authentication or Cloudflare Access if it should be private.\nTo inspect tunnel logs, run this on the VPS with your real UUID:\n\n```sh\nsudo journalctl -u cloudflared-tunnel-TUNNEL_UUID.service -n 50 --no-pager\n```\n\n## Local building on macOS\n\nNix on macOS cannot natively build the Linux system used by this VPS. You need a\nLinux VM or a separate Linux builder that supports **`x86_64-linux`**. Intel Macs\ncan virtualize that architecture directly. Apple Silicon normally runs an\n`aarch64-linux` VM, so it also needs x86_64 emulation or translation; an ARM Linux\nVM alone is not enough.\n\n### Set up a nix-darwin Linux builder\n\n[nix-darwin provides `nix.linux-builder`](https:\u002F\u002Fgithub.com\u002Fnix-darwin\u002Fnix-darwin\u002Fblob\u002Fmaster\u002Fmodules\u002Fnix\u002Flinux-builder.nix)\nto manage a local Linux builder VM and register it with your Mac's Nix daemon.\nThis requires an existing nix-darwin setup that manages the Nix installation;\nfollow the [upstream builder prerequisites](https:\u002F\u002Fgithub.com\u002FNixOS\u002Fnixpkgs\u002Fblob\u002Fmaster\u002Fdoc\u002Fpackages\u002Fdarwin-builder.section.md).\n\nFirst, add this to **your Mac's nix-darwin configuration**, keeping the builder's\ndefault configuration for its initial bootstrap:\n\n```nix\nnix.linux-builder.enable = true;\n```\n\nApply your Mac's configuration with its usual command, for example:\n\n```sh\nsudo darwin-rebuild switch --flake \u002Fpath\u002Fto\u002Fyour\u002Fmac-config#YOUR_MAC_NAME\n```\n\nOn an Intel Mac, the default builder supports `x86_64-linux`. On Apple Silicon,\nget the default ARM Linux builder running first, then add these options to your\nMac's configuration and apply it again:\n\n```nix\nnix.linux-builder.systems = [\"aarch64-linux\" \"x86_64-linux\"];\nnix.linux-builder.config.boot.binfmt.emulatedSystems = [\"x86_64-linux\"];\n```\n\nThis advertises x86_64 support to the Mac's Nix daemon and enables emulation\ninside the Linux VM. Merely adding `x86_64-linux` to the advertised systems does\nnot enable emulation. Keep the initial bootstrap separate from this customization\nso the default builder can build the customized VM.\n\n### Verify and deploy\n\nFrom this repository on your Mac, run a small Linux build that cannot be\nsubstituted from a cache:\n\n```sh\nnix build --impure --no-link --print-build-logs --expr '\n  let\n    flake = builtins.getFlake (toString .\u002F.);\n    pkgs = flake.inputs.nixpkgs.legacyPackages.x86_64-linux;\n  in pkgs.runCommand \"linux-builder-check\" { allowSubstitutes = false; }\n    \"uname -m | tee $out\"\n'\n```\n\nThe build log should print `x86_64`. Once that succeeds, use:\n\n```sh\njust deploy admin@x.x.x.x\n```\n\nLeave the builder argument as its default, `local`: your Mac's Nix daemon sends\nLinux derivations to the registered VM and receives the outputs into its local\nstore. Deployment then transfers the completed system to the VPS and activates\nit there. Emulated builds may be slower than a native x86_64 Linux builder; you\ncan select a separate machine such as `zenbox` using the next section instead.\n\n## Building on a separate machine\n\nBy default, deployment builds through your local Nix installation. Local\nbuilds use the local store and any builders configured with Nix. The build must\nsupport this flake's `x86_64-linux` target. A native x86_64 Linux machine can build\ndirectly; macOS or ARM Linux needs a compatible Linux VM, configured builder,\nor emulation. Deployment does not automatically configure cross-compilation or\nfall back to the VPS when local building is unavailable.\n\nTo select a separate builder, install Nix with `nix-command` and `flakes` enabled\non an x86_64 Linux machine and verify SSH access from your local machine:\n\n```sh\nssh zenbox 'uname -m; nix --version'\n```\n\nPass its SSH address as the third argument, after the deployment target and\nflake configuration name:\n\n```sh\n# Build on zenbox for the first deployment.\njust deploy root@x.x.x.x vps zenbox\n\n# Build on zenbox for later deployments.\njust deploy admin@x.x.x.x vps zenbox\n\n# Explicitly choose local building (the default).\njust deploy admin@x.x.x.x vps local\n```\n\nThe builder can be `user@builder.example.com` or an `ssh-ng:\u002F\u002F` store URL.\nThe builder account needs access to its Nix store and permission to accept the\nbuild inputs. Nix's remote-store permission errors must be resolved on that\nbuilder before it can be used. Both the builder and the VPS must be reachable\nfrom your local machine.\n\nWith an explicit remote builder, intermediate outputs stay on that builder.\nOnly the completed system's runtime closure is streamed through your local\nmachine to the VPS. Cache substitution reduces the paths transferred, and no\nlocal Linux build is required.\n\nFor recovery or a one-time trust bootstrap on an existing VPS, you can explicitly\nbuild on the deployment target:\n\n```sh\njust deploy admin@x.x.x.x vps target\n```\n\nThis is an opt-in fallback; normal local and separate-builder deployments do not\nbuild on the VPS. Reboot and check SSH access after kernel changes as described\nin [Setup](#setup).\n\n## Trusted builds\n\nThis configuration adds `admin` to `nix.settings.trusted-users`, alongside\n`root`. Deployment can therefore import the selected builder's unsigned outputs\nas `admin`, then use sudo for activation. There is no signing-key setup.\n\n**A trusted Nix user has root-equivalent privileges without a sudo password.**\nUse this account only for server administration, and select only builders you\ntrust to produce the server's system. SSH authenticates the connection and\nprotects the transfer; it does not verify whether a build is safe to run.\n\nThe copy command uses `--no-check-sigs` for that deployment only. Global\nsignature checking remains enabled for normal Nix operations. This setting\ndoes not change SSH authentication or grant other users Nix trust.\n\n### Initial and existing VPS instances\n\nFor the first deployment, use the provisioned `root` account, which Nix already\ntrusts:\n\n```sh\njust deploy root@x.x.x.x\n# Or, from macOS or another machine without a configured Linux builder:\njust deploy root@x.x.x.x vps zenbox\n```\n\nThat deployment creates `admin` and installs its Nix trust configuration.\nSubsequent local or separate-builder deployments can use `admin`.\n\nIf an existing VPS predates this change and root SSH is already disabled, apply\nthis configuration once with the explicit on-target fallback:\n\n```sh\njust deploy admin@x.x.x.x vps target\n```\n\nThe system is built on the target, so no unsigned runtime outputs need to be\nimported before trust is installed. Afterward, return to your local machine or\nseparate builder for builds. Signing keys can be added later if you need a\nworkflow that keeps the deployment account outside `trusted-users`.\n","这是一个为NixOS虚拟私有服务器（VPS）提供开箱即用配置的基础设施即代码（IaC）项目。它基于Nix语言声明式管理VPS系统配置，支持可选的Tailscale组网和Cloudflare Tunnel反向代理集成，并内置安全的密钥管理（age加密）、多环境构建（本地\u002F远程\u002F跨平台）及一键部署流程。项目采用模块化设计，便于定制服务部署、权限控制与敏感信息隔离。适用于需要稳定、可复现、安全运维的个人开发者或小团队NixOS VPS部署场景。",2,"2026-11-24 04:34:43","CREATED_QUERY"]