-
Notifications
You must be signed in to change notification settings - Fork 1
/
flake.nix
98 lines (84 loc) · 2.52 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
{
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
'';
};
};
}