Self-host your own digital island
1 2### Hosting a website 3 4To host a simple static website stored at `/var/www` at your domain, you can create a `website.nix`: 5 6``` 7{ config, ... }: 8 9{ 10 services.nginx.virtualHosts."${config.networking.domain}" = { 11 enableACME = true; 12 forceSSL = true; 13 root = "/var/www"; 14 }; 15} 16``` 17 18And import it in `configuration.nix`. 19 20If you want to build your website with Nix it's possible to add it as a reproducible package. 21 22``` 23{ config, pkgs, ... }: 24 25{ 26 services.nginx.virtualHosts."${config.networking.domain}" = { 27 enableACME = true; 28 forceSSL = true; 29 root = 30 let website = pkgs.stdenv.mkDerivation rec { 31 name = "website"; 32 33 src = pkgs.stdenv.fetchFromGitHub { 34 owner = "<user>"; 35 repo = "website"; 36 rev = "<hash>"; 37 sha256 = ""; 38 }; 39 40 buildInputs = with pkgs [ 41 # dependencies 42 ]; 43 44 installPhase = '' 45 mkdir $out 46 cp -r * $out 47 ''; 48 }; 49 in website; 50 }; 51} 52```