-
-
Notifications
You must be signed in to change notification settings - Fork 253
/
default.nix
138 lines (129 loc) · 4.48 KB
/
default.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
{
inputs ? import ./nix/inputs.nix,
system ? builtins.currentSystem,
pkgs ? import inputs.nixpkgs."23.05" {
config = { };
overlays = [ (import ./nix/overlay.nix) ];
inherit system;
},
withManuals ? false, # building the manuals is expensive
}:
let
lib = pkgs.lib;
releases = import ./nix/releases.nix { inherit lib inputs system; };
pkgs-unstable = import inputs.main.nixpkgs-rolling {
config = { };
overlays = [ ];
inherit system;
};
nix-dev =
pkgs.stdenv.mkDerivation {
name = "nix-dev";
src = ./.;
nativeBuildInputs = with pkgs.python310.pkgs; [
linkify-it-py
myst-parser
sphinx
sphinx-book-theme
sphinx-copybutton
sphinx-design
sphinx-notfound-page
sphinx-sitemap
pkgs.perl
];
buildPhase =
let
substitutedNixManualReference = pkgs.substitute {
src = ./source/reference/nix-manual.md;
replacements = lib.concatLists (lib.mapAttrsToList (from: to: [ "--subst-var-by" from to ]) releases.substitutions);
};
in
''
${lib.optionalString withManuals "cp -f ${substitutedNixManualReference} source/reference/nix-manual.md"}
make html
'';
installPhase =
let
# Various versions of the Nix manuals, grep for (nix-manual)= to find where they are displayed.
# FIXME: This requires human interaction to update! See ./CONTRIBUTING.md for details.
release = version: nix: ''
cp -R --no-preserve=mode ${nix.doc}/share/doc/nix/manual $out/manual/nix/${version}
# add upstream page redirects of the form `<from> <to> <status>`, excluding comments and empty lines
# not all releases have that though
if [[ -f ${nix.doc}/share/doc/nix/manual/_redirects ]]; then
sed '/^#/d;/^$/d;s#^\(.*\) \(.*\) #/manual/nix/${version}\1 /manual/nix/${version}\2 #g' ${nix.doc}/share/doc/nix/manual/_redirects >> $out/_redirects
fi
# provide a single-page view from mdBook's print feature.
# this is hacky but cheap and does work.
sed -z 's|\s*window\.addEventListener(\x27load\x27, function() {\s*window\.setTimeout(window.print, 100);\s*});||g' ${nix.doc}/share/doc/nix/manual/print.html > $out/manual/nix/${version}/nix-${version}.html
'';
# Redirects from mutable URLs like /manual/nix/latest/... to /manual/nix/2.21/...
mutableRedirect = mutable: immutable: ''
echo "/manual/nix/${mutable}/* /manual/nix/${immutable}/:splat 302" >> $out/_redirects
'';
in
''
mkdir -p $out/manual/nix
cp -R build/html/* $out/
'' + lib.optionalString withManuals ''
${lib.concatStringsSep "\n" (lib.mapAttrsToList release releases.nixReleases)}
${lib.concatStringsSep "\n" (lib.mapAttrsToList mutableRedirect releases.mutableNixManualRedirects)}
'';
};
devmode =
let
pythonEnvironment = pkgs.python310.withPackages (ps: with ps; [
livereload
]);
script = ''
from livereload import Server
from subprocess import Popen, PIPE
import shlex
import sys
server = Server()
def nix_build():
p = Popen(
shlex.split("nix-build -A build") + sys.argv[1:],
# capture output as text
stdout=PIPE,
stderr=PIPE,
text=True,
)
# we only care about failures
stdout, stderr = p.communicate()
if p.returncode:
print(stderr)
return p
# (re-)build once before serving
nix_build().wait()
server.watch("source/*", nix_build)
server.watch("source/**/*", nix_build)
server.serve(root="result")
'';
in
pkgs.writeShellApplication {
name = "devmode";
runtimeInputs = [ pythonEnvironment ];
text = ''
python ${pkgs.writeText "live.py" script}
'';
};
update-nix-releases = pkgs-unstable.callPackage ./nix/update-nix-releases.nix { };
update-nixpkgs-releases = pkgs-unstable.callPackage ./nix/update-nixpkgs-releases.nix { };
in
{
# build with `nix-build -A build`
build = nix-dev;
shell = pkgs.mkShell {
inputsFrom = [ nix-dev ];
packages = [
devmode
update-nix-releases
update-nixpkgs-releases
pkgs.npins
pkgs.python310.pkgs.black
pkgs.vale
pkgs.netlify-cli
];
};
}