SHADE is young: 0.1.0-next.2 is a pre-release, and 0.1.0 isn't out yet.

SHADE
Run SHADE

NixOS (experimental)

On NixOS, SHADE can run without Docker: the shade repository has a flake that builds the same release the image holds (the API bundle, the admin screens, the migrations and the console commands, from the same lockfile) and a NixOS module that declares an instance with its Postgres database, its Redis server and its services. It is experimental in 0.1: it is tested, but its options may change in a minor version. The image stays the reference way to run SHADE, and Self-hosting without Coolify is the path most instances take.

Everything about SHADE's settings in Setting up an instance holds here too. What differs is how the instance is started: as systemd services that NixOS writes from your configuration, instead of containers.

What you need

  • A NixOS host (x86_64 or aarch64) with flakes switched on.
  • A domain for the instance's API, and optionally one for the admin, pointed at the host.
  • Ports 80 and 443 open when the module's Caddy is in front; otherwise your own proxy.

Adding the flake

The flake is released with every version of SHADE, so a host pins the version it runs. 0.1.0 isn't out; the tag below is the pre-release v0.1.0-next.2, so take the newest one in the changelog.

# flake.nix of the host
{
  inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
  inputs.shade.url = "github:shadehq-dev/shade/v0.1.0-next.2";

  outputs = { nixpkgs, shade, ... }: {
    nixosConfigurations.server = nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      modules = [ shade.nixosModules.shade ./configuration.nix ];
    };
  };
}

It gives packages.<system>.shade (the built release), nixosModules.shade (the module below) and checks.<system> (its tests).

One instance

An instance is one business, as with the image. The module's options sit under services.shade.instances.<name>:

# configuration.nix
services.shade.instances.example = {
  apiUrl = "https://api.example.org";
  adminUrl = "https://admin.example.org";       # optional: the admin on a domain of its own
  environmentFile = "/run/secrets/shade-example.env";
  redis.passwordFile = "/run/secrets/shade-example-redis";
  database.ownerPasswordFile = "/run/secrets/shade-example-db-owner";
  database.backupPasswordFile = "/run/secrets/shade-example-db-backup";
  proxy = "caddy";                              # optional: Caddy in front, with HTTPS
  settings = {
    SHADE_PACKAGE_APPROVAL = true;
    SHADE_BACKUP_URL = "s3://backups/example";
  };
};

With that, nixos-rebuild switch gives the instance:

  • the services shade-example-admin, shade-example-public and shade-example-worker, one per container role. roles = [ "all" ]; runs the small profile, all three in one service, with what that gives up;
  • a system user shade-example, and the state folder /var/lib/shade/example for uploaded media and the unpacked server packages, in place of the image's /app/data;
  • its own Postgres database, shade-example, with the three roles of The database's roles: shade-example, the running role, which reaches it over the local socket as the system user, with no password and owning nothing; shade-example-owner, which owns the database and connects over the loopback address; and shade-example-backup, which reads everything and is read-only;
  • its own Redis server, redis-shade-example (Valkey, with a password, noeviction and nothing written to disk, as in the deployment template);
  • the command shade-example, which runs SHADE's console commands for this instance.

A oneshot service, shade-example-database, makes the roles and the database once, as the postgres user, and sets the two passwords again on every start. It refuses a database made before the three roles (one owned by shade-example): set it up again with a fresh database. The owner's password is loaded only in the admin (and all) service and the console, and the backup role's only in the worker (and all) service. The module no longer uses services.postgresql.ensureDatabases or ensureUsers.

The admin service applies the migrations when it starts, as MIGRATE_ON_START does in the template; the public role and the worker wait for them. settings takes any further variable from SHADE's configuration (the backup bucket, OIDC, SHADE_TRUSTED_MODULE_KEYS). A second instance on the same host needs ports of its own: ports = { admin = 4100; public = 4101; worker = 4102; } and redis.port = 6380.

Secrets

Everything in your NixOS configuration ends up in the Nix store, which every user of the host can read. So the module takes no secret as an option. environmentFile is a file of NAME=value lines that systemd reads when a service starts:

APP_SECRET=<openssl rand -base64 48>
SHADE_BACKUP_KEY=<openssl rand -base64 32>
SHADE_BACKUP_S3_SECRET_ACCESS_KEY=...

redis.passwordFile holds the Redis password on its own, letters and digits only (openssl rand -hex 32), since it goes into the Redis address as it is; database.ownerPasswordFile and database.backupPasswordFile hold the owner's and the backup role's passwords the same way (letters and digits only, openssl rand -hex 32). All three are paths given as strings, outside the store: a tool such as sops-nix or agenix, or a file you write yourself, readable by root only. The module refuses a secret's name in settings (APP_SECRET, a token, a password, a key) and a secret file under /nix/store.

Routing

With proxy = "caddy", Caddy serves the API's domain with HTTPS and routes it as the deployment template does, and as the Caddy of shade install does on Docker: /api/v1/account goes to the public role, everything else to the admin. An admin domain of its own goes to the admin. Without it, the services listen on 127.0.0.1 (ports 4000, 4001 and 4002) and your own proxy routes them the same way; the worker only answers /health.

The first admin

sudo shade-example create-admin --email you@example.org --name "Your Name"

It asks for the password, and runs as the instance's user with its settings and secrets. Every console command works this way (The console), apart from shade install and shade update, which set up and update the Docker installation and are left out here.

Updating and rolling back

Move the flake's input to the new version (github:shadehq-dev/shade/v0.1.1) and switch. The admin service takes the backup before it migrates, if backups are set up (Updating and backups), and then applies the new migrations.

A NixOS generation rolls the code back, never the data. Going back one release is safe, because a release only adds tables and columns and removes them a release later, so the previous release runs on the new database. Going back further means restoring the backup taken before the update.

For developers: checking the flake

From a checkout of shade, on Linux or in WSL2 with Nix:

  • nix build .#shade builds the release. The pnpm dependencies are one download pinned by its hash in nix/package.nix (pnpmDeps.hash); the build itself has no network. After a change to pnpm-lock.yaml, set the hash to "", build, and copy the hash Nix prints.
  • nix build .#checks.x86_64-linux.module evaluates what the module refuses, without a VM.
  • nix flake check also runs the VM test: one instance with its three roles, an admin and a read token made with the console, the content API read on the public role, and an untrusted module run in the sandbox. It boots a virtual machine: quick with KVM, and it also runs without, under QEMU's software emulation (a few minutes).

pnpm release:gates runs nix flake check where Nix is installed and says when it skipped it. While the native install is experimental, a failure there is a warning, not a reason to hold a release.