{ description = "Build the blog"; inputs = { nixpkgs.url = "github:nixos/nixpkgs/22.11"; }; outputs = inputs: with inputs; let system = "x86_64-linux"; pkgs = import nixpkgs { inherit system; }; # Specify gems and dependencies here github-pages-version = 227; inc_gems = { minima = "2.5"; webrick = "1.7"; }; inc_plugins = { jekyll-feed = "0.12"; }; # Generation of the Gemfile generate_gemfile = let gems = builtins.concatStringsSep "\n" (pkgs.lib.attrsets.mapAttrsToList (name: version: "gem \"${name}\", \"~> ${version}\"" ) inc_gems); plugins = builtins.concatStringsSep "\n" (pkgs.lib.attrsets.mapAttrsToList (name: version: " gem \"${name}\", \"~> ${version}\"" ) inc_plugins); in '' # This file is autogenerated by the flake.nix file, do not edit source "https://rubygems.org" # Gems dependencies to be installed ${gems} gem "github-pages", "~> ${builtins.toString github-pages-version}", group: :jekyll_plugins # Github Pages plugins group :jekyll_plugins do ${plugins} end ''; # The build environment env = pkgs.bundlerEnv { name = "blog"; ruby = pkgs.ruby; gemdir = ./.; }; # Utility to run a script easily in the flakes app simple_script = name: add_deps: text: let exec = pkgs.writeShellApplication { inherit name text; runtimeInputs = with pkgs; [ gnumake bundler ] ++ add_deps; }; in { type = "app"; program = "${exec}/bin/${name}"; }; in { apps.${system} = { # nix run -> serves the website locally default = simple_script "serve_blog" [] '' echo "Bundler env: ${env}" ${env}/bin/bundler exec -- jekyll serve --trace ''; # nix run .#generate -> Re-generate the gemfile, lockfile, build environment and gemset.nix # To use only if added a dependency, bumped a version, etc ... generate = simple_script "generate_blog_env" [ pkgs.bundix ] '' set -e rm -f gemset.nix Gemfile Gemfile.lock .bundle/config cat << EOF > Gemfile ${generate_gemfile} EOF export BUNDLE_PATH=vendor export BUNDLE_CACHE_ALL=true export BUNDLE_NO_INSTALL=true export BUNDLE_FORCE_RUBY_PLATFORM=true bundler update bundler lock bundler package bundix --magic rm -rf vendor ''; }; }; }