Repository navigation
Expand file tree
/
Copy pathdefault.nix
More file actions
144 lines (134 loc) · 4.47 KB
/
Copy pathdefault.nix
File metadata and controls
144 lines (134 loc) · 4.47 KB
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
{
inputs ? import ./nix/inputs.nix,
system ? builtins.currentSystem,
pkgs ? import inputs.main.nixpkgs-rolling {
config = { };
overlays = [ ];
inherit system;
},
withManuals ? false, # building the manuals is expensive
inNixShell ? false # Provided by direnv-nix; Ignored for now.
}:
let
lib = pkgs.lib;
releases = import ./nix/releases.nix { inherit lib inputs system; };
nix-dev-python-pkgs = with pkgs.python3.pkgs; [
linkify-it-py
myst-parser
sphinx
sphinx-book-theme
sphinx-copybutton
sphinx-design
sphinx-notfound-page
sphinx-sitemap
pkgs.perl
];
# generated with nix run github:rgri/tex2nix -- *.tex *.sty
nix-dev-latex = [
(pkgs.callPackage ./nix/tex-env.nix {
extraTexPackages = {
inherit (pkgs.texlive) latexmk gnu-freefont;
};
})
];
nix-dev = pkgs.stdenv.mkDerivation {
name = "nix-dev";
src = ./.;
nativeBuildInputs = [
nix-dev-python-pkgs
nix-dev-latex
pkgs.pagefind
];
buildPhase =
let
substitutedNixManualReference = pkgs.substitute {
src = ./source/reference/nix-manual.md;
substitutions = lib.concatLists (
lib.mapAttrsToList (from: to: [
"--subst-var-by"
from
to
]) releases.substitutions
);
};
in
''
cp -f ${substitutedNixManualReference} source/reference/nix-manual.md
make html
make latexpdf
'';
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/
cp build/latex/nix-dev.pdf $out/
cp netlify.toml $out/
''
+ lib.optionalString withManuals ''
${lib.concatStringsSep "\n" (lib.mapAttrsToList release releases.nixReleases)}
${lib.concatStringsSep "\n" (lib.mapAttrsToList mutableRedirect releases.mutableNixManualRedirects)}
'';
};
devmode =
let
boolean = x: if x then "true" else "false";
in
pkgs.devmode.override {
buildArgs = "-A build --show-trace --arg withManuals ${boolean withManuals}";
open = "/index.html";
};
update-nix-releases = pkgs.callPackage ./nix/update-nix-releases.nix { };
update-nixpkgs-releases = pkgs.callPackage ./nix/update-nixpkgs-releases.nix { };
nixpkgs-master = inputs.main.nixpkgs-master;
pkgs-master = (import nixpkgs-master {
inherit system;
});
nixpkgs-doc = pkgs.callPackage ./nix/nixpkgs-doc.nix {
nixpkgs = nixpkgs-master;
revision = nixpkgs-master.revision;
inherit (pkgs-master.nixpkgs-manual) lib-docs;
};
in
{
# build with `nix-build -A build`
build = nix-dev;
# the content folder of the site, `nix-build -A nixpkgs-doc`
inherit nixpkgs-doc pkgs-master;
shell = pkgs.mkShell {
inputsFrom = [ nix-dev ];
packages = [
devmode
update-nix-releases
update-nixpkgs-releases
pkgs.npins
pkgs.python3.pkgs.black
pkgs.vale
pkgs.netlify-cli
pkgs.nodejs_26
];
shellHook = ''
# link to the nixpkgs source derivation
rm -rf ${toString ./site}/nixpkgs-doc
ln -s ${nixpkgs-doc} ${toString ./site}/nixpkgs-doc
'';
};
}