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
|
|
|
|
pkgs = import inputs.nixpkgs {
|
|
|
|
config = { };
|
|
|
|
overlays = [ (import ./overlay.nix) ];
|
2023-11-06 22:43:55 -05:00
|
|
|
inherit system;
|
2023-10-16 06:43:38 -04: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
|
|
|
|
];
|
|
|
|
buildPhase = ''
|
|
|
|
make html
|
|
|
|
'';
|
2023-10-18 06:04:34 -04:00
|
|
|
installPhase =
|
|
|
|
let
|
|
|
|
# Various versions of the Nix manuals, grep for (nix-manual)=
|
|
|
|
# FIXME: This requires human interaction to update!
|
|
|
|
# See ./CONTRIBUTING.md for details.
|
|
|
|
releases = [
|
|
|
|
"2.19"
|
|
|
|
"2.18"
|
|
|
|
"2.13"
|
|
|
|
];
|
|
|
|
inputName = version: pkgs.lib.strings.replaceStrings [ "." ] [ "-" ] version;
|
|
|
|
src = version: (import inputs."nix_${inputName version}").default.doc;
|
|
|
|
copy = version: ''
|
|
|
|
cp -R ${src version}/share/doc/nix/manual/* $out/manual/nix/${version}
|
|
|
|
'';
|
|
|
|
in
|
|
|
|
with pkgs.lib.strings;
|
|
|
|
''
|
|
|
|
mkdir -p $out/manual/nix/{${concatStringsSep "," releases}}
|
|
|
|
${concatStringsSep "\n" (map copy releases)}
|
|
|
|
cp -R build/html/* $out/
|
|
|
|
'';
|
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}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
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
|
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
|
|
|
];
|
|
|
|
};
|
|
|
|
}
|