From a693d9307bb1763eca43b5fa8ba1d04d27c7f62e Mon Sep 17 00:00:00 2001 From: "Wael M. Nasreddine" Date: Mon, 24 Dec 2018 17:47:49 -0800 Subject: [PATCH 1/5] Add support for compiling presentations in sub-folders The reveal.js files are now absolute and the reveal.js symlink is removed. This allows the HTML files to reside in any sub-folder without having to maintain relative dependencies. --- mkPresentation.nix | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mkPresentation.nix b/mkPresentation.nix index 505a760..3f36245 100644 --- a/mkPresentation.nix +++ b/mkPresentation.nix @@ -24,11 +24,11 @@ pkgs.stdenv.mkDerivation rec { buildInputs = with pkgs; [ pandoc ] ++ extraBuildInputs; installPhase = '' - mkdir $out for presentation in $(find . -name "*\.md"); do - id=$(basename $presentation ".md") - pandoc -t revealjs -s -o $out/"$id".html "$id".md + id="$(basename "$presentation" ".md")" + path="$(dirname "$presentation")" + mkdir -p "$out/$path" + pandoc --to=revealjs --variable revealjs-url=${revealJS} --resource-path="$path" --standalone --out="$out/$path/$id.html" "$presentation" done - ln -s ${revealJS} $out/reveal.js ''; } From 7a1f4baec665696344df9c7ce6cde343d2c33e55 Mon Sep 17 00:00:00 2001 From: "Wael M. Nasreddine" Date: Mon, 24 Dec 2018 17:49:49 -0800 Subject: [PATCH 2/5] Update the default revealJS version to 3.7.0 --- example/default.nix | 2 +- mkPresentation.nix | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/example/default.nix b/example/default.nix index 914f0dc..6c565c8 100644 --- a/example/default.nix +++ b/example/default.nix @@ -6,6 +6,6 @@ with pkgs.lib; src = ./.; name = "example-presentation"; # reveal version can be changed with revealJS - # 3.5.0 is used by default + # 3.7.0 is used by default revealVersion = "3.4.0"; } diff --git a/mkPresentation.nix b/mkPresentation.nix index 3f36245..bf1c5fd 100644 --- a/mkPresentation.nix +++ b/mkPresentation.nix @@ -4,7 +4,7 @@ pkgs , src , name -, revealVersion ? "3.5.0" +, revealVersion ? "3.7.0" # extra dependencies ,extraBuildInputs ? [] # assets to include in the result packages, typically examples From 55be9ea5d725ad66eef7e941c721ecf643b202f8 Mon Sep 17 00:00:00 2001 From: "Wael M. Nasreddine" Date: Mon, 24 Dec 2018 17:50:47 -0800 Subject: [PATCH 3/5] Add support for compiling self-contained presentations The resulting HTML file will have all assets inlined, that includes all reveal.js files as well as any embedded images in the markdown presentation. --- mkPresentation.nix | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/mkPresentation.nix b/mkPresentation.nix index bf1c5fd..3b2589a 100644 --- a/mkPresentation.nix +++ b/mkPresentation.nix @@ -5,30 +5,34 @@ , src , name , revealVersion ? "3.7.0" +, selfContained ? false # extra dependencies - ,extraBuildInputs ? [] +, extraBuildInputs ? [] # assets to include in the result packages, typically examples - ,assets ? [] +, assets ? [] }: let revealJS = fetchTarball "https://github.com/hakimel/reveal.js/archive/${revealVersion}.tar.gz"; in -pkgs.stdenv.mkDerivation rec { +with pkgs; +with pkgs.lib; + +stdenv.mkDerivation rec { inherit name src; preferLocalBuild = true; allowSubstitutes = false; # dependencies declaration - buildInputs = with pkgs; [ pandoc ] ++ extraBuildInputs; + buildInputs = [ pandoc ] ++ extraBuildInputs; installPhase = '' for presentation in $(find . -name "*\.md"); do id="$(basename "$presentation" ".md")" path="$(dirname "$presentation")" mkdir -p "$out/$path" - pandoc --to=revealjs --variable revealjs-url=${revealJS} --resource-path="$path" --standalone --out="$out/$path/$id.html" "$presentation" + pandoc --to=revealjs --variable revealjs-url=${revealJS} --resource-path="$src/$path" --standalone ${optionalString selfContained "--self-contained"} --out="$out/$path/$id.html" "$presentation" done ''; } From 92fa8d17891a25ce212ddb4c7fff55afc3c8f67e Mon Sep 17 00:00:00 2001 From: "Wael M. Nasreddine" Date: Mon, 24 Dec 2018 18:10:36 -0800 Subject: [PATCH 4/5] Remove unused assets --- mkPresentation.nix | 2 -- 1 file changed, 2 deletions(-) diff --git a/mkPresentation.nix b/mkPresentation.nix index 3b2589a..f5ff9e6 100644 --- a/mkPresentation.nix +++ b/mkPresentation.nix @@ -8,8 +8,6 @@ , selfContained ? false # extra dependencies , extraBuildInputs ? [] - # assets to include in the result packages, typically examples -, assets ? [] }: let revealJS = fetchTarball "https://github.com/hakimel/reveal.js/archive/${revealVersion}.tar.gz"; From 94c62f282d600ede9ff51a64ddcf0c19ad5afb2f Mon Sep 17 00:00:00 2001 From: "Wael M. Nasreddine" Date: Mon, 24 Dec 2018 18:35:06 -0800 Subject: [PATCH 5/5] Add support for passing variables to pandoc When using a reveal.js theme that is not the default theme and has `selfContained` enabled, Pandoc requires network access and this will not work with the sandbox enabled. You must disable the sandbox with `nix-build --option build-use-sandbox false`. --- example/default.nix | 3 +++ mkPresentation.nix | 13 +++++++++---- readme.md | 6 +++++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/example/default.nix b/example/default.nix index 6c565c8..9690262 100644 --- a/example/default.nix +++ b/example/default.nix @@ -8,4 +8,7 @@ with pkgs.lib; # reveal version can be changed with revealJS # 3.7.0 is used by default revealVersion = "3.4.0"; + extraPandocVariables = { + theme = "sky"; + }; } diff --git a/mkPresentation.nix b/mkPresentation.nix index f5ff9e6..0f2b98e 100644 --- a/mkPresentation.nix +++ b/mkPresentation.nix @@ -8,14 +8,19 @@ , selfContained ? false # extra dependencies , extraBuildInputs ? [] +, extraPandocVariables ? {} }: -let - revealJS = fetchTarball "https://github.com/hakimel/reveal.js/archive/${revealVersion}.tar.gz"; -in with pkgs; with pkgs.lib; +let + revealJS = fetchTarball "https://github.com/hakimel/reveal.js/archive/${revealVersion}.tar.gz"; + + extraVars = vars: + builtins.concatStringsSep "" (mapAttrsToList (name: value: "--variable " + name + "=" + value) vars); +in + stdenv.mkDerivation rec { inherit name src; @@ -30,7 +35,7 @@ stdenv.mkDerivation rec { id="$(basename "$presentation" ".md")" path="$(dirname "$presentation")" mkdir -p "$out/$path" - pandoc --to=revealjs --variable revealjs-url=${revealJS} --resource-path="$src/$path" --standalone ${optionalString selfContained "--self-contained"} --out="$out/$path/$id.html" "$presentation" + pandoc --to=revealjs --variable revealjs-url=${revealJS} ${extraVars extraPandocVariables} --resource-path="$src/$path" --standalone ${optionalString selfContained "--self-contained"} --out="$out/$path/$id.html" "$presentation" done ''; } diff --git a/readme.md b/readme.md index bd606fe..a122f62 100644 --- a/readme.md +++ b/readme.md @@ -5,5 +5,9 @@ example slides are in example/presentation.md. Can be built by running: ```sh -$ nix-build example +$ nix-build --option build-use-sandbox false example ``` + +NOTE that `--option build-use-sandbox false` is required when using a +different theme than the default one and when `selfContained` is enabled +because Pandoc needs network access.