Add post Hosting Jekyll websites on NixOS

Remove aliurl project, add rinth

Signed-off-by: Ivan Bushchik <ivabus@ivabus.dev>
This commit is contained in:
Ivan Bushchik 2024-02-03 16:15:58 +03:00
parent 89263a2929
commit f8a8fcc909
No known key found for this signature in database
GPG key ID: 2F16FBF3262E090C
4 changed files with 108 additions and 14 deletions

View file

@ -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 <nixpkgs> { }, 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)

View file

@ -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)

13
_projects/006-urouter.md Normal file
View file

@ -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)

11
_projects/007-rinth.md Normal file
View file

@ -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.