-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
108 lines (91 loc) · 2.86 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# adapted from:
# - https://litchipi.github.io/nix/2023/01/12/build-jekyll-blog-with-nix.html
# - https://technogothic.net/pages/JekyllOnNix/
{
description = "Build the blog";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
outputs = inputs: with inputs; let
system = "x86_64-linux";
pkgs = import nixpkgs { inherit system; };
# Specify gems and dependencies here
jekyll-version = "~> 4.2.2";
inc_gems = {
webrick = "~> 1.7";
};
inc_plugins = {
jekyll-scholar = "~> 7.0";
};
# 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}
# HACK to keep sass-embedded working
gem "jekyll", "${jekyll-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
gcc
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 .#build -> builds the website locally
build = simple_script "build_blog" [] ''
echo "Bundler env: ${env}"
${env}/bin/bundler exec -- jekyll build --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
'';
};
};
}