2023-11-13 11:30:54 -05:00
|
|
|
{ inputs ? import ./nix/sources.nix
|
|
|
|
, system ? builtins.currentSystem
|
|
|
|
,
|
2023-11-06 22:43:55 -05:00
|
|
|
}:
|
2023-10-16 06:43:38 -04:00
|
|
|
let
|
2024-03-17 01:52:26 -04:00
|
|
|
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;
|
2023-10-16 06:43:38 -04:00
|
|
|
};
|
|
|
|
|
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 =
|
|
|
|
let
|
2024-02-06 18:25:38 -05:00
|
|
|
# Various versions of the Nix manuals, grep for (nix-manual)= to find where they are displayed.
|
2023-12-05 21:31:01 -05:00
|
|
|
# FIXME: This requires human interaction to update! See ./CONTRIBUTING.md for details.
|
|
|
|
in
|
|
|
|
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
|
|
|
|
nix-manual-index =
|
2024-03-17 01:52:26 -04:00
|
|
|
let
|
|
|
|
inherit (lib.strings) replaceStrings;
|
|
|
|
inherit (lib.attrsets) mapAttrsToList;
|
|
|
|
inherit (releases) version supported-releases;
|
|
|
|
in
|
2024-02-06 18:25:38 -05:00
|
|
|
replaceStrings
|
2024-03-17 01:52:26 -04:00
|
|
|
(mapAttrsToList (release: _: "@${release}@") supported-releases)
|
|
|
|
(mapAttrsToList (_: package: version package) supported-releases)
|
2024-02-06 18:25:38 -05:00
|
|
|
(builtins.readFile ./source/reference/nix-manual.md);
|
2023-12-05 21:31:01 -05:00
|
|
|
in
|
|
|
|
''
|
|
|
|
cp -f ${builtins.toFile "nix-manual.md" nix-manual-index} $TMP/nix.dev/source/reference/nix-manual.md
|
|
|
|
make html
|
2023-10-18 06:04:34 -04:00
|
|
|
'';
|
2023-12-05 21:31:01 -05:00
|
|
|
installPhase =
|
|
|
|
let
|
2024-03-17 01:52:26 -04:00
|
|
|
inherit (releases) version;
|
2024-02-06 18:25:38 -05:00
|
|
|
copy = nix: ''
|
|
|
|
cp -Rf ${nix.doc}/share/doc/nix/manual/* $out/manual/nix/${version nix}
|
2023-12-05 21:31:01 -05:00
|
|
|
'';
|
2024-03-17 01:52:26 -04:00
|
|
|
# provide a single-page view from mdBook's print feature
|
|
|
|
single-page = nix:
|
|
|
|
''
|
|
|
|
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}/nix-${version nix}.html
|
|
|
|
'';
|
2024-02-06 18:25:38 -05:00
|
|
|
# add upstream page redirects of the form `<from> <to> <status>`, excluding comments and empty lines
|
2024-03-17 01:52:26 -04:00
|
|
|
redirects = nix:
|
|
|
|
# not all releases have that though
|
|
|
|
lib.optionalString (lib.pathExists "${nix.doc}/share/doc/nix/manual/_redirects") ''
|
|
|
|
sed '/^#/d;/^$/d;s#^\(.*\) \(.*\) #/manual/nix/${version nix}\1 /manual/nix/${version nix}\2 #g' ${nix.doc}/share/doc/nix/manual/_redirects >> $out/_redirects
|
|
|
|
'';
|
2024-02-06 18:25:38 -05:00
|
|
|
shortlink = release: nix: ''
|
2024-03-17 01:52:26 -04:00
|
|
|
echo /nix/manual/${release}/* /nix/manual/${version nix}/:splat 302 >> $out/_redirects
|
2023-12-05 21:31:01 -05:00
|
|
|
'';
|
2024-03-17 01:52:26 -04:00
|
|
|
inherit (releases) unique-versions nix-releases;
|
|
|
|
inherit (lib.attrsets) mapAttrsToList attrValues;
|
|
|
|
inherit (lib.strings) concatStringsSep;
|
2023-12-05 21:31:01 -05:00
|
|
|
in
|
|
|
|
''
|
|
|
|
mkdir -p $out
|
|
|
|
cp -R build/html/* $out/
|
|
|
|
# NOTE: the comma in the shell expansion makes it also work for singleton lists
|
2024-02-06 18:25:38 -05:00
|
|
|
mkdir -p $out/manual/nix/{${concatStringsSep "," (mapAttrsToList (_: nix: version nix) nix-releases)},}
|
2024-03-17 01:52:26 -04:00
|
|
|
${concatStringsSep "\n" (map copy (unique-versions (attrValues nix-releases)))}
|
|
|
|
${concatStringsSep "\n" (map single-page (unique-versions (attrValues nix-releases)))}
|
|
|
|
${concatStringsSep "\n" (map redirects (unique-versions (attrValues nix-releases)))}
|
2023-12-05 21:31:01 -05:00
|
|
|
${concatStringsSep "\n" (mapAttrsToList shortlink nix-releases)}
|
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;
|
|
|
|
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
|
2023-10-18 06:04:34 -04:00
|
|
|
pkgs.niv
|
2023-11-13 07:20:51 -05:00
|
|
|
pkgs.python310.pkgs.black
|
|
|
|
pkgs.vale
|
2023-10-16 06:43:38 -04:00
|
|
|
];
|
|
|
|
};
|
2024-03-17 01:52:26 -04:00
|
|
|
nix_2-15 = (import inputs.nix_2-15).default;
|
|
|
|
nix_2-16 = (import inputs.nix_2-16).default;
|
|
|
|
nix_2-14 = (import inputs.nix_2-14).default;
|
2023-10-16 06:43:38 -04:00
|
|
|
}
|