-*- mode: org -*- #+TITLE: configuration nix #+DESCRIPTION: makefile for spine #+FILETAGS: :spine:build:tools: #+AUTHOR: Ralph Amissah #+EMAIL: [[mailto:ralph.amissah@gmail.com][ralph.amissah@gmail.com]] #+COPYRIGHT: Copyright (C) 2015 - 2023 Ralph Amissah #+LANGUAGE: en #+STARTUP: show4levels hideblocks hidestars noindent entitiespretty #+PROPERTY: header-args :exports code #+PROPERTY: header-args+ :noweb yes #+PROPERTY: header-args+ :results no #+PROPERTY: header-args+ :cache no #+PROPERTY: header-args+ :padline no #+PROPERTY: header-args+ :mkdirp yes #+OPTIONS: H:3 num:nil toc:t \n:t ::t |:t ^:nil -:t f:t *:t - [[./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.flake-utils.url = "github:numtide/flake-utils"; inputs.spine = { url = "git+file:///home/ralph/grotto/repo/git.repo/projects/doc-reform/code/software/spine"; inputs.nixpkgs.follows = "nixpkgs"; flake = true; }; inputs.d-overlay = { url = "git+file:///home/ralph/grotto/repo/git.repo/projects/doc-reform/packages/nix-flakes/dlang/dlang-nix-flakes"; inputs.nixpkgs.follows = "nixpkgs"; flake = true; }; outputs = { self, nixpkgs, flake-utils, spine, d-overlay, } @ inputs: let version = "<>"; shell = ./shell.nix; # ./default.nix; devEnv = ./.envrc; # ./shell.nix; # ./default.nix; 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: let pkgs = nixpkgsFor.${system}; in { default = spine.packages.${system}.default; spine-overlay-ldc = spine.packages.${system}.spine-overlay-ldc; spine-nixpkgs-ldc = spine.packages.${system}.spine-nixpkgs-ldc; #spine-overlay-dmd = spine.packages.${system}.spine-overlay-dmd; #spine-overlay-ldc = spine.packages.${system}.spine-overlay-ldc; #spine-overlay-gdc = spine.packages.${system}.spine-overlay-gdc; #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; #buildInputs = [ sqlite ]; #nativeBuildInputs = [ dub dmd ldc gdc gnumake ]; packages = [ ldc #dmd dub gnumake sqlite ]; inherit shellHook; }; dsh-spine = spine.devShells.${system}.default; dsh-overlay-ldc = d-overlay.devShells.${system}.default; dsh-epub = mkShell { name = "spine dev shell for epub output"; inherit shell; inherit devEnv; packages = [ ldc #dmd dub gnumake sqlite libxml2 html-tidy xmlstarlet epubcheck ebook_tools libxml2 html-tidy xmlstarlet epubcheck ebook_tools epr sigil calibre #(suite includes: ebook-viewer) foliate ]; inherit shellHook; }; dsh-html = mkShell { name = "spine dev shell for latex & pdf output"; inherit shell; inherit devEnv; packages = [ ldc #dmd dub gnumake sqlite ]; inherit shellHook; }; dsh-latex-pdf = mkShell { name = "spine dev shell for latex & pdf output"; inherit shell; inherit devEnv; packages = [ ldc #dmd dub gnumake sqlite source-sans-pro source-serif-pro source-code-pro texlive.combined.scheme-full ]; inherit shellHook; }; dsh-sqlite = mkShell { name = "spine dev shell for latex & pdf output"; inherit shell; inherit devEnv; packages = [ ldc #dmd dub gnumake sqlite ]; inherit shellHook; }; dsh-i18n = mkShell { name = "spine dev shell internationalization, po4a"; inherit shell; inherit devEnv; packages = [ ldc #dmd dub gnumake sqlite perl538Packages.Po4a ]; inherit shellHook; }; 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 {pkgs ? import {}}: with pkgs; mkShell { buildInputs = [ # ❯❯❯ nix_related ##nix #direnv #nixVersions.unstable #nixFlakes #nix-prefetch-git #validatePkgConfig nix-output-monitor #nix-tree #jq #alejandra #git # ❯❯❯ dev #gnumake #ps # ❯❯❯ d_build_related # ❯❯ package manager #dub # ❯❯ compiler #ldc ##rund # ❯❯ linker ##lld ##mold # ❯❯ builder ##ninja ##meson # ❯❯❯ sqlite search related #sqlite # ❯❯❯ pdf_latex_related # source-sans-pro # source-serif-pro # source-code-pro # texlive.combined.scheme-full # ❯❯❯ xml_and_epub_related # libxml2 # html-tidy # xmlstarlet # epubcheck # ebook_tools # epr # sigil # calibre #(suite includes: ebook-viewer) # foliate # ❯❯❯ i18n translation related # perl538Packages.Po4a ]; shellHook = '' ''; } #+END_SRC #+BEGIN_SRC nix shellHook = '' echo ' shell.nix echo ❯❯ ❯❯ nix flake update && nix flake check --show-trace && nix flake show && nix develop ".#devShell" -c zsh ❯❯ nix develop ❯❯ nix develop -c zsh ❯❯ nix develop ".#default" -c zsh ❯❯ nix develop ".#devShell-ldc-overlay" -c zsh ❯❯ nix build ❯❯ nix build ".#default" --print-build-logs ❯❯ nix build ".#spine-ldc" --print-build-logs |& nom ❯❯ nix profile install . ' ''; #+END_SRC #+HEADER: :tangle ../default.nix #+HEADER: :tangle-mode (identity #o755) #+HEADER: :shebang "#!/usr/bin/env -S nix-build" #+BEGIN_SRC nix {pkgs ? import {}}: pkgs.callPackage ./devenv.nix {} #+END_SRC * devEnv nix profile install . #+HEADER: :tangle ../devenv.nix #+HEADER: :tangle-mode (identity #o644) #+BEGIN_SRC nix { pkgs ? import {}, name ? "user-env", }: with pkgs; buildEnv { inherit name; extraOutputsToInstall = ["out" "man" "lib"]; # to get all needed symlinks paths = [ # ❯❯❯ nix_related #nix # if not on NixOS, this is needed direnv nixVersions.unstable #nixFlakes nix-prefetch-git validatePkgConfig nix-output-monitor nix-tree jq alejandra git # ❯❯❯ dev gnumake ps # ❯❯❯ d_build_related # ❯❯ package manager dub # ❯❯ compiler ldc # ❯❯❯ sqlite search related sqlite # this will create a script that will rebuild and upgrade your setup; using shell script syntax (writeScriptBin "nix-rebuild" '' #!${stdenv.shell} #cd || exit 1 nix flake update nix profile upgrade '.*' '') # puts in your root the nixpkgs version (writeTextFile { name = "nixpkgs-version"; destination = "/nixpkgs-version"; text = lib.version; }) ]; } #+END_SRC ** derivation.nix :default: #+HEADER: :tangle ../derivation.nix #+HEADER: :tangle-mode (identity #o644) #+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" DFLAGS="-O2 -inline" 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/spine-markup-samples/. #cp -rv ./markup $out/spine-markup-samples/. runHook postInstall ''; #postInstall= '' # cp -rv ./markup $out/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 = "<>"; #zipfile = "spine-0.12.0-tag-0.11.2.r107.gf89a107.tar.gz"; src = fetchTarball { url = "<>"; sha256 = "<>"; }; nativeBuildInputs = with pkgs; [dub ldc]; buildInputs = with pkgs; [nixVersions.unstable 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 #src = ./.; ** variables used SET *** spine version SET VERSION :version:set:project: #+NAME: spine_version_set #+BEGIN_SRC sh 0.12.0 #+END_SRC #+NAME: project_path_local_out_static #+HEADER: :noweb yes #+BEGIN_SRC nix /srv/www/spine #+END_SRC #+NAME: spine_tarball_path #+HEADER: :noweb yes #+BEGIN_SRC nix /home/ralph/grotto/repo/git.repo/projects/doc-reform/code/software/tarball #+END_SRC #+NAME: spine_tarball_path_url #+HEADER: :noweb yes #+BEGIN_SRC nix file://<>/<> #+END_SRC #+NAME: spine_git_file_path #+HEADER: :noweb yes #+BEGIN_SRC nix /home/ralph/grotto/repo/git.repo/projects/doc-reform/code/software/spine #+END_SRC #+NAME: nixpkgs_local #+BEGIN_SRC sh /srv/nixpkgs-dev/nixpkgs #+END_SRC #+NAME: spine_git_file_path_url #+HEADER: :noweb yes #+BEGIN_SRC nix git+file://<> #+END_SRC #+NAME: spine_tarball_filename #+HEADER: :noweb yes #+BEGIN_SRC nix spine-0.12.0-tag-0.11.2.r107.gf89a107.tar.gz #+END_SRC #+NAME: spine_tarball_sha256 #+HEADER: :noweb yes #+BEGIN_SRC nix sha256:03dr7dn7kq6arw4ry7qar13iqmi1caw70imfjwi8qr7g2j4mnk2q #+END_SRC #+BEGIN_SRC nix sha256:0000000000000000000000000000000000000000000000000000 #+END_SRC /home/ralph/grotto/repo/git.repo/projects/project-spine/tarball #+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 #+BEGIN_SRC nix "nixpkgs/nixos-23.05"; #+END_SRC #+HEADER: :noweb yes #+BEGIN_SRC nix <> #+END_SRC ** .env/echo-nixNote CHECK MODIFY *** notes on nix commands #+HEADER: :tangle ../.env/nix-commands #+BEGIN_SRC text - nix flake update && nix flake check --show-trace && nix flake show && nix develop .#devShell - nix build ".#default" --print-build-logs - nix build ".#spine-dmd" --print-build-logs - nix build ".#spine-ldc" --print-build-logs - nix build ".#spine-gdc" --print-build-logs - nix develop - nix develop ".#devShell" --print-build-logs - nix develop ".#devShell-html" --print-build-logs - nix develop ".#devShell-epub" --print-build-logs - nix develop ".#devShell-latex-pdf" --print-build-logs - nix develop ".#devShell-sqlite" --print-build-logs - nix develop ".#devShell-i18n" --print-build-logs nix run .#default --print-build-logs nix develop --build ".#default" --print-build-logs nix-shell '' -A nix --pure #+END_SRC *** echo-nixNote #+HEADER: :tangle ../.env/echo-nixNote #+BEGIN_SRC sh echo '-*- mode: org -*- ,* nixpkgs path? # eval "$(nix print-dev-env)" ' > nixNote_.org echo " == `nix-instantiate --find-file nixpkgs`" >> nixNote_.org echo ' ,* nix build and show derivation ,#+BEGIN_SRC sh nix-shell --pure nix-build nix build -f default.nix --print-build-logs nix shell -f default.nix --print-build-logs nix develop --build -f derivation.nix -I .envrc --print-build-logs nix-instantiate | nix-build nix-instantiate -I .envrc | nix-build -I .envrc nix build `nix-instantiate` nix build `nix-instantiate -I .envrc` nix develop nix-instantiate | nix show-derivation | jq nix-instantiate -I .envrc | nix show-derivation -f derivation.nix -I .envrc | jq nix-instantiate | nix show-derivation --recursive | jq nix-instantiate -I .envrc | nix show-derivation -f derivation.nix --recursive -I .envrc | jq nix search --json 2>/dev/null |jq ,#+END_SRC ,* version and build info ,#+BEGIN_SRC sh' >> nixNote_.org echo 'spine version (git) == $SpineVER' >> nixNote_.org echo "spine version (git) == $SpineVER" >> nixNote_.org echo 'nix-instantiate == `nix-instantiate`' >> nixNote_.org echo "nix-instantiate == `nix-instantiate`" >> nixNote_.org echo "#+END_SRC ,* initialised shell variables ,#+BEGIN_SRC sh SpineSRC=$SpineSRC SpineDOC=$SpineDOC SpinePOD=$SpinePOD SpineOUTversioned=$SpineOUTversioned SpineOUT=$SpineOUT ,#+END_SRC " >> nixNote_.org echo '* spine run instruction examples ,** parallelized tasks ,*** doc source ,#+BEGIN_SRC sh $SpineBIN/spine --very-verbose --pod --source --output="$SpineOUTversioned" $SpinePOD/* ,#+END_SRC ,*** html & epub output ,#+BEGIN_SRC sh $SpineBIN/spine --very-verbose --html --epub --output="$SpineOUTversioned" $SpinePOD/* ,#+END_SRC ,*** sqlite db for each document - populate each db ,#+BEGIN_SRC sh $SpineBIN/spine --very-verbose --sqlite-discrete --output="$SpineOUTversioned" $SpinePOD/* ,#+END_SRC ,*** doc source; html, epub; sqlite outputs ,#+BEGIN_SRC sh $SpineBIN/spine --verbose --pod --html --epub --sqlite-discrete --output="$SpineOUTversioned" $SpinePOD/* ,#+END_SRC ,*** curate (authors topics) ,#+BEGIN_SRC sh $SpineBIN/spine --very-verbose --curate --output="$SpineOUTversioned" $SpinePOD/* ,#+END_SRC ,*** html, curate ,#+BEGIN_SRC sh $SpineBIN/spine --verbose --dark --html --html-link-curate --curate --output="$SpineOUTversioned" $SpinePOD/* $SpineBIN/spine --very-verbose --html --html-link-curate --curate --output="$SpineOUTversioned" $SpinePOD/* ,#+END_SRC ,*** composite command: source pod, html, epub, curate, sqlite ,#+BEGIN_SRC sh $SpineBIN/spine --verbose --dark --pod --epub --html --html-link-curate --curate --sqlite-discrete --output="$SpineOUTversioned" $SpinePOD/* ,#+END_SRC ,** sequential tasks ,*** sqlite db (shared) - create db ,#+BEGIN_SRC sh $SpineBIN/spine --very-verbose --sqlite-db-create --output="$SpineOUTversioned" ,#+END_SRC ,*** sqlite db (shared) - populate db ,#+BEGIN_SRC sh $SpineBIN/spine --very-verbose --sqlite-update --output="$SpineOUTversioned" $SpineDOC/spine-markup-samples/markup/pod/* ,#+END_SRC ,*** sqlite db (shared) - drop db ,#+BEGIN_SRC sh $SpineBIN/spine --very-verbose --sqlite-db-drop --output="$SpineOUTversioned" ,#+END_SRC ,*** sqlite db (shared) - create & populate db (single step) ,#+BEGIN_SRC sh $SpineBIN/spine --very-verbose --sqlite-db-create --sqlite-update --output="$SpineOUTversioned" $SpinePOD/* ,#+END_SRC ,*** composite command: source pod, html, epub, curate, sqlite ,#+BEGIN_SRC sh $SpineBIN/spine --verbose --no-parallel --dark --pod --epub --html --html-link-curate --curate --sqlite-discrete --output="$SpineOUTversioned" $SpinePOD/* ,#+END_SRC ,** config [./pod/].dr/config_local_site ,#+BEGIN_SRC sh cat $SpinePOD/.dr/config_local_site $SpineBIN/spine --show-config $SpinePOD $SpineBIN/spine --show-config --output="$SpineOUTversioned" $SpinePOD ,#+END_SRC ,** cgi operations (output to $SpineOUT /var/www) ,#+BEGIN_SRC sh $SpineBIN/spine --very-verbose --sqlite-db-create --output="$SpineOUT" $SpinePOD/* $SpineBIN/spine -v --cgi-search-form-codegen --output=$SpineOUT $SpinePOD/* $SpineBIN/spine -v --show-config --config=$SpinePOD/.dr $SpineBIN/spine --html $SpinePOD/* $SpineBIN/spine -v --cgi-search-form-codegen --config=$SpinePOD/.dr/config_local_site ,#+END_SRC ,*** generate html linked to search form ,#+BEGIN_SRC sh $SpineBIN/spine -v --html --html-link-search --html-link-curate --curate --output=$SpineOUT $SpinePOD/* ,#+END_SRC ,*** create or re-create sql db (--sqlite-db-create or --sqlite-db-recreate) ,#+BEGIN_SRC sh $SpineBIN/spine -v --sqlite-db-create --sqlite-db-filename="<>" --sqlite-db-path="$SpineDBpath" $SpineBIN/spine -v --sqlite-db-recreate --sqlite-db-filename="<>" --sqlite-db-path="$SpineDBpath" ,#+END_SRC ,*** populate sqlite db ,#+BEGIN_SRC sh $SpineBIN/spine -v --sqlite-update --sqlite-db-filename="<>" --output=$SpineOUT $SpinePOD/* ,#+END_SRC ,*** generate html (linked to search form), sql output, curate COMPOSITE ,#+BEGIN_SRC sh $SpineBIN/spine -v --html --html-link-search --html-link-curate --curate --sqlite-update --sqlite-db-filename="<>" --cgi-sqlite-search-filename="<>" --sqlite-db-path="$SpineDBpath" --output="$SpineOUT" $SpinePOD/* $SpineBIN/spine --epub --html --html-link-search --html-link-curate --curate --sqlite-update --sqlite-db-filename="spine.search.db" --cgi-sqlite-search-filename="spine_search" --cgi-url-action="https://sisudoc.org/spine_search" --ouput="$SpineOUT" $SpinePOD/* ,#+END_SRC ,*** generate html (linked to search form), sql output, curate COMPOSITE with resource configuration if names and paths are configured in resource configuration file, e.g. $SpinePOD/.rc/config_local_site ,#+BEGIN_SRC sh $SpineBIN/spine -v --html --html-link-search --html-link-curate --curate --sqlite-update $SpinePOD/* ,#+END_SRC ,#+BEGIN_SRC yaml # sample resource configuration file ( $SpinePOD/.rc/config_local_site ) output: path: "/srv/www/spine" default: language: "en" papersize: "a4" text_wrap: "80" digest: "sha256" webserv: http: "http" domain: "localhost" data_http: "http" data_domain: "localhost" data_root_url: "https://sisudoc.org" data_root_path: "/srv/www/spine" images_root_part: "image" cgi_search_form_title: "≅ SiSU Spine search" cgi_http: "https" cgi_domain: "sisudoc.org" cgi_bin_url: "http://sisudoc.org/cgi-bin" cgi_bin_part: "cgi-bin" cgi_bin_path: "/var/www/cgi/cgi-bin" cgi_search_script: "<>" cgi_action: "https://sisudoc.org/spine_search" db_sqlite_filename: "<>" db_sqlite_path: "/var/www/sqlite" ,#+END_SRC ,*** make search form ,#+BEGIN_SRC sh $SpineBIN/spine -v --cgi-search-form-codegen --config=$SpinePOD/.dr/config_local_site ,#+END_SRC ,*** latex ,#+BEGIN_SRC sh $SpineBIN/spine --latex --serial --output="$SpineOUT" $SpinePOD/* ls $SpineOutstatic/latex/*.tex ,#+END_SRC ' >> nixNote_.org #cat nixNote_.org #echo "emacs nixNote_.org" #echo "cat nixNote_.org" #+END_SRC