-*- mode: org -*- #+TITLE: sisudoc spine (doc_reform) (project) configuration nix #+DESCRIPTION: configuration nix #+FILETAGS: :spine:build:tools: #+AUTHOR: Ralph Amissah #+EMAIL: [[mailto:ralph.amissah@gmail.com][ralph.amissah@gmail.com]] #+COPYRIGHT: Copyright (C) 2015 (continuously updated, current 2026) Ralph Amissah #+LANGUAGE: en #+STARTUP: content hideblocks hidestars noindent entitiespretty #+PROPERTY: header-args+ :eval never-export :exports code #+PROPERTY: header-args+ :noweb yes :padline no #+PROPERTY: header-args+ :results silent :cache no #+PROPERTY: header-args+ :mkdirp yes #+OPTIONS: H:3 num:nil toc:t \n:t ::t |:t ^:nil -:t f:t *:t - magic single double-quote → " ← FIX changes hilighting behavior (occuring after it) in org document. INVESTIGATE (org-mode CONFIG?) FIND & FIX - [[./config_env.org][config_env.org]] * nix :nix: ** flake.nix :flake: #+HEADER: :tangle ../flake.nix #+HEADER: :noweb yes #+BEGIN_SRC nix { description = "spine (sisu like parser & document generator) made available to process markup samples"; inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; inputs.spine = { url = "<>"; inputs.nixpkgs.follows = "nixpkgs"; }; inputs.d-overlay = { url = "<>"; inputs.nixpkgs.follows = "nixpkgs"; }; outputs = { self, nixpkgs, spine, d-overlay, ... }@inputs: let version = "<>"; shell = ./shell.nix; devEnv = ./nixDevEnv.sh; supportedSystems = ["x86_64-linux"]; # [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ]; forAllSystems = nixpkgs.lib.genAttrs supportedSystems; nixpkgsFor = forAllSystems (system: import nixpkgs {inherit system;}); # nixpkgs instantiated for supported system types in { packages = forAllSystems (system: { default = spine.packages.${system}.default; spine-nixpkgs-dmd = spine.packages.${system}.spine-nixpkgs-dmd; spine-overlay-dmd = spine.packages.${system}.spine-overlay-dmd; spine-nixpkgs-ldc = spine.packages.${system}.spine-nixpkgs-ldc; spine-overlay-ldc = spine.packages.${system}.spine-overlay-ldc; #vendorSha256 = "sha256-0Q00000000000000000000000000000000000000000="; }); apps = forAllSystems (system: { default = { type = "app"; program = "${self.packages.${system}.default}/bin/spine"; }; }); devShells = forAllSystems (system: let pkgs = nixpkgsFor.${system}; shellHook = '' export DFLAGS="-O2 -boundscheck=on" export Date=$(date "+%Y%m%d") ## set local values in .envrc-local (or here if you must) ''; in with pkgs; { dsh = mkShell { name = "spine base dev shell"; inherit shell; inherit devEnv; packages = [ ldc #dmd dub gnumake sqlite ]; inherit shellHook; }; dsh-spine = spine.devShells.${system}.default; dsh-overlay-dmd = d-overlay.devShells.${system}.dsh-overlay-dmd; dsh-nixpkgs-dmd = d-overlay.devShells.${system}.dsh-nixpkgs-dmd; dsh-overlay-ldc = d-overlay.devShells.${system}.dsh-overlay-ldc; dsh-nixpkgs-ldc = d-overlay.devShells.${system}.dsh-nixpkgs-ldc; dsh-epub = mkShell { name = "spine-${version} dev shell for epub output"; inherit shell; inherit devEnv; packages = [ direnv nix-direnv ldc #dmd dub gnumake sqlite libxml2 html-tidy xmlstarlet epubcheck ebook_tools epr sigil calibre #(suite includes: ebook-viewer) koreader foliate ]; inherit shellHook; }; dsh-html = mkShell { name = "spine-${version} dev shell for html output"; inherit shell; inherit devEnv; packages = [ direnv nix-direnv ldc #dmd dub gnumake sqlite # ❯❯ text-mode web browsers elinks links2 lynx w3m # ❯❯ light graphical #dillo ]; inherit shellHook; }; dsh-latex-pdf = mkShell { name = "spine-${version} dev shell for latex & pdf output"; inherit shell; inherit devEnv; packages = [ direnv nix-direnv ldc #dmd dub gnumake source-sans-pro source-serif-pro source-code-pro texlive.combined.scheme-full ]; inherit shellHook; }; dsh-sqlite = mkShell { name = "spine-${version} dev shell for sqlite3 output"; inherit shell; inherit devEnv; packages = [ direnv nix-direnv ldc #dmd dub gnumake sqlite ]; inherit shellHook; }; dsh-i18n = mkShell { name = "spine-${version} dev shell for internationalization, po4a"; inherit shell; inherit devEnv; packages = [ direnv nix-direnv ldc #dmd dub gnumake sqlite perlPackages.Po4a ]; inherit shellHook; }; dsh-build-spine-generate-samples-env-defaults = mkShell { name = "spine-${version} dev shell test build spine and generate samples env defaults"; inherit shell; inherit devEnv; packages = [ nix sqlite #chromium #calibre #(suite includes: ebook-viewer) ]; shellHook = '' export DFLAGS="-O2 -boundscheck=on" ## set local values in .envrc-local (or here if you must) nix build ".#spine-overlay-ldc" --print-build-logs #$SpineBIN -v --source --pod --epub --html --html-link-curate --html-link-markup --curate --output=$SpineOUT $SpinePOD/* $SpineBIN --very-verbose --sqlite-db-recreate --sqlite-db-filename=$SpineSQLdb --sqlite-db-path=./_tmp-db $SpineBIN --very-verbose --source --pod --epub --html --html-link-curate --html-link-markup --sqlite-update --sqlite-db-filename=$SpineSQLdb --sqlite-db-path=./_tmp-db --curate --output=$SpineOUT $SpinePOD/* echo "./result/bin/spine -v --source --pod --epub --html --html-link-curate --html-link-markup --curate --output=$SpineOUT $SpinePOD/*" ''; }; dsh-build-spine-generate-samples-test = mkShell { name = "spine-${version} dev shell test build spine and generate samples test"; inherit shell; inherit devEnv; packages = [ nix sqlite #chromium #calibre #(suite includes: ebook-viewer) ]; shellHook = '' export DFLAGS="-O2 -boundscheck=on" ## set local values in .envrc-local (or here if you must) nix build ".#spine-overlay-ldc" --print-build-logs #./result/bin/spine -v --source --pod --epub --html --html-link-curate --html-link-markup --curate --output=./OUTPUT_TEST_sisudocSpine ./markup/pod-samples/pod/* ./result/bin/spine --very-verbose --sqlite-db-recreate --sqlite-db-filename=spine.search.db --sqlite-db-path=./_tmp-db ./result/bin/spine --very-verbose --source --pod --epub --html --html-link-curate --html-link-markup --sqlite-update --sqlite-db-filename=spine.search.db --sqlite-db-path=./_tmp-db --curate --output=./OUTPUT_TEST_sisudocSpine ./markup/pod-samples/pod/* echo "./result/bin/spine -v --source --pod --epub --html --html-link-curate --html-link-markup --curate --output=./OUTPUT_TEST_sisudocSpine ./markup/pod-samples/pod/*" ''; }; default = self.devShells.${system}.dsh; #default = import ./shell.nix {inherit pkgs;}; }); }; } #+END_SRC ** shell.nix :shell: #+HEADER: :tangle ../shell.nix #+HEADER: :tangle-mode (identity #o755) #+HEADER: :shebang "#!/usr/bin/env -S nix-shell --pure\n#!nix-shell -i bash" #+HEADER: :noweb yes #+BEGIN_SRC nix # Development environment for sisudoc-spine-samples. # Basic dev shell mirroring the flake's default devShell (`dsh`), # with the flake's default package (spine) built and put on PATH. # # Usage: # nix-shell # enters shell, builds spine via the flake # nix-shell --run 'spine --version' # runs spine after build # # Requires: experimental-features = nix-command flakes { pkgs ? import {}, flake ? builtins.getFlake (toString ./.), # captured at eval time - nix-shell rewrites $SHELL at runtime, # so we must remember the user's real login shell here. userShell ? builtins.getEnv "SHELL", }: let spine = flake.packages.${pkgs.stdenv.hostPlatform.system}.default; in with pkgs; mkShell { name = "spine base dev shell"; packages = [ # ❯❯❯ flake default build (spine binary) spine # ❯❯❯ d_build_related ldc #dmd dub # ❯❯❯ dev gnumake # ❯❯❯ sqlite search related sqlite # ❯❯❯ xml_and_epub_related # libxml2 # html-tidy # xmlstarlet # epubcheck # ebook_tools # epr # sigil # calibre #(suite includes: ebook-viewer) # koreader # foliate # ❯❯❯ pdf reader # evince # ❯❯❯ i18n translation related # perlPackages.Po4a ]; shellHook = '' export DFLAGS="-O2 -boundscheck=on" export Date=$(date "+%Y%m%d") ## set local values in .envrc-local (or here if you must) echo "spine: $(command -v spine)" ## hand off to the user's login shell (e.g. zsh) only when this is ## an interactive nix-shell entry - not under `nix-shell --run` or ## `--command`, where exec would swallow the command. Guard env var ## prevents re-entry loops. __spine_user_shell=${if userShell == "" then "" else "\"" + userShell + "\""} if [ -z "$__SPINE_SHELL_HANDOFF" ] \ && [ -n "$__spine_user_shell" ] \ && [ "$(basename "$__spine_user_shell")" != "bash" ] \ && [[ $- == *i* ]]; then export __SPINE_SHELL_HANDOFF=1 spine --version exec "$__spine_user_shell" fi unset __spine_user_shell spine --version ''; } #+END_SRC ** derivation.nix :default: #+HEADER: :tangle ../derivation.nix #+HEADER: :tangle-mode (identity #o755) #+HEADER: :shebang "#!/usr/bin/env -S nix-build derivation.nix" #+HEADER: :noweb yes #+BEGIN_SRC nix { pkgs ? import {}, stdenv ? pkgs.stdenv, lib ? pkgs.lib, ldc ? null, dcompiler ? pkgs.ldc, dub ? pkgs.dub, }: assert dcompiler != null; with ( with lib; let filterDub = name: type: let baseName = baseNameOf (toString name); in ! ( # filter function to remove the .dub package folder from src type == "directory" && baseName == ".dub" ); targetOf = package: "${package.targetPath or "."}/${package.targetName or package.name}"; # remove reference to build tools and library sources disallowedReferences = deps: [dcompiler dub]; removeExpr = refs: ''remove-references-to ${lib.concatMapStrings (ref: " -t ${ref}") refs}''; in { mkDubDerivation = lib.makeOverridable ({ src, nativeBuildInputs ? [], dubJSON ? src + "/dub.json", passthru ? {}, package ? lib.importJSON dubJSON, ... } @ attrs: stdenv.mkDerivation (attrs // { pname = package.name; nativeBuildInputs = [dcompiler dub pkgs.removeReferencesTo] ++ nativeBuildInputs; disallowedReferences = disallowedReferences deps; passthru = passthru // { inherit dub dcompiler pkgs; }; src = lib.cleanSourceWith { filter = filterDub; src = lib.cleanSource src; }; preFixup = '' find $out/bin -type f -exec ${removeExpr (disallowedReferences deps)} '{}' + || true ''; buildPhase = '' runHook preBuild HOME="$PWD" for DC_ in dmd ldmd2 gdmd; do echo "- check for D compiler $DC_" DC=$(type -P $DC_ || echo "") if [ ! "$DC" == "" ]; then break fi done if [ "$DC" == "" ]; then exit "Error: could not find D compiler" fi echo "$DC_ used as D compiler to build $pname" dub build --compiler=$DC --build=release --combined --skip-registry=all runHook postBuild ''; checkPhase = '' runHook preCheck HOME="$PWD" dub test --combined --skip-registry=all runHook postCheck ''; installPhase = '' runHook preInstall mkdir -p $out/bin cp -r "${targetOf package}" $out/bin #cp -rv "${targetOf package}" $out/sisudoc-spine-markup-samples/. #cp -rv ./markup $out/sisudoc-spine-markup-samples/. runHook postInstall ''; #postInstall= '' # cp -rv ./markup $out/sisudoc-spine-markup-samples/. #''; meta = lib.optionalAttrs (package ? description) { description = package.description; } // attrs.meta or {}; } // lib.optionalAttrs (!(attrs ? version)) { name = package.name; # use name from dub.json, unless pname and version are specified })); } ); mkDubDerivation rec { pname = "spine"; version = "<>"; # fetched from the same upstream the flake's `inputs.spine` points at # (git://git.sisudoc.org/software/sisudoc-spine). Unlike flake inputs, # builtins.fetchGit is usable from a plain (non-flake) derivation.nix. src = builtins.fetchGit { url = "git://git.sisudoc.org/software/sisudoc-spine"; ref = "main"; shallow = true; }; nativeBuildInputs = with pkgs; [dub ldc]; buildInputs = with pkgs; [nixVersions.latest sqlite]; meta = with pkgs.lib; { description = "A sisu like parser & document generator"; longDescription = '' a sisu like parser & document generator ''; homepage = "https://sisudoc.org"; license = licenses.agpl3Plus; platforms = platforms.linux; maintainers = ["RalphAmissah"]; }; } #+END_SRC #+NAME: project_path_local_out_static #+HEADER: :noweb yes #+BEGIN_SRC nix /srv/www/spine #+END_SRC #+NAME: project_path_local_out_static_ #+BEGIN_SRC nix /var/www #+END_SRC #+NAME: project_path_sqlite #+BEGIN_SRC nix /var/www/sqlite #+END_SRC #+NAME: nixpkgs_url #+BEGIN_SRC nix github:nixos/nixpkgs #+END_SRC #+BEGIN_SRC nix github:NixOS/nixpkgs/nixpkgs-unstable #+END_SRC #+BEGIN_SRC nix "nixpkgs/nixos-unstable"; #+END_SRC * SHARED ** version and other things shared *** spine project VERSION :version:set:project: #+NAME: spine_version #+HEADER: :noweb yes #+BEGIN_SRC emacs-lisp <<./sisudoc_spine_version_info_and_doc_header_including_copyright_and_license.org:spine_project_version()>> #+END_SRC *** spine project git sources **** spine project git sources url #+NAME: sisudoc_spine_nix_src #+HEADER: :noweb yes #+BEGIN_SRC emacs-lisp <<./sisudoc_spine_version_info_and_doc_header_including_copyright_and_license.org:sisudoc_spine_nix_src()>> #+END_SRC *** spine project git sources url **** spine project git sources overlay url #+NAME: sisudoc_dlang_nix_overlay_src #+HEADER: :noweb yes #+BEGIN_SRC emacs-lisp <<./sisudoc_spine_version_info_and_doc_header_including_copyright_and_license.org:sisudoc_dlang_nix_overlay_src()>> #+END_SRC