aboutsummaryrefslogtreecommitdiffhomepage
path: root/org/config_nix.org
blob: 2ef18e5acd48004aa19813aeb8e3fc159fee068e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
-*- 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

* nix :nix:
** flake.nix :flake:

#+HEADER: :tangle ../flake.nix
#+HEADER: :noweb yes
#+BEGIN_SRC nix
{
  description = "a sisu like parser & document generator";
  inputs.nixpkgs.url = "<<nixpkgs_url>>";
  inputs.flake-utils.url = "github:numtide/flake-utils";
  outputs = {
    self,
    nixpkgs,
    flake-utils,
  } @ inputs: let
    pname = "spine";
    version = "<<spine_version_set>>";
    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
    checkPhase = ''
      runHook preCheck
      dub test --combined --skip-registry=all
      runHook postCheck
    '';
    localOverlay = (final: prev: {
      ldc = prev.callPackage ./nix-overlays/ldc {  };
      dmd = prev.callPackage ./nix-overlays/dmd {  };
      dub = prev.callPackage ./nix-overlays/dub {  };       # -> ?
      #gdc = prev.callPackage ./nix-overlays/gdc {  };      # empty
    });
    pkgsForSystem = system: import nixpkgs {
      overlays = [
        localOverlay
      ];
      inherit system;
    };
    installPhase = ''
      runHook preInstall
      mkdir -p $out/bin
      install -m755 ./bin/spine $out/bin/spine
      runHook postInstall
    '';
    postInstall = ''
      echo `ls -la $out/bin/spine`
      $out/bin/spine -v
    '';
  in {
    packages = forAllSystems (system: let
      pkgs-ovl = pkgsForSystem system;
      pkgs = nixpkgsFor.${system};
    in
      with pkgs-ovl; {
        default = stdenv.mkDerivation {
          inherit pname;
          inherit version;
          meta.mainProgram = "spine";
          executable = true;
          src = self;
          inherit shell;
          inherit devEnv;
          buildInputs = [sqlite];
          nativeBuildInputs = [dub ldc gnumake]; # [ dub dmd ]; [ dub ldc ]; [ dub gdc ];
          preBuild = ''
            export HOME=$(pwd)
          '';
          buildPhase = ''
            runHook preBuild
            for DC_ in dmd ldmd2 ldc2 gdc 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 --cache=local --compiler=$DC --build=$DC_ --combined --skip-registry=all
            runHook postBuild
          '';
          inherit checkPhase;
          inherit installPhase;
          inherit postInstall;
        };
        spine-overlay-dmd = stdenv.mkDerivation {
          inherit pname;
          inherit version;
          meta.mainProgram = "spine-dmd";
          executable = true;
          src = self;
          inherit shell;
          inherit devEnv;
          buildInputs = [sqlite];
          nativeBuildInputs = [dub dmd gnumake];
          preBuild = ''
            export HOME=$(pwd)
          '';
          buildPhase = ''
            runHook preBuild
            dub build --cache=local --compiler=$(type -P dmd) --build=dmd --combined --skip-registry=all
            runHook postBuild
          '';
          inherit checkPhase;
          inherit installPhase;
          inherit postInstall;
        };
        spine-overlay-ldc = stdenv.mkDerivation {
          inherit pname;
          inherit version;
          meta.mainProgram = "spine-ldc";
          executable = true;
          src = self;
          inherit shell;
          inherit devEnv;
          buildInputs = [sqlite];
          nativeBuildInputs = [dub ldc gnumake];
          preBuild = ''
            export HOME=$(pwd)
          '';
          buildPhase = ''
            runHook preBuild
            dub build --cache=local --compiler=$(type -P ldc2) --build=ldc2 --combined --skip-registry=all
            runHook postBuild
          '';
          inherit checkPhase;
          inherit installPhase;
          inherit postInstall;
        };
        spine-nixpkgs-ldc = stdenv.mkDerivation {
          inherit pname;
          inherit version;
          meta.mainProgram = "spine-ldc";
          executable = true;
          src = self;
          inherit shell;
          inherit devEnv;
          buildInputs = with pkgs; [sqlite];
          nativeBuildInputs = with pkgs; [dub ldc gnumake];
          preBuild = ''
            export HOME=$(pwd)
          '';
          buildPhase = ''
            runHook preBuild
            dub build --cache=local --compiler=$(type -P ldc2) --build=ldc2 --combined --skip-registry=all
            runHook postBuild
          '';
          inherit checkPhase;
          inherit installPhase;
          inherit postInstall;
        };
        #spine-overlay-gdc = stdenv.mkDerivation {
        #  inherit pname;
        #  inherit version;
        #  meta.mainProgram = "spine-gdc";
        #  executable = true;
        #  src = self;
        #  inherit shell;
        #  inherit devEnv;
        #  buildInputs = [ sqlite ];
        #  nativeBuildInputs = [ dub gdc gnumake ];
        #  buildPhase = ''
        #    runHook preBuild
        #    dub build --cache=local --compiler=$(type -P gdc) --build=gdc --combined --skip-registry=all
        #    runHook postBuild
        #  '';
        #  inherit checkPhase;
        #  inherit installPhase;
        #  inherit postInstall;
        #};
        #vendorSha256 = "sha256-0Q00000000000000000000000000000000000000000=";
      });
    apps = forAllSystems (system: {
      default = {
        type = "app";
        program = "${self.packages.${system}.default}/bin/spine";
      };
    });
    devShells = forAllSystems (system: let
      pkgs-ovl = pkgsForSystem system;
      pkgs = nixpkgsFor.${system};
      shellHook = ''
        export DFLAGS="-O2 -boundscheck=on"
        export Date=`date "+%Y%m%d"`
      '';
    in
      with pkgs-ovl; {
        dsh-overlay = 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-overlay-dmd-dub = mkShell {
          name = "spine base dev shell";
          inherit shell;
          inherit devEnv;
          #buildInputs = [ sqlite ];
          #nativeBuildInputs = [ dub dmd ldc gdc gnumake ];
          packages = [
            dmd
            dub
            gnumake
            sqlite
          ];
          inherit shellHook;
        };
        dsh-overlay-ldc-dub = mkShell {
          name = "spine base dev shell";
          inherit shell;
          inherit devEnv;
          #buildInputs = [ sqlite ];
          #nativeBuildInputs = [ dub dmd ldc gdc gnumake ];
          packages = [
            ldc
            dub
            gnumake
            sqlite
          ];
          inherit shellHook;
        };
        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
            perl534Packages.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 <nixpkgs> {}}:
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
      # perl534Packages.Po4a
    ];
    shellHook = ''
    '';
  }
#+END_SRC

** default.nix :default:

#+HEADER: :tangle ../default.nix
#+HEADER: :tangle-mode (identity #o755)
#+HEADER: :shebang "#!/usr/bin/env -S nix-build"
#+BEGIN_SRC nix
{pkgs ? import <nixpkgs> {}}:
pkgs.callPackage ./devenv.nix {}
#+END_SRC

** devenv.nix :default:devenv:

#+HEADER: :tangle ../devenv.nix
#+HEADER: :tangle-mode (identity #o644)
#+BEGIN_SRC nix
{
  pkgs ? import <nixpkgs> {},
  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 <path-to-flake> || 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 <nixpkgs> {},
  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
              runHook postInstall
            '';
            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 = "<<spine_version_set>>";
    src = ./.;
    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

- unused
  - installPhase

#+BEGIN_SRC txt
installPhase = ''
  mkdir -p $out/bin
  cp spine $out/bin
  chmod +x $out/bin/spine
'';
#+END_SRC

** variables used SET
*** spine version SET VERSION :version:set:project:

#+NAME: spine_version_set
#+BEGIN_SRC sh
0.12.0
#+END_SRC

*** nixpkgs path / url

- nixpkgs_url_github
- nixpkgs_url_local

**** github (official)

#+NAME: nixpkgs_url_github
#+BEGIN_SRC sh
github:NixOS/nixpkgs/nixpkgs-unstable
#+END_SRC

**** localhost

#+NAME: nixpkgs_url_local
#+BEGIN_SRC sh
/srv/nix/nixpkgs
#+END_SRC

*** nixpkgs path options

- <nixpkgs>

#+NAME: nixpkgs_url
#+HEADER: :noweb yes
#+BEGIN_SRC sh
<<nixpkgs_url_github>>
#+END_SRC

#+NAME: nixpkgs_url_github
#+BEGIN_SRC nix
github:nixos/nixpkgs
#+END_SRC

#+NAME: nixpkgs_path_local
#+BEGIN_SRC nix
/srv/nix/nixpkgs
#+END_SRC

* misc (remove?)
** dub.selections.json

#+HEADER: :NO-tangle ../dub.selections.json
#+BEGIN_SRC nix
{
	"fileVersion": 1,
	"versions": {
		"d2sqlite3": "0.19.1",
		"dyaml": "0.8.3",
		"imageformats": "7.0.2",
		"tinyendian": "0.2.0"
	}
}
#+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 '<nixpkgs>' -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 "  <nixpkgs> == `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="<<spine_search_db>>" --sqlite-db-path="$SpineDBpath"
$SpineBIN/spine -v --sqlite-db-recreate --sqlite-db-filename="<<spine_search_db>>" --sqlite-db-path="$SpineDBpath"
,#+END_SRC

,*** populate sqlite db

,#+BEGIN_SRC sh
$SpineBIN/spine -v --sqlite-update --sqlite-db-filename="<<spine_search_db>>" --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="<<spine_search_db>>" --cgi-sqlite-search-filename="<<spine_search_cgi>>" --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:           "<<spine_search_cgi>>"
  cgi_action:                  "https://sisudoc.org/spine_search"
  db_sqlite_filename:          "<<spine_search_db>>"
  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

*** db search related variables

#+NAME: spine_search_db
#+BEGIN_SRC sh
spine.search.db
#+END_SRC

#+NAME: spine_search_cgi
#+BEGIN_SRC sh
spine_search
#+END_SRC

** makefile

#+HEADER: :tangle ../makefile_
#+BEGIN_SRC make
buildPhase:
	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; \
  echo "D compiler = $${DC}"; \
	if [ "$${DC}" == "" ]; then \
    echo "Error: could not find D compiler"; \
	  exit 1; \
	fi; \
	echo "$${DC_} used as D compiler to build $${pname}"; \
	export DFLAGS="-O2 -inline"; \
	dub build --compiler=$${DC} --build=release --combined --skip-registry=all;
checkPhase:
	runHook preCheck; \
	HOME=$${PWD}; \
	dub test --combined --skip-registry=all; \
	runHook postCheck
installPhase:
	runHook preInstall; \
	mkdir -p $${out}/bin; \
	install -m755 ./bin/spine $${out}/bin/spine; \
	runHook postInstall
	#cp -r bin/spine $out/bin/.
postInstall:
	echo "$${out}/share/cgi-bin"; \
	echo `ls -la $${out}/bin/spine`
#+END_SRC

** empty sha56 hash

#+NAME: blank_hash
#+BEGIN_SRC nix
sha256-0000000000000000000000000000000000000000000=
#+END_SRC

#+NAME: assumed_hash
#+BEGIN_SRC nix
sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
#+END_SRC