export NIX_PATH=/nix/var/nix/profiles/per-user/root/channels/nixos
#export NIX_PATH=/nixpkgs-ra/nixpkgs
# reload when these files change
watch_file flake.nix
# watch_file flake.lock
## load the flake devShell
eval "$(nix print-dev-env)"
# echo $NIX_BUILD_TOP
export SpineVER=$(git describe --long --tags | sed 's/^[ a-z_-]\+\([0-9.]\+\)/\1/;s/\([^-]*-g\)/r\1/;s/-/./g')
export SpineSRC=/grotto-ra/repo/git.repo/projects/project-spine/doc-reform
export SpineBIN=/grotto-ra/repo/git.repo/projects/project-spine/doc-reform/result/bin
export SpineDOC=/grotto-ra/repo/git.repo/projects/project-spine/doc-reform-markup/spine-markup-samples
export SpinePOD=$SpineDOC/markup/pod
export SpineOUTversioned=/srv/www/spine/$SpineVER
export SpineOUTstatic=/srv/www/spine/static

echo '-*- mode: org -*-

* nixpkgs path?

  eval "$(nix print-dev-env)"
' > nix_note_.org

echo "  <nixpkgs> == `nix-instantiate --find-file nixpkgs`" >> nix_note_.org

echo '
* nix build and show derivation

#+BEGIN_SRC sh
nix-shell --pure

nix-build
nix build -f default.nix
nix shell -f default.nix
nix-instantiate | nix-build
nix build `nix-instantiate`

nix develop

nix-instantiate | nix show-derivation | jq
nix-instantiate | nix show-derivation --recursive | jq

nix search --json 2>/dev/null |jq
#+END_SRC

* version and build info

#+BEGIN_SRC sh' >> nix_note_.org

echo 'spine version (git) == $SpineVER' >> nix_note_.org
echo "spine version (git) == $SpineVER" >> nix_note_.org
echo 'nix-instantiate == `nix-instantiate`' >> nix_note_.org
echo "nix-instantiate == `nix-instantiate`" >> nix_note_.org

echo "#+END_SRC

* initialised shell variables

#+BEGIN_SRC sh
SpineSRC=$SpineSRC
SpineDOC=$SpineDOC
SpinePOD=$SpinePOD
SpineOUTversioned=$SpineOUTversioned
SpineOUTstatic=$SpineOUTstatic
#+END_SRC
" >> nix_note_.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 $SpineOUTstatic /var/www)

#+BEGIN_SRC sh
$SpineBIN/spine --very-verbose --sqlite-db-create --output="$SpineOUTstatic" $SpinePOD/*

$SpineBIN/spine -v --cgi-search-form-codegen --output=$SpineOUTstatic $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=$SpineOUTstatic $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="spine.search.db" --output="$SpineOUTstatic"
$SpineBIN/spine -v --sqlite-db-recreate --sqlite-db-filename="spine.search.db" --output="$SpineOUTstatic"
#+END_SRC

*** populate sqlite db

#+BEGIN_SRC sh
$SpineBIN/spine -v --sqlite-update --sqlite-db-filename="spine.search.db" --output=$SpineOUTstatic $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="spine.search.db" --cgi-sqlite-search-filename="spine_search" --output="$SpineOUTstatic" $SpinePOD/*
#+END_SRC

*** make search form

#+BEGIN_SRC sh
$SpineBIN/spine -v --cgi-search-form-codegen --config=$SpinePOD/.dr/config_local_site
#+END_SRC

' >> nix_note_.org

cat nix_note_.org

echo "emacs nix_note_.org"
echo "cat nix_note_.org"