Home | Blog
Last Updated: 21/Jun/2020

Deploy this blog using nix

Added on 21/Jun/2020



What?

This blog uses Jekyll static site generator, and is being hosted at Netlify.

I recently switched my laptop and faced the problem of having to re-setup my machine to be able to develope this website.

I wanted to simplify this setup in the future by having a reproducible build without having the need to dirtify my environment (eg. installing a different version of Ruby, Bundler and so on).

I decided to use Nix to acheive this.

Introducing Nix

When I first heard of Nix it was in the context of NixOS.

Nix is a powerful package manager for Linux and other Unix systems that makes package management reliable and reproducible. Nix builds are:

How to install Nix

This page list several methods to install Nix.

How to install Nix
Fig.1 - How to install Nix.

How to setup Nix to build this website

Some terminologies before starting:

Process before Nix

  1. Install packages: bundle install
  2. Start Jekyll server: bundle exec jekyll serve --watch --incremental

Process after Nix

  1. Install packages: bash setup.sh: It'll use bundix to generate a new gemset.nix file.
  2. Start Jekyll server: nix-shell: It'll execute default.nix bellow which will set build all packages and start the server.

setup.sh

#!/usr/bin/env bash

nix-shell -p bundler -p bundix --run 'bundler lock; bundler package --no-install --path vendor; bundix; rm -rf vendor'
default.nix
with import <nixpkgs> { };

let
    jekyll_env = bundlerEnv rec {
        name = "jekyll_env";
        inherit ruby;
        gemfile = ./Gemfile;
        lockfile = ./Gemfile.lock;
        gemset = ./gemset.nix;
    };
in
stdenv.mkDerivation rec {
    name = "mhasbini";
    buildInputs = [ jekyll_env bundler ruby ];

    shellHook = ''
      export LC_ALL="C.UTF-8"
      export LANG="en_US.UTF-8"
      export LANGUAGE="en_US.UTF-8"

      exec ${jekyll_env}/bin/jekyll serve --watch --incremental
    '';
}




✉️ Subscribe via email
Thanks for Subscribing!
Subscription failed. Please try again later.