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
|
-*- mode: org -*-
#+TITLE: configuration nix
#+DESCRIPTION: spine-search nix configuration
#+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
* nix :nix:
** flake.nix :flake:
#+HEADER: :tangle ../flake.nix
#+HEADER: :noweb yes
#+BEGIN_SRC nix
{
description = "a sisu like document parser search form";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
inputs.spine-d-overlay = {
url = "<<sisudoc_dlang_nix_overlay_src>>";
inputs.nixpkgs.follows = "nixpkgs";
};
outputs = {
self,
nixpkgs,
spine-d-overlay,
...
}@inputs: let
pname = "spine_search";
version = "<<spine_version>>";
#shell = ./shell.nix;
#devEnv = ./nixDevEnv.sh;
supportedSystems = ["x86_64-linux"];
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
nixpkgsFor = forAllSystems (system: import nixpkgs {inherit system;}); # nixpkgs instantiated for supported system types
localOverlay = (final: prev: {
ldc = prev.callPackage ./nix-overlays/ldc { }; # -> ok <<ldc_version>>
# dmd overlay: revert to GCC14; (current) GCC 15 introduced nullptr in its headers, and DMD's ImportC parser needs update to handle it, monitor and update:
dmd = prev.callPackage ./nix-overlays/dmd { stdenv = prev.gcc14Stdenv; }; # -> ok <<dmd_version>>
dub = prev.callPackage ./nix-overlays/dub { }; # -> ? <<dub_version>>
#gdc = prev.callPackage ./nix-overlays/gdc { };
});
pkgsForSystem = system: import nixpkgs {
overlays = [
localOverlay
];
inherit system;
};
mkSpineSearch = { pkgs, compilerPkg, compilerBin, buildType }: pkgs.stdenv.mkDerivation {
inherit pname version;
meta.mainProgram = "spine_search";
#executable = true; # not used
src = self;
buildInputs = [ pkgs.sqlite ];
nativeBuildInputs = [ pkgs.dub compilerPkg pkgs.gnumake ];
preBuild = ''
export HOME=$TMPDIR
#export HOME=$(pwd)
'';
buildPhase = ''
runHook preBuild
buildCMD="dub run --cache=local --compiler=$(type -P ${compilerBin}) --build=${buildType} --combined --skip-registry=all"
echo $buildCMD
$buildCMD
echo $buildCMD
runHook postBuild
'';
checkPhase = ''
runHook preCheck
dub test --combined --skip-registry=all
runHook postCheck
'';
installPhase = ''
runHook preInstall
mkdir -p $out/cgi-bin
install -m755 -D ./cgi-bin/spine_search $out/cgi-bin/spine_search
runHook postInstall
'';
postInstall = ''
echo `ls -la $out/cgi-bin/spine_search`
'';
};
shellHook = ''
export Date=`date "+%Y%m%d"`
'';
mkDevShell = { pkgs, name, compiler, extraPackages ? [] }: pkgs.mkShell {
inherit name shellHook;
packages = [
pkgs.direnv
pkgs.nix-direnv
compiler
pkgs.dub
pkgs.dtools
pkgs.gnumake
pkgs.sqlite
pkgs.gnugrep
pkgs.gnused
pkgs.ripgrep
] ++ extraPackages;
};
in {
packages = forAllSystems (system: let
pkgs-ovl = pkgsForSystem system;
pkgs-nix = nixpkgsFor.${system};
in {
default = self.packages.${system}.spine-search-nixpkgs-ldc;
spine-search-nixpkgs-dmd = mkSpineSearch {
pkgs = pkgs-nix;
# nixpkgs dmd: revert to GCC14 (same nullptr/ImportC fix as overlay dmd)
compilerPkg = pkgs-nix.dmd.override { stdenv = pkgs-nix.gcc14Stdenv; };
compilerBin = "dmd";
buildType = "dmd";
};
spine-search-nixpkgs-ldc = mkSpineSearch {
pkgs = pkgs-nix;
compilerPkg = pkgs-nix.ldc;
compilerBin = "ldmd2";
buildType = "ldmd2";
};
spine-search-overlay-dmd = mkSpineSearch {
pkgs = pkgs-ovl;
compilerPkg = pkgs-ovl.dmd;
compilerBin = "dmd";
buildType = "dmd";
};
spine-search-overlay-ldc = mkSpineSearch {
pkgs = pkgs-ovl;
compilerPkg = pkgs-ovl.ldc;
compilerBin = "ldmd2";
buildType = "ldmd2";
};
#spine-search-overlay-gdc = mkSpineSearch {
# pkgs = pkgs-ovl;
# compilerPkg = pkgs-ovl.gdc;
# compilerBin = "gdc";
# buildType = "gdc";
#};
});
devShells = forAllSystems (system: let
pkgs-ovl = pkgsForSystem system;
pkgs-nix = nixpkgsFor.${system};
in
with pkgs-nix; {
dsh-d-overlay = spine-d-overlay.devShells.${system}.default;
dsh-overlay = mkShell {
name = "${pname}-${version} dev shell (overlay)";
packages = with pkgs-ovl; [
ldc
#dmd
dub
gnumake
sqlite
];
inherit shellHook;
};
dsh-nixpkgs-dmd = mkShell {
name = "${pname}-${version} dev shell (nixpkgs dmd)";
packages = [
dmd
dub
gnumake
sqlite
];
inherit shellHook;
};
dsh-nixpkgs-ldc = mkShell {
name = "${pname}-${version} dev shell (nixpkgs ldc)";
packages = [
ldc
dub
gnumake
sqlite
];
inherit shellHook;
};
dsh-overlay-dmd = mkShell {
name = "${pname}-${version} dev shell (overlay dmd)";
# "spine-0.18.0 base dev shell, dmd-2.111.0, dub-1.40.0";
packages = with pkgs-ovl; [
dmd
dub
gnumake
sqlite
];
inherit shellHook;
};
dsh-overlay-ldc = mkShell {
name = "${pname}-${version} dev shell (overlay ldc)";
# "spine-0.18.0 base dev shell, ldc-1.42.0, dub-1.40.0";
packages = with pkgs-ovl; [
ldc
dub
gnumake
sqlite
];
inherit shellHook;
};
dsh-sqlite = mkShell {
name = "${pname}-${version} dev shell (sqlite)";
packages = [
ldc
#dmd
dub
gnumake
sqlite
];
inherit shellHook;
};
default = self.devShells.${system}.dsh-nixpkgs-ldc;
#default = import ./shell.nix {pkgs = pkgs-nix;};
});
};
}
#+END_SRC
** shell.nix :shell:
#+HEADER: :tangle ../shell.nix
#+HEADER: :noweb yes
#+BEGIN_SRC nix
#!/usr/bin/env -S nix-shell --pure
#!nix-shell -i bash
# Development environment for sisudoc-spine-search-cgi.
# Builds the spine_search CGI binary via ./package.nix.
#
# Build logic for the spine_search derivation lives in ./package.nix -
# this file only describes the dev shell.
#
# Usage:
# nix-shell # enters shell, builds spine_search
# nix-shell --run 'echo $SPINE_SEARCH_BIN'
{
pkgs ? import <nixpkgs> {},
spine-search ? pkgs.callPackage ./package.nix {},
# 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",
}:
with pkgs;
mkShell {
name = "spine_search base dev shell";
packages = [
# ❯❯❯ spine_search CGI binary built from ./package.nix
spine-search
# ❯❯❯ d_build_related
ldc
#dmd
dub
# ❯❯❯ dev
gnumake
git
# ❯❯❯ nix workflow
direnv
nix-direnv
nix-prefetch-git
nix-output-monitor
nix-tree
jq
# ❯❯❯ sqlite
sqlite
];
shellHook = ''
export Date=$(date "+%Y%m%d")
## set local values in .envrc-local (or here if you must)
## spine_search lives under cgi-bin, not bin - expose it via env
## var and prepend cgi-bin to PATH for convenience.
export SPINE_SEARCH_BIN="${spine-search}/cgi-bin/spine_search"
export PATH="${spine-search}/cgi-bin:$PATH"
echo "spine_search: $SPINE_SEARCH_BIN"
## 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_SEARCH_SHELL_HANDOFF" ] \
&& [ -n "$__spine_user_shell" ] \
&& [ "$(basename "$__spine_user_shell")" != "bash" ] \
&& [[ $- == *i* ]]; then
export __SPINE_SEARCH_SHELL_HANDOFF=1
exec "$__spine_user_shell"
fi
unset __spine_user_shell
'';
}
#+END_SRC
#+BEGIN_SRC nix
{pkgs-nix ? import <nixpkgs> {}}:
with pkgs-nix;
mkShell {
buildInputs = [
# ❯❯❯ nix_related
#nix
direnv
nix-direnv
nixVersions.latest #nixVersions.latest #nixVersions.git
nix-prefetch-git
validatePkgConfig
nix-output-monitor
nix-tree
jq #gx
#nixfmt-rfc-style
git
# ❯❯❯ dev
gnumake
ps
# ❯❯❯ d_build_related
# ❯❯ package manager
#dub
# ❯❯ compiler
#dmd
#ldc
#rund
# ❯❯ linker
#lld
#mold
# ❯❯ builder
#ninja
#meson
# ❯❯❯ sqlite search related
sqlite
# ❯❯❯ tools
#aria #wget #curl
];
shellHook = ''
'';
}
#+END_SRC
echo "ldc `${pkgs.ldc}/bin/ldc2 -v`"
** package.nix :default:
#+HEADER: :tangle ../package.nix
#+HEADER: :tangle-mode (identity #o644)
#+HEADER: :noweb yes
#+BEGIN_SRC nix
# package.nix - spine_search CGI derivation (build logic)
#
# Standalone, callPackage-style derivation for the spine_search CGI
# binary. Used by shell.nix to put a freshly-built spine_search into
# the dev shell. May also be consumed via:
# nix-build ./package.nix
# pkgs.callPackage ./package.nix {}
#
# Compiler defaults to ldc/ldmd2 (matching the flake's default
# package `spine-search-nixpkgs-ldc`). Override to build with dmd:
# pkgs.callPackage ./package.nix {
# compilerPkg = pkgs.dmd;
# compilerBin = "dmd";
# buildType = "dmd";
# }
#
# Note: spine_search is a CGI binary and is installed to
# $out/cgi-bin/spine_search (not $out/bin/), since it is intended to
# be served by a web server, not invoked directly from PATH.
{
lib,
stdenv,
dub,
ldc,
gnumake,
sqlite,
compilerPkg ? ldc,
compilerBin ? "ldmd2",
buildType ? "ldmd2",
}:
stdenv.mkDerivation {
pname = "spine_search";
version = "0.18.0";
src = lib.cleanSource ./.;
buildInputs = [ sqlite ];
nativeBuildInputs = [ dub compilerPkg gnumake ];
preBuild = ''
export HOME=$(pwd)
'';
buildPhase = ''
runHook preBuild
buildCMD="dub run --cache=local \
--compiler=$(type -P ${compilerBin}) \
--build=${buildType} \
--combined --skip-registry=all"
echo $buildCMD
$buildCMD
runHook postBuild
'';
checkPhase = ''
runHook preCheck
dub test --combined --skip-registry=all
runHook postCheck
'';
installPhase = ''
runHook preInstall
mkdir -p $out/cgi-bin
install -m755 -D ./cgi-bin/spine_search $out/cgi-bin/spine_search
runHook postInstall
'';
postInstall = ''
echo `ls -la $out/cgi-bin/spine_search`
'';
meta = {
description = "CGI search interface for spine document collections";
homepage = "https://sisudoc.org";
license = lib.licenses.agpl3Plus;
platforms = lib.platforms.linux;
mainProgram = "spine_search";
};
}
#+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 <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
disallowedRefs = [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 = attrs.pname or package.name;
nativeBuildInputs = [dcompiler dub pkgs.removeReferencesTo] ++ nativeBuildInputs;
disallowedReferences = disallowedRefs;
passthru =
passthru
// {
inherit dub dcompiler pkgs;
};
src = lib.cleanSourceWith {
filter = filterDub;
src = lib.cleanSource src;
};
preFixup = ''
find $out/cgi-bin -type f -exec ${removeExpr disallowedRefs} '{}' + || 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
echo "Error: could not find D compiler" >&2
exit 1
fi
echo "$DC_ used as D compiler to build $pname"
dub run --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/cgi-bin
install -m755 -D "${targetOf package}" "$out/cgi-bin/spine_search"
runHook postInstall
'';
postInstall = ''
echo `ls -la $out/cgi-bin/spine_search`
'';
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-search";
version = "<<spine_version>>";
src = ./.;
buildInputs = [
pkgs.sqlite
(
with pkgs; [
nixVersions.latest #nixVersions.latest #nixVersions.git
## package manager
dub
## compiler
ldc
#rund
sqlite
]
)
];
meta = with pkgs.lib; {
homepage = "https://sisudoc.org";
description = "cgi sqlite search form for document object search";
longDescription = ''
a sisu like parser & document generator
'';
license = licenses.agpl3Plus;
platforms = platforms.linux;
maintainers = ["RalphAmissah"];
mainProgram = "spine_search";
};
}
#+END_SRC
- unused
- installPhase
#+BEGIN_SRC text
installPhase = ''
mkdir -p $out/bin
cp spine $out/bin
chmod +x $out/bin/spine
'';
#+END_SRC
** variables used SET
*** 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
*** nixpkgs path / url
- nixpkgs_url_github
- nixpkgs_url_local
**** github (official)
#+NAME: nixpkgs_url_github
#+BEGIN_SRC shell
github:NixOS/nixpkgs/nixpkgs-unstable
#+END_SRC
**** localhost
#+NAME: nixpkgs_url_local
#+BEGIN_SRC shell
/srv/nix/nixpkgs
#+END_SRC
*** nixpkgs path options
- <nixpkgs>
#+NAME: nixpkgs_url
#+HEADER: :noweb yes
#+BEGIN_SRC org
<<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
* 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
** dlang overlays
*** ldc
#+NAME: ldc_version
#+HEADER: :noweb yes
#+BEGIN_SRC emacs-lisp
<<./nix-develop-dlang-shared.org:ldc-version()>>
#+END_SRC
*** dmd
#+NAME: dmd_version
#+HEADER: :noweb yes
#+BEGIN_SRC emacs-lisp
<<./nix-develop-dlang-shared.org:dmd-version()>>
#+END_SRC
*** dub
#+NAME: dub_version
#+HEADER: :noweb yes
#+BEGIN_SRC emacs-lisp
<<./nix-develop-dlang-shared.org:dub-version()>>
#+END_SRC
*** dtools
#+NAME: dtools_version
#+HEADER: :noweb yes
#+BEGIN_SRC emacs-lisp
<<./nix-develop-dlang-shared.org:dtools-version()>>
#+END_SRC
** sha256 blank hash
#+NAME: sha256-blank
#+BEGIN_SRC nix
<<./nix-develop-dlang-shared.org:sha256-blank()>>
#+END_SRC
#+NAME: blank_hash
#+BEGIN_SRC nix
<<./nix-develop-dlang-shared.org:sha256-blank()>>
#+END_SRC
|