diff --git a/_posts/2024-02-03-hosting-jekyll-on-nixos.md b/_posts/2024-02-03-hosting-jekyll-on-nixos.md new file mode 100644 index 0000000..63f7b87 --- /dev/null +++ b/_posts/2024-02-03-hosting-jekyll-on-nixos.md @@ -0,0 +1,84 @@ +--- +layout: post +summary: "This post is hosted on NixOS" +title: "Hosting Jekyll websites on NixOS" +toc: true +--- + +## Preamble + +Previously this website (ivabus.dev) was hosted on Cloudflare Pages, but recently I learned about NixOS and wanted to host my site "declarative" way. + +## The way + +### Step 1: Package website + +To host website correct way, we want to have its Nix derivation. Before we create one, we have to have `gemset.nix`. To generate one, run this in the root of your Jekyll project + +```shell +nix-shell -p bundler -p bundix --run 'bundler update; bundler lock; bundler package --no-install --path vendor; bundix; rm -rf vendor' +``` + +Note: make sure to remove all the platform-specific gems from `Gemfile` and `Gemfile.lock`, like `google-protobuf`, so your website could be built + +Then you need to create a package for your website with code like this + +```nix +{ pkgs ? import { }, bundlerEnv ? pkgs.bundlerEnv, ... }: +let + version = "commit hash"; + repo = builtins.fetchGit { + url = "https://address/of/git/repo"; + rev = version; + }; + + gems = bundlerEnv { + name = "your-site"; + ruby = pkgs.ruby; + gemdir = "${repo}/."; + }; +in pkgs.stdenv.mkDerivation { + inherit version; + name = "your-site"; + src = repo; + + buildInputs = with pkgs; [ + gems + # nokogiri dependencies + zlib + libiconv + libxml2 + libxslt + # jekyll wants a JS runtime + nodejs-slim + ]; + + buildPhase = '' + bundle exec jekyll build + ''; + + installPhase = '' + mkdir -p $out + cp -r _site/* $out/ + ''; +} + +``` + +### Step 2: Prepare nginx + +```nix +services.nginx = { + enable = true; + virtualHosts."your.site" = { + root = pkgs.callPackage ./path/to/pkg.nix { }; + extraConfig = '' + error_page 404 /404.html; + ''; + }; +} +``` + +### Step 3: Rebuild + +Rebuild your system and try to visit your website (don't forget to open 80 (and 443, if HTTPS is enabled) ports in the firewall, if needed) diff --git a/_projects/006-aliurl.md b/_projects/006-aliurl.md deleted file mode 100644 index 3bc42fa..0000000 --- a/_projects/006-aliurl.md +++ /dev/null @@ -1,14 +0,0 @@ ---- -layout: project -title: "aliurl & urouter" -description: "Aliasers for URLs" -participant: false ---- - -[aliurl](https://github.com/ivabus/aliurl) is "dynamic" URL "aliaser" (router), that could be managed via POST requests. - -[urouter](https://github.com/ivabus/urouter) is "static" URL router, that reads route list in compile-time. - -Both of them are built on top of [Rocket.rs](https://rocket.rs) framework. - -Aliurl powers [ивабус.рф](https://ивабус.рф) and urouter powers [iva.bz](https://iva.bz) \ No newline at end of file diff --git a/_projects/006-urouter.md b/_projects/006-urouter.md new file mode 100644 index 0000000..217eec5 --- /dev/null +++ b/_projects/006-urouter.md @@ -0,0 +1,13 @@ +--- +layout: project +title: "urouter" +description: "Aliaser for URLs" +project-url: "https://github.com/ivabus/urouter" +participant: false +--- + +[urouter](https://github.com/ivabus/urouter) is "static" URL router, that reads route list at from file once. + +urouter is built on top of the [Rocket.rs](https://rocket.rs) framework. + +urouter powers [iva.bz](https://iva.bz) \ No newline at end of file diff --git a/_projects/007-rinth.md b/_projects/007-rinth.md new file mode 100644 index 0000000..745bcf6 --- /dev/null +++ b/_projects/007-rinth.md @@ -0,0 +1,11 @@ +--- +layout: project +title: "Rinth" +description: "FM and SSG synthesizer" +participant: false +project-url: "https://github.com/ivabus/rinth" +--- + +Rinth is work in progress FM and SSG synthesizer. + +First alpha release [is available](https://github.com/ivabus/rinth/releases/tag/0.0.1) on GitHub. \ No newline at end of file