-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathflake.nix
160 lines (151 loc) · 5.73 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
{
description = "A flake with pre-commit hooks";
inputs = {
flake-parts.url = "github:hercules-ci/flake-parts";
flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable-small";
pre-commit-hooks-nix.url = "github:cachix/pre-commit-hooks.nix";
pre-commit-hooks-nix.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = inputs@{ self, flake-parts, hercules-ci-effects, ... }:
flake-parts.lib.mkFlake
{ inherit inputs; }
({ lib, withSystem, ... }: {
imports = [
inputs.hercules-ci-effects.flakeModule
inputs.pre-commit-hooks-nix.flakeModule
];
systems = [ "x86_64-linux" ];
hercules-ci.flake-update = {
enable = true;
when = {
dayOfMonth = 5;
};
};
perSystem = { config, self', inputs', pkgs, ... }: {
packages.antora = pkgs.callPackage ./antora/package.nix { };
pre-commit.settings.hooks.nixpkgs-fmt.enable = true;
pre-commit.settings.excludes = [
# The snippets didn't improve. May try again later.
"docs/modules/ROOT/partials/snippets"
];
devShells.default = pkgs.mkShell {
nativeBuildInputs = [
config.packages.antora
pkgs.inotify-tools
pkgs.netlify-cli
pkgs.nixpkgs-fmt
pkgs.yarn
];
NODE_PATH = config.packages.antora.node_modules;
shellHook = ''
${config.pre-commit.installationScript}
echo
echo 1>&2 "antora $(antora --version)"
cat 1>&2 <<EOF
Welcome to the docs.hercules-ci.com shell
Commands:
live-rebuild Performs a local build whenever watched files change.
open-browser Opens the homepage in a browser
EOF
last_status() {
local r=$?
if [[ $r = 0 ]]; then
echo ok
elif [[ $r = 1 ]]; then
echo FAILED
else
echo "FAILED ($r)"
fi
}
live-rebuild() {
(
echo 1>&2 "Press ENTER to force a rebuild."
inotifywait -mr . ../hercules-ci-effects ../arion ../hercules-ci-agent -e MODIFY \
| grep --line-buffered -E 'adoc|hbs|(lib/.*\.js)' &
cleanup() {
kill %%
}
trap cleanup EXIT
echo first build for good measure
cat
) | while read ln; do
echo 1>&2 "antora starting..."
antora antora-playbook-local.yml --stacktrace
echo 1>&2 "antora finished ($(last_status)) at $(date +%T)";
done
}
open-browser() {
xdg-open public/index.html
}
'';
LANG = "en_US.utf8";
};
};
herculesCI = { config, ... }:
let
inherit (config.repo) branch;
isProd = branch == "master";
deploy = withSystem "x86_64-linux" ({ config, pkgs, hci-effects, ... }:
hci-effects.netlifyDeploy {
siteId = "48f50b78-b03a-4f2b-bc57-8e043b0f569f";
secretName = "default-netlify";
productionDeployment = isProd;
content = "./public";
src = ./.;
nativeBuildInputs = [
config.packages.antora
pkgs.tree
pkgs.git
pkgs.nix
];
# TODO package the extension properly
NODE_PATH = config.packages.antora.node_modules;
preEffect = ''
mkdir -p public
mkdir -p ~/.config/nix
echo >>~/.config/nix/nix.conf experimental-features = flakes nix-command
git config --global user.email "[email protected]"
git config --global user.name CI
git config --global init.defaultBranch master
git init .
git remote add origin https://github.com/hercules-ci/docs.hercules-ci.com
git add -N .
git commit -m init .
git checkout -B ${lib.escapeShellArg branch}
checklog() {
tee $TMPDIR/err
! grep -E 'ERROR'
}
export CI=true;
export FORCE_SHOW_EDIT_PAGE_LINK=true;
antora --fetch ./antora-playbook.yml --stacktrace 2>&1 | checklog;
antora --url https://docs.hercules-ci.com --html-url-extension-style=indexify --redirect-facility=netlify ./antora-playbook.yml 2>&1 | checklog;
cat <./_redirects >>./public/_redirects
'' + lib.optionalString (!isProd) ''
{ echo 'User-agent: *'
echo 'Disallow: /'
} >public/robots.txt
'';
extraDeployArgs = [
# "--debug"
] ++ lib.optionals (!isProd) [
"--alias"
branch
];
}
);
in
{
onPush.default = {
outputs = {
effects.netlifyDeploy = deploy;
};
};
onSchedule.scheduled-deploy = {
outputs.effects.netlifyDeploy = deploy;
when.hour = [ 0 6 12 18 ];
};
};
});
}