diff options
| author | Ralph Amissah <ralph.amissah@gmail.com> | 2026-04-10 21:30:13 -0400 |
|---|---|---|
| committer | Ralph Amissah <ralph.amissah@gmail.com> | 2026-04-10 21:30:13 -0400 |
| commit | 9dd16085ce740af9244e00839da364ecd4f722b8 (patch) | |
| tree | c1dcbdcccdb93f74a8d74a30d2749f82c6db41f5 | |
| parent | flake.nix dmd build fix overlay: revert to GCC14 (diff) | |
nix keeping: nix-shell, nix-build derivation.nix
| -rwxr-xr-x | default.nix | 3 | ||||
| -rwxr-xr-x[-rw-r--r--] | derivation.nix | 30 | ||||
| -rw-r--r-- | devenv.nix | 47 | ||||
| -rw-r--r-- | flake.lock | 6 | ||||
| -rw-r--r-- | flake.nix | 3 | ||||
| -rw-r--r-- | org/config_nix.org | 229 | ||||
| -rw-r--r-- | package.nix | 68 | ||||
| -rwxr-xr-x | shell.nix | 61 |
8 files changed, 281 insertions, 166 deletions
diff --git a/default.nix b/default.nix deleted file mode 100755 index 922b291..0000000 --- a/default.nix +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env -S nix-build -{pkgs ? import <nixpkgs> {}}: -pkgs.callPackage ./devenv.nix {} diff --git a/derivation.nix b/derivation.nix index a27956f..95797b4 100644..100755 --- a/derivation.nix +++ b/derivation.nix @@ -1,3 +1,4 @@ +#!/usr/bin/env -S nix-build derivation.nix { pkgs ? import <nixpkgs> {}, stdenv ? pkgs.stdenv, @@ -17,7 +18,7 @@ with ( ); targetOf = package: "${package.targetPath or "."}/${package.targetName or package.name}"; # remove reference to build tools and library sources - disallowedReferences = deps: [dcompiler dub]; + disallowedRefs = [dcompiler dub]; removeExpr = refs: ''remove-references-to ${lib.concatMapStrings (ref: " -t ${ref}") refs}''; in { mkDubDerivation = lib.makeOverridable ({ @@ -30,9 +31,9 @@ with ( } @ attrs: stdenv.mkDerivation (attrs // { - pname = package.name; + pname = attrs.pname or package.name; nativeBuildInputs = [dcompiler dub pkgs.removeReferencesTo] ++ nativeBuildInputs; - disallowedReferences = disallowedReferences deps; + disallowedReferences = disallowedRefs; passthru = passthru // { @@ -43,7 +44,7 @@ with ( src = lib.cleanSource src; }; preFixup = '' - find $out/cgi-bin -type f -exec ${removeExpr (disallowedReferences deps)} '{}' + || true + find $out/cgi-bin -type f -exec ${removeExpr disallowedRefs} '{}' + || true ''; buildPhase = '' runHook preBuild @@ -57,7 +58,8 @@ with ( fi done if [ "$DC" == "" ]; then - exit "Error: could not find D compiler" + 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 @@ -72,12 +74,10 @@ with ( installPhase = '' runHook preInstall mkdir -p $out/cgi-bin - cp -r "${targetOf package}" $out/cgi-bin - install -m755 -D $out/cgi-bin/spine_search spine_search + install -m755 -D "${targetOf package}" "$out/cgi-bin/spine_search" runHook postInstall ''; postInstall = '' - echo "HERE ${targetOf package} $out/cgi-bin" echo `ls -la $out/cgi-bin/spine_search` ''; meta = @@ -92,34 +92,32 @@ with ( } ); mkDubDerivation rec { - name = "spine-search-0.18.0"; - #name = "spine-search-${version}"; + pname = "spine-search"; + version = "0.18.0"; src = ./.; buildInputs = [ pkgs.sqlite ( - with pkgs-nix; [ + with pkgs; [ nixVersions.latest #nixVersions.latest #nixVersions.git ## package manager dub ## compiler ldc - rund + #rund sqlite ] ) ]; - meta = with pkgs-nix.lib; { - pname = "spine-search"; - version = "0.18.0"; + meta = with pkgs.lib; { homepage = "https://sisudoc.org"; description = "cgi sqlite search form for document object search"; longDescription = '' a sisu like parser & document generator ''; - homepage = "https://sisudoc.org"; license = licenses.agpl3Plus; platforms = platforms.linux; maintainers = ["RalphAmissah"]; + mainProgram = "spine_search"; }; } diff --git a/devenv.nix b/devenv.nix deleted file mode 100644 index 56e6613..0000000 --- a/devenv.nix +++ /dev/null @@ -1,47 +0,0 @@ -{ - 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 - 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 - # ❯❯❯ 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; - }) - ]; - } @@ -2,11 +2,11 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1775701739, - "narHash": "sha256-2FWWY1rr/+pGUJK1npcVcsWNEblzmKs6VxD3VEvwJSs=", + "lastModified": 1775793324, + "narHash": "sha256-omax7atcZbol+6HJ2RLpP+ZCFcPa5bZ65Hn71RufeWQ=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "0f7663154ff2fec150f9dbf5f81ec2785dc1e0db", + "rev": "9d29d5f667d7467f98efc31881e824fa586c927e", "type": "github" }, "original": { @@ -181,7 +181,8 @@ ]; inherit shellHook; }; - default = import ./shell.nix {inherit pkgs-nix;}; + default = self.devShells.${system}.dsh-nixpkgs-ldc; + #default = import ./shell.nix {pkgs = pkgs-nix;}; }); }; } diff --git a/org/config_nix.org b/org/config_nix.org index 2044cfa..5846fcc 100644 --- a/org/config_nix.org +++ b/org/config_nix.org @@ -204,7 +204,8 @@ ]; inherit shellHook; }; - default = import ./shell.nix {inherit pkgs-nix;}; + default = self.devShells.${system}.dsh-nixpkgs-ldc; + #default = import ./shell.nix {pkgs = pkgs-nix;}; }); }; } @@ -215,22 +216,69 @@ #+HEADER: :tangle ../shell.nix #+HEADER: :noweb yes #+BEGIN_SRC nix -{pkgs-nix ? import <nixpkgs> {}}: -with pkgs-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 { - buildInputs = [ - # nix workflow + 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 - git - # project build - gnumake + # ❯❯❯ 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 @@ -279,81 +327,87 @@ with pkgs-nix; echo "ldc `${pkgs.ldc}/bin/ldc2 -v`" -** 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 +** package.nix :default: -#+HEADER: :tangle-mode (identity #o755) -#+HEADER: :shebang "#!/usr/bin/env -S nix-build" -#+BEGIN_SRC nix -{ pkgs ? import <nixpkgs> {} }: -pkgs.callPackage ./derivation.nix {} -#+END_SRC - -*** devenv.nix :default:devenv: - -#+HEADER: :tangle ../devenv.nix +#+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. { - pkgs ? import <nixpkgs> {}, - name ? "user-env", + lib, + stdenv, + dub, + ldc, + gnumake, + sqlite, + compilerPkg ? ldc, + compilerBin ? "ldmd2", + buildType ? "ldmd2", }: -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 - 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 - # ❯❯❯ 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; - }) - ]; - } +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 #o644) +#+HEADER: :tangle-mode (identity #o755) +#+HEADER: :shebang "#!/usr/bin/env -S nix-build derivation.nix" #+HEADER: :noweb yes #+BEGIN_SRC nix { @@ -375,7 +429,7 @@ with ( ); targetOf = package: "${package.targetPath or "."}/${package.targetName or package.name}"; # remove reference to build tools and library sources - disallowedReferences = deps: [dcompiler dub]; + disallowedRefs = [dcompiler dub]; removeExpr = refs: ''remove-references-to ${lib.concatMapStrings (ref: " -t ${ref}") refs}''; in { mkDubDerivation = lib.makeOverridable ({ @@ -388,9 +442,9 @@ with ( } @ attrs: stdenv.mkDerivation (attrs // { - pname = package.name; + pname = attrs.pname or package.name; nativeBuildInputs = [dcompiler dub pkgs.removeReferencesTo] ++ nativeBuildInputs; - disallowedReferences = disallowedReferences deps; + disallowedReferences = disallowedRefs; passthru = passthru // { @@ -401,7 +455,7 @@ with ( src = lib.cleanSource src; }; preFixup = '' - find $out/cgi-bin -type f -exec ${removeExpr (disallowedReferences deps)} '{}' + || true + find $out/cgi-bin -type f -exec ${removeExpr disallowedRefs} '{}' + || true ''; buildPhase = '' runHook preBuild @@ -415,7 +469,8 @@ with ( fi done if [ "$DC" == "" ]; then - exit "Error: could not find D compiler" + 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 @@ -430,12 +485,10 @@ with ( installPhase = '' runHook preInstall mkdir -p $out/cgi-bin - cp -r "${targetOf package}" $out/cgi-bin - install -m755 -D $out/cgi-bin/spine_search spine_search + install -m755 -D "${targetOf package}" "$out/cgi-bin/spine_search" runHook postInstall ''; postInstall = '' - echo "HERE ${targetOf package} $out/cgi-bin" echo `ls -la $out/cgi-bin/spine_search` ''; meta = @@ -450,35 +503,33 @@ with ( } ); mkDubDerivation rec { - name = "spine-search-<<spine_version>>"; - #name = "spine-search-${version}"; + pname = "spine-search"; + version = "<<spine_version>>"; src = ./.; buildInputs = [ pkgs.sqlite ( - with pkgs-nix; [ + with pkgs; [ nixVersions.latest #nixVersions.latest #nixVersions.git ## package manager dub ## compiler ldc - rund + #rund sqlite ] ) ]; - meta = with pkgs-nix.lib; { - pname = "spine-search"; - version = "<<spine_version>>"; + meta = with pkgs.lib; { homepage = "https://sisudoc.org"; description = "cgi sqlite search form for document object search"; longDescription = '' a sisu like parser & document generator ''; - homepage = "https://sisudoc.org"; license = licenses.agpl3Plus; platforms = platforms.linux; maintainers = ["RalphAmissah"]; + mainProgram = "spine_search"; }; } #+END_SRC diff --git a/package.nix b/package.nix new file mode 100644 index 0000000..335d911 --- /dev/null +++ b/package.nix @@ -0,0 +1,68 @@ +# 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"; + }; +} @@ -1,17 +1,64 @@ -{pkgs-nix ? import <nixpkgs> {}}: -with pkgs-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 { - buildInputs = [ - # nix workflow + 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 - git - # project build - gnumake + # ❯❯❯ 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 + ''; } |
