diff --git a/README.md b/README.md index 0292d8e..29bda9d 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Official documentation for getting things done with Nix. ## Contributing -Run `./live` and open a browser at . +Run `nix-shell --run devmode` and open a browser at . As you make changes your browser should auto-reload within a few seconds. diff --git a/flake.nix b/flake.nix index 2ed694f..ee5561b 100644 --- a/flake.nix +++ b/flake.nix @@ -4,7 +4,7 @@ inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05"; inputs.flake-utils.url = "github:numtide/flake-utils"; - outputs = { self, nixpkgs, flake-utils}: + outputs = { self, nixpkgs, flake-utils }: flake-utils.lib.eachDefaultSystem (system: let pkgs = import nixpkgs { @@ -15,7 +15,36 @@ (import ./overlay.nix) ]; }; - in { + devmode = + let + pythonEnvironment = pkgs.python310.withPackages (ps: with ps; [ + livereload + ]); + script = '' + from livereload import Server, shell + + server = Server() + + build_docs = shell("nix build") + + print("Doing an initial build of the docs...") + build_docs() + + server.watch("source/*", build_docs) + server.watch("source/**/*", build_docs) + server.watch("_templates/*.html", build_docs) + server.serve(root="result/") + ''; + in + pkgs.writeShellApplication { + name = "devmode"; + runtimeInputs = [ pythonEnvironment ]; + text = '' + python ${pkgs.writeText "live.py" script} + ''; + }; + in + { packages.default = pkgs.stdenv.mkDerivation { name = "nix-dev"; src = self; @@ -39,17 +68,10 @@ }; devShells.default = pkgs.mkShell { - buildInputs = with pkgs.python310.pkgs; [ + inputsFrom = [ self.packages.${system}.default ]; + packages = with pkgs.python310.pkgs; [ black - livereload - linkify-it-py - myst-parser - sphinx - sphinx-book-theme - sphinx-copybutton - sphinx-design - sphinx-notfound-page - sphinx-sitemap + devmode ]; }; } diff --git a/live b/live deleted file mode 100755 index a3cd512..0000000 --- a/live +++ /dev/null @@ -1 +0,0 @@ -nix-shell --run "python live.py" diff --git a/live.py b/live.py deleted file mode 100644 index 3ca621b..0000000 --- a/live.py +++ /dev/null @@ -1,13 +0,0 @@ -from livereload import Server, shell - -server = Server() - -build_docs = shell("make html") - -print("Doing an initial build of the docs...") -build_docs() - -server.watch("source/*", build_docs) -server.watch("source/**/*", build_docs) -server.watch("_templates/*.html", build_docs) -server.serve(root="build/html")