2024-06-03 03:50:23 -04:00
|
|
|
{
|
|
|
|
inputs ? import ./nix/inputs.nix,
|
|
|
|
system ? builtins.currentSystem,
|
|
|
|
pkgs ? import inputs.nixpkgs."23.05" {
|
2023-10-16 06:43:38 -04:00
|
|
|
config = { };
|
2024-03-17 01:52:26 -04:00
|
|
|
overlays = [ (import ./nix/overlay.nix) ];
|
2023-11-06 22:43:55 -05:00
|
|
|
inherit system;
|
2024-06-03 03:50:23 -04:00
|
|
|
},
|
|
|
|
}:
|
|
|
|
let
|
2024-03-17 01:52:26 -04:00
|
|
|
lib = pkgs.lib;
|
|
|
|
releases = import ./nix/releases.nix { inherit lib inputs system; };
|
2024-03-15 20:24:22 -04:00
|
|
|
|
2023-12-05 21:31:01 -05:00
|
|
|
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
|
2024-03-17 01:52:26 -04:00
|
|
|
pkgs.perl
|
2023-12-05 21:31:01 -05:00
|
|
|
];
|
|
|
|
buildPhase =
|
|
|
|
let
|
2024-04-03 19:51:03 -04:00
|
|
|
substitutedNixManualReference = pkgs.substitute {
|
|
|
|
src = ./source/reference/nix-manual.md;
|
|
|
|
replacements = lib.concatLists (lib.mapAttrsToList (from: to: [ "--subst-var-by" from to ]) releases.substitutions);
|
|
|
|
};
|
2023-12-05 21:31:01 -05:00
|
|
|
in
|
|
|
|
''
|
2024-04-03 19:51:03 -04:00
|
|
|
cp -f ${substitutedNixManualReference} source/reference/nix-manual.md
|
2023-12-05 21:31:01 -05:00
|
|
|
make html
|
2023-10-18 06:04:34 -04:00
|
|
|
'';
|
2023-12-05 21:31:01 -05:00
|
|
|
installPhase =
|
|
|
|
let
|
2024-04-03 19:51:03 -04:00
|
|
|
# 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
|
2024-03-17 01:52:26 -04:00
|
|
|
# not all releases have that though
|
2024-04-03 19:51:03 -04:00
|
|
|
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
|
2024-06-13 05:39:13 -04:00
|
|
|
|
|
|
|
# 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
|
2024-04-03 19:51:03 -04:00
|
|
|
'';
|
|
|
|
# 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
|
2023-12-05 21:31:01 -05:00
|
|
|
'';
|
|
|
|
in
|
|
|
|
''
|
2024-04-03 19:51:03 -04:00
|
|
|
mkdir -p $out/manual/nix
|
2023-12-05 21:31:01 -05:00
|
|
|
cp -R build/html/* $out/
|
2024-04-03 19:51:03 -04:00
|
|
|
${lib.concatStringsSep "\n" (lib.mapAttrsToList release releases.nixReleases)}
|
|
|
|
${lib.concatStringsSep "\n" (lib.mapAttrsToList mutableRedirect releases.mutableNixManualRedirects)}
|
2023-12-05 21:10:31 -05:00
|
|
|
'';
|
2023-12-05 21:31:01 -05:00
|
|
|
};
|
2023-10-16 06:43:38 -04:00
|
|
|
|
|
|
|
devmode =
|
|
|
|
let
|
|
|
|
pythonEnvironment = pkgs.python310.withPackages (ps: with ps; [
|
|
|
|
livereload
|
|
|
|
]);
|
|
|
|
script = ''
|
2023-11-13 11:30:54 -05:00
|
|
|
from livereload import Server
|
|
|
|
from subprocess import Popen, PIPE
|
|
|
|
import shlex
|
2023-10-16 06:43:38 -04:00
|
|
|
|
|
|
|
server = Server()
|
|
|
|
|
2023-11-13 11:30:54 -05:00
|
|
|
def nix_build():
|
|
|
|
p = Popen(
|
|
|
|
shlex.split("nix-build -A build"),
|
|
|
|
# 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
|
2023-10-16 06:43:38 -04:00
|
|
|
|
2023-11-13 11:30:54 -05:00
|
|
|
# (re-)build once before serving
|
|
|
|
nix_build().wait()
|
2023-10-16 06:43:38 -04:00
|
|
|
|
2023-11-13 11:30:54 -05:00
|
|
|
server.watch("source/*", nix_build)
|
|
|
|
server.watch("source/**/*", nix_build)
|
|
|
|
server.serve(root="result")
|
2023-10-16 06:43:38 -04:00
|
|
|
'';
|
|
|
|
in
|
|
|
|
pkgs.writeShellApplication {
|
|
|
|
name = "devmode";
|
|
|
|
runtimeInputs = [ pythonEnvironment ];
|
|
|
|
text = ''
|
|
|
|
python ${pkgs.writeText "live.py" script}
|
|
|
|
'';
|
|
|
|
};
|
2024-03-15 07:53:05 -04:00
|
|
|
update-nix-releases = pkgs.callPackage ./nix/update-nix-releases.nix { };
|
2024-03-16 17:00:22 -04:00
|
|
|
update-nixpkgs-releases = pkgs.callPackage ./nix/update-nixpkgs-releases.nix { };
|
2023-10-16 06:43:38 -04:00
|
|
|
in
|
|
|
|
{
|
|
|
|
# build with `nix-build -A build`
|
|
|
|
build = nix-dev;
|
2024-04-03 19:51:03 -04:00
|
|
|
|
2023-10-16 06:43:38 -04:00
|
|
|
shell = pkgs.mkShell {
|
|
|
|
inputsFrom = [ nix-dev ];
|
2023-11-13 07:20:51 -05:00
|
|
|
packages = [
|
2023-10-16 06:43:38 -04:00
|
|
|
devmode
|
2024-03-15 07:53:05 -04:00
|
|
|
update-nix-releases
|
2024-03-16 17:00:22 -04:00
|
|
|
update-nixpkgs-releases
|
2024-06-03 03:50:23 -04:00
|
|
|
pkgs.npins
|
2023-11-13 07:20:51 -05:00
|
|
|
pkgs.python310.pkgs.black
|
|
|
|
pkgs.vale
|
2024-05-26 11:09:24 -04:00
|
|
|
pkgs.netlify-cli
|
2023-10-16 06:43:38 -04:00
|
|
|
];
|
|
|
|
};
|
|
|
|
}
|