-*- mode: org -*-
#+TITLE:       sisudoc spine (doc_reform) (project) environment
#+DESCRIPTION: env envrc used by make & nix
#+FILETAGS:    :spine:build:tools:
#+AUTHOR:      Ralph Amissah
#+EMAIL:       [[mailto:ralph.amissah@gmail.com][ralph.amissah@gmail.com]]
#+COPYRIGHT:   Copyright (C) 2015 - 2025 Ralph Amissah
#+LANGUAGE:    en
#+STARTUP:     content 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

- [[./doc-reform.org][doc-reform.org]]  [[../org/][org/]]
- [[./config_nix.org][config_nix.org]]
- [[./config_make.org][config_make.org]]

* envrc
** nixDevEnv envrc :envrc:

#+HEADER: :tangle ../nixDevEnv.sh
#+BEGIN_SRC shell
if [ -f .envrc ]; then
  source_env_if_exists .envrc || source .envrc
fi
#+END_SRC

* envrc :envrc:

- https://github.com/nix-community/nix-direnv
  - source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/${NixDirEnvVersion}/direnvrc" "sha256-0000000000000000000000000000000000000000000="

** .envrc

#+NAME: envrc
#+HEADER: :tangle ../.envrc
#+BEGIN_SRC shell
if [ -f .envrc-git-init ]; then
  source_env_if_exists .envrc-git-init || source .envrc-git-init
fi
if [ -f .envrc-local ]; then
  source_env_if_exists .envrc-local || source .envrc-local
fi
if [ -f .envrc-nix ]; then
  source_env_if_exists .envrc-nix || source .envrc-nix
fi
PATH_add result/bin
#nix flake update && nix flake check --show-trace && nix flake show
#+END_SRC

** .envrc-nix

- https://github.com/nix-community/nix-direnv
  - source_url
    - direnv fetchurl "https://raw.githubusercontent.com/nix-community/nix-direnv/<<direnv-version>>/direnvrc" "<<direnv-sha>>"
    - ${NixDirEnvVersion}

#+HEADER: :tangle ../.envrc-nix
#+BEGIN_SRC shell
NIX_ENFORCE_PURITY=1
# - https://github.com/nix-community/nix-direnv
NixDirEnvVersion="3.0.6"
NixDirEnvSHA="sha256-RYcUJaRMf8oF5LznDrlCXbkOQrywm0HDv1VjYGaJGdM="
if ! has nix_direnv_version || ! nix_direnv_version ${NixDirEnvVersion}; then
  source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/${NixDirEnvVersion}/direnvrc" "${NixDirEnvSHA}"
fi
watch_file flake.lock
watch_file flake.nix
watch_file shell.nix
watch_file makefile
watch_file nixDevEnv.sh
watch_file .envrc-local
watch_file .envrc-nix
PATH_add result/bin
use flake .
echo "
• consider running:
  ❯❯ nix flake show
  ❯❯ nix flake update && nix flake check && nix flake show

• for a dev shell (development environment):

  ❯❯ nix develop
  ❯❯ nix develop '.#' --print-build-logs -c zsh
  ❯❯ nix develop '.#dsh-latex-pdf' --print-build-logs -c zsh

• to build project:

  ❯❯ nix build '.#' --print-build-logs
  - (see nix other/additional build options):
    ❯❯ nix flake show
"
#+END_SRC

*** 3.0.6

#+NAME: direnv-version
#+BEGIN_SRC shell
3.0.6
#+END_SRC

#+NAME: direnv-sha
#+BEGIN_SRC shell
sha256-RYcUJaRMf8oF5LznDrlCXbkOQrywm0HDv1VjYGaJGdM=
#+END_SRC

*** 3.0.4

#+BEGIN_SRC shell
3.0.4
#+END_SRC

#+BEGIN_SRC shell
sha256-DzlYZ33mWF/Gs8DDeyjr8mnVmQGx7ASYqA5WlxwvBG4=
#+END_SRC

*** 3.0.0

#+BEGIN_SRC shell
3.0.0
#+END_SRC

#+BEGIN_SRC shell
sha256-21TMnI2xWX7HkSTjFFri2UaohXVj854mgvWapWrxRXg=
#+END_SRC

*** 2.4.0

#+BEGIN_SRC shell
2.4.0
#+END_SRC

#+BEGIN_SRC shell
sha256-XQzUAvL6pysIJnRJyR7uVpmUSZfc7LSgWQwq/4mBr1U=
#+END_SRC

#+BEGIN_SRC shell
2.3.0
#+END_SRC

#+BEGIN_SRC shell
sha256-Dmd+j63L84wuzgyjITIfSxSD57Tx7v51DMxVZOsiUD8=
#+END_SRC

*** empty

#+NAME: direnv-sha_
#+BEGIN_SRC shell
sha256-0000000000000000000000000000000000000000000=
#+END_SRC

#+BEGIN_SRC shell
- https://github.com/nix-community/nix-direnv
NixDirEnvSHA="sha256-0000000000000000000000000000000000000000000="
direnv fetchurl https://raw.githubusercontent.com/nix-community/nix-direnv/${NixDirEnvVersion}/direnvrc
#+END_SRC

** .envrc-git-init

#+HEADER: :tangle ../.envrc-git-init
#+HEADER: :noweb yes
#+BEGIN_SRC shell
if [[ ! -d ./.git ]]; then
  git init
  git add .
fi
#+END_SRC

** .envrc-local CHECK MODIFY

- bespoke modify appropriately and generate if needed

#+HEADER: :tangle ../.envrc-local_
#+HEADER: :noweb yes
#+BEGIN_SRC shell
export SisuVER=$(git describe --long --tags | sed 's/^[ a-z_-]\+\([0-9.]\+\)/\1/;s/\([^-]*-g\)/r\1/;s/-/./g')
PATH_add result/bin
#export sisuBIN=result/bin
export sisuPROJ=~/grotto/repo/git.repo/projects/doc-reform/code/software/sisu
export sisuDOC=./data/samples/current
export sisuOUT=/srv/www/sisu
#export sisuOUT=/var/www
#export sisuOUTver=/tmp/sisu/$sisuVER/www
export sisuCGIbin=/var/www/cgi/cgi-bin
export sisuSearchActionLocal='http://localhost/sisu_search'
export sisuSearchActionRemote='https://sisudoc.org/sisu_search'
export sisuCGIform='sisu_search'
export sisuSQLdb='spine.search.db'
export sisuDBpath=/var/www/sqlite
#export sisuDBpath=/srv/www/sisu/sqlite
#+END_SRC