From 11a4034556f8611820025beee07672579b672389 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Tue, 24 Jan 2023 12:38:39 -0500 Subject: nix & build housekeeping, alternative D compilers --- .envrc | 24 +++++++++ .envrc-local_ | 5 -- devenv.nix | 4 +- flake.lock | 6 +-- flake.nix | 150 ++++++++++++++++++++++++++++++++++++++++++++++++++--- org/config_nix.org | 117 +++++++++++++++++++++++++++++++++++------ shell.nix | 2 +- 7 files changed, 274 insertions(+), 34 deletions(-) diff --git a/.envrc b/.envrc index eb13c32..954d4cd 100644 --- a/.envrc +++ b/.envrc @@ -1,4 +1,5 @@ use flake . +#use flake .#default NIX_ENFORCE_PURITY=1 NixDirEnvVersion="2.2.0" if ! has nix_direnv_version || ! nix_direnv_version ${NixDirEnvVersion}; then @@ -6,6 +7,29 @@ if ! has nix_direnv_version || ! nix_direnv_version ${NixDirEnvVersion}; then # source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/${NixDirEnvVersion}/direnvrc" "sha256-0000000000000000000000000000000000000000000=" source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/${NixDirEnvVersion}/direnvrc" "sha256-5EwyKnkJNQeXrRkYbwwRBcXbibosCJqyIUuz9Xq+LRc=" fi +# reload when these files change +watch_file flake.lock +watch_file flake.nix +nix flake update && nix flake check --show-trace && nix flake show if [ -f .envrc-local ]; then source_env_if_exists .envrc-local || source .envrc-local fi +echo " + +- nix flake update && nix flake check --show-trace && nix flake show && nix develop .#devShell + +- nix build .#default --print-build-logs +- nix build .#spine-search-ldc --print-build-logs +- nix build .#spine-search-dmd --print-build-logs +- nix build .#spine-search-gdc --print-build-logs + +nix-shell '' -A nix --pure + +nix run .#default --print-build-logs + +nix develop --build .#default --print-build-logs + +nix shell .#default --print-build-logs --command spine -v +nix shell .#default --print-build-logs --command spine --very-verbose --epub --html --html-link-search --html-link-curate --curate --output=\"\$SpineOUT\" ./markup/pod +nix shell .#default --print-build-logs --command spine --very-verbose --html --html-link-search --html-link-curate --curate --sqlite-update --sqlite-db-filename=\"spine.search.db\" --cgi-sqlite-search-filename=\"spine_search\" --sqlite-db-path=\"\$SpineDBpath\" --output=\"\$SpineOUT\" ./markup/pod +" diff --git a/.envrc-local_ b/.envrc-local_ index 4e230a6..7fc8556 100644 --- a/.envrc-local_ +++ b/.envrc-local_ @@ -1,8 +1,3 @@ -# reload when these files change -watch_file flake.lock -watch_file flake.nix -nix flake update; nix flake check; nix flake show -#use flake .#default export NIX_PATH=/nix/var/nix/profiles/per-user/root/channels/nixos #export NIX_PATH=nixpkgs=/srv/nix/nixpkgs export DFLAGS="-O2 -inline -boundscheck=on -color=on" diff --git a/devenv.nix b/devenv.nix index 8098ba7..98a02b5 100755 --- a/devenv.nix +++ b/devenv.nix @@ -1,7 +1,7 @@ -{ pkgs ? import { }, name ? "user-env" }: with pkgs; +{ pkgs ? import { }, name ? "user-env" }: with pkgs; buildEnv { inherit name; - extraOutputsToInstall = [ "out" "man" "lib" ]; # to get all needed symlinks + extraOutputsToInstall = [ "out" "man" "lib" ]; # to get all needed symlinks paths = [ #nix # if not on NixOS, this is needed direnv diff --git a/flake.lock b/flake.lock index 5154297..fcd9096 100644 --- a/flake.lock +++ b/flake.lock @@ -17,11 +17,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1672428209, - "narHash": "sha256-eejhqkDz2cb2vc5VeaWphJz8UXNuoNoM8/Op8eWv2tQ=", + "lastModified": 1674487464, + "narHash": "sha256-Jgq50e4S4JVCYpWLqrabBzDp/1mfaxHCh8/OOorHTy0=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "293a28df6d7ff3dec1e61e37cc4ee6e6c0fb0847", + "rev": "3954218cf613eba8e0dcefa9abe337d26bc48fd0", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 36050e1..b8a023e 100644 --- a/flake.nix +++ b/flake.nix @@ -4,8 +4,9 @@ inputs.flake-utils.url = "github:numtide/flake-utils"; outputs = { self, nixpkgs, flake-utils }: let + pname = "spine_search"; version = "0.12.0"; - supportedSystems = [ "x86_64-linux" ]; # [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ]; + 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. in { @@ -13,17 +14,16 @@ let pkgs = nixpkgsFor.${system}; in with pkgs; { default = stdenv.mkDerivation { - pname = "spine_search"; + inherit pname; inherit version; executable = true; src = self; shell = ./default.nix; devEnv = ./devenv.nix; buildInputs = [ sqlite ]; - nativeBuildInputs = [ dub ldc ]; # [ dub dmd ]; [ dub ldc ]; [ dub gdc ]; + nativeBuildInputs = [ dub dmd ldc gdc gnumake ]; # [ dub dmd ]; [ dub ldc ]; [ dub gdc ]; buildPhase = '' runHook preBuild - HOME="$PWD" for DC_ in dmd ldmd2 ldc2 gdc gdmd; do echo "- check for D compiler $DC_" DC=$(type -P $DC_ || echo "") @@ -36,7 +36,144 @@ ''; checkPhase = '' runHook preCheck - HOME="$PWD" + dub test --combined --skip-registry=all + runHook postCheck + ''; + installPhase = '' + runHook preInstall + mkdir -p $out/share/cgi-bin + install -m755 -D ./cgi-bin/spine_search $out/share/cgi-bin/spine_search + runHook postInstall + ''; + postInstall = '' + echo `ls -la $out/share/cgi-bin/spine_search` + echo " + nix build or nix develop? (suggestions): + - nix build + nix build .#default --print-build-logs + nix flake update; nix build .#default --print-build-logs + nix build --print-build-logs + - nix run + nix run .#default --print-build-logs + nix run default.nix --print-build-logs + - nix shell + nix shell .#default --print-build-logs --command spine -v + - nix develop + nix develop --profile .#default --print-build-logs --command spine -v + nix develop ; eval \"$buildPhase\" + nix develop --build -f derivation.nix -I .envrc --print-build-logs + - nix profile install . --print-build-logs + nix-instantiate | nix show-derivation | jq + " + ''; + }; + spine-search-dmd = stdenv.mkDerivation { + inherit pname; + inherit version; + meta.mainProgram = "spine_search-dmd"; + executable = true; + src = self; + buildInputs = [ sqlite ]; + nativeBuildInputs = [ dub dmd gnumake ]; + buildPhase = '' + runHook preBuild + dub build --compiler=$(type -P dmd) --build=dmd --combined --skip-registry=all + runHook postBuild + ''; + checkPhase = '' + runHook preCheck + dub test --combined --skip-registry=all + runHook postCheck + ''; + installPhase = '' + runHook preInstall + mkdir -p $out/share/cgi-bin + install -m755 -D ./cgi-bin/spine_search $out/share/cgi-bin/spine_search + runHook postInstall + ''; + postInstall = '' + echo `ls -la $out/share/cgi-bin/spine_search` + echo " + nix build or nix develop? (suggestions): + - nix build + nix build .#default --print-build-logs + nix flake update; nix build .#default --print-build-logs + nix build --print-build-logs + - nix run + nix run .#default --print-build-logs + nix run default.nix --print-build-logs + - nix shell + nix shell .#default --print-build-logs --command spine -v + - nix develop + nix develop --profile .#default --print-build-logs --command spine -v + nix develop ; eval \"$buildPhase\" + nix develop --build -f derivation.nix -I .envrc --print-build-logs + - nix profile install . --print-build-logs + nix-instantiate | nix show-derivation | jq + " + ''; + }; + spine-search-ldc = stdenv.mkDerivation { + inherit pname; + inherit version; + meta.mainProgram = "spine_search-ldc"; + executable = true; + src = self; + buildInputs = [ sqlite ]; + nativeBuildInputs = [ dub ldc gnumake ]; + buildPhase = '' + runHook preBuild + dub build --compiler=$(type -P ldc2) --build=ldc2 --combined --skip-registry=all + runHook postBuild + ''; + checkPhase = '' + runHook preCheck + dub test --combined --skip-registry=all + runHook postCheck + ''; + installPhase = '' + runHook preInstall + mkdir -p $out/share/cgi-bin + install -m755 -D ./cgi-bin/spine_search $out/share/cgi-bin/spine_search + runHook postInstall + ''; + postInstall = '' + echo `ls -la $out/share/cgi-bin/spine_search` + echo " + nix build or nix develop? (suggestions): + - nix build + nix build .#default --print-build-logs + nix flake update; nix build .#default --print-build-logs + nix build --print-build-logs + - nix run + nix run .#default --print-build-logs + nix run default.nix --print-build-logs + - nix shell + nix shell .#default --print-build-logs --command spine -v + - nix develop + nix develop --profile .#default --print-build-logs --command spine -v + nix develop ; eval \"$buildPhase\" + nix develop --build -f derivation.nix -I .envrc --print-build-logs + - nix profile install . --print-build-logs + nix-instantiate | nix show-derivation | jq + " + ''; + }; + spine-search-gdc = stdenv.mkDerivation { + inherit pname; + inherit version; + meta.mainProgram = "spine_search-gdc"; + executable = true; + src = self; + buildInputs = [ sqlite ]; + nativeBuildInputs = [ dub gdc gnumake ]; + buildPhase = '' + runHook preBuild + dub build --compiler=$(type -P gdc) --build=gdc --combined --skip-registry=all + runHook postBuild + ''; + checkPhase = '' + runHook preCheck dub test --combined --skip-registry=all runHook postCheck ''; @@ -73,7 +210,8 @@ devShells = forAllSystems (system: let pkgs = nixpkgsFor.${system}; in with pkgs; { - devShell = mkShell { buildInputs = [ git dub dmd ldc gdc sqlite ]; }; + devShell = mkShell { }; + #devShell = mkShell { buildInputs = [ git dub dmd ldc gdc sqlite ]; }; }); }; } diff --git a/org/config_nix.org b/org/config_nix.org index 5cbff2a..21aff72 100644 --- a/org/config_nix.org +++ b/org/config_nix.org @@ -79,6 +79,7 @@ nix show-derivation /nix/store/q7n14bm8j5vzm62qaraczdb4bpyf59vv-spine-0.11.1.drv #+HEADER: :tangle ../.envrc #+BEGIN_SRC sh use flake . +#use flake .#default NIX_ENFORCE_PURITY=1 NixDirEnvVersion="2.2.0" if ! has nix_direnv_version || ! nix_direnv_version ${NixDirEnvVersion}; then @@ -86,9 +87,32 @@ if ! has nix_direnv_version || ! nix_direnv_version ${NixDirEnvVersion}; then # source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/${NixDirEnvVersion}/direnvrc" "sha256-0000000000000000000000000000000000000000000=" source_url "https://raw.githubusercontent.com/nix-community/nix-direnv/${NixDirEnvVersion}/direnvrc" "sha256-5EwyKnkJNQeXrRkYbwwRBcXbibosCJqyIUuz9Xq+LRc=" fi +# reload when these files change +watch_file flake.lock +watch_file flake.nix +nix flake update && nix flake check --show-trace && nix flake show if [ -f .envrc-local ]; then source_env_if_exists .envrc-local || source .envrc-local fi +echo " + +- nix flake update && nix flake check --show-trace && nix flake show && nix develop .#devShell + +- nix build .#default --print-build-logs +- nix build .#spine-search-ldc --print-build-logs +- nix build .#spine-search-dmd --print-build-logs +- nix build .#spine-search-gdc --print-build-logs + +nix-shell '' -A nix --pure + +nix run .#default --print-build-logs + +nix develop --build .#default --print-build-logs + +nix shell .#default --print-build-logs --command spine -v +nix shell .#default --print-build-logs --command spine --very-verbose --epub --html --html-link-search --html-link-curate --curate --output=\"\$SpineOUT\" ./markup/pod +nix shell .#default --print-build-logs --command spine --very-verbose --html --html-link-search --html-link-curate --curate --sqlite-update --sqlite-db-filename=\"spine.search.db\" --cgi-sqlite-search-filename=\"spine_search\" --sqlite-db-path=\"\$SpineDBpath\" --output=\"\$SpineOUT\" ./markup/pod +" #+END_SRC **** .envrc-local CHECK MODIFY @@ -98,11 +122,6 @@ fi #+HEADER: :tangle ../.envrc-local_ #+HEADER: :noweb yes #+BEGIN_SRC sh -# reload when these files change -watch_file flake.lock -watch_file flake.nix -nix flake update; nix flake check; nix flake show -#use flake .#default export NIX_PATH=/nix/var/nix/profiles/per-user/root/channels/nixos #export NIX_PATH=nixpkgs=/srv/nix/nixpkgs export DFLAGS="-O2 -inline -boundscheck=on -color=on" @@ -172,8 +191,9 @@ postInstall: inputs.flake-utils.url = "github:numtide/flake-utils"; outputs = { self, nixpkgs, flake-utils }: let + pname = "spine_search"; version = "<>"; - supportedSystems = [ "x86_64-linux" ]; # [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ]; + 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. in { @@ -181,22 +201,80 @@ postInstall: let pkgs = nixpkgsFor.${system}; in with pkgs; { default = stdenv.mkDerivation { - pname = "spine_search"; + inherit pname; inherit version; executable = true; src = self; shell = ./default.nix; devEnv = ./devenv.nix; buildInputs = [ sqlite ]; - nativeBuildInputs = [ dub ldc ]; # [ dub dmd ]; [ dub ldc ]; [ dub gdc ]; - <> + nativeBuildInputs = [ dub dmd ldc gdc gnumake ]; # [ dub dmd ]; [ dub ldc ]; [ dub gdc ]; + 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 --compiler=$DC --build=$DC_ --combined --skip-registry=all + runHook postBuild + ''; + <> + }; + spine-search-dmd = stdenv.mkDerivation { + inherit pname; + inherit version; + meta.mainProgram = "spine_search-dmd"; + executable = true; + src = self; + buildInputs = [ sqlite ]; + nativeBuildInputs = [ dub dmd gnumake ]; + buildPhase = '' + runHook preBuild + dub build --compiler=$(type -P dmd) --build=dmd --combined --skip-registry=all + runHook postBuild + ''; + <> + }; + spine-search-ldc = stdenv.mkDerivation { + inherit pname; + inherit version; + meta.mainProgram = "spine_search-ldc"; + executable = true; + src = self; + buildInputs = [ sqlite ]; + nativeBuildInputs = [ dub ldc gnumake ]; + buildPhase = '' + runHook preBuild + dub build --compiler=$(type -P ldc2) --build=ldc2 --combined --skip-registry=all + runHook postBuild + ''; + <> + }; + spine-search-gdc = stdenv.mkDerivation { + inherit pname; + inherit version; + meta.mainProgram = "spine_search-gdc"; + executable = true; + src = self; + buildInputs = [ sqlite ]; + nativeBuildInputs = [ dub gdc gnumake ]; + buildPhase = '' + runHook preBuild + dub build --compiler=$(type -P gdc) --build=gdc --combined --skip-registry=all + runHook postBuild + ''; + <> }; #vendorSha256 = "sha256-0Q00000000000000000000000000000000000000000="; }); devShells = forAllSystems (system: let pkgs = nixpkgsFor.${system}; in with pkgs; { - devShell = mkShell { buildInputs = [ git dub dmd ldc gdc sqlite ]; }; + devShell = mkShell { }; + #devShell = mkShell { buildInputs = [ git dub dmd ldc gdc sqlite ]; }; }); }; } @@ -245,10 +323,10 @@ postInstall: outputs = { <> }: let version = "<>"; - supportedSystems = [ "x86_64-linux" ]; # [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ]; - # helper function to generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'. + supportedSystems = [ "x86_64-linux" ]; # [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ]; + # helper function to generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'. forAllSystems = nixpkgs.lib.genAttrs supportedSystems; - nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; }); # nixpkgs instantiated for supported system types. + nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; }); # nixpkgs instantiated for supported system types. <> in { packages = forAllSystems (system: @@ -379,9 +457,14 @@ buildPhase = '' dub build --compiler=$DC --build=$DC_ --combined --skip-registry=all runHook postBuild ''; +<> +#+END_SRC + +#+NAME: flake_phases_other_than_buildPhase +#+HEADER: :noweb yes +#+BEGIN_SRC nix checkPhase = '' runHook preCheck - HOME="$PWD" dub test --combined --skip-registry=all runHook postCheck ''; @@ -486,7 +569,7 @@ mkShell { nix shell --print-build-logs - nix develop - nix develop --build .#default --print-build-logs + nix develop --build .#default --print-build-logs nix develop --build -f derivation.nix -I .envrc --print-build-logs nix develop ; eval \$buildPhase @@ -765,10 +848,10 @@ pkgs.callPackage ./derivation.nix {} #+HEADER: :tangle ../devenv.nix #+HEADER: :tangle-mode (identity #o755) #+BEGIN_SRC nix -{ pkgs ? import { }, name ? "user-env" }: with pkgs; +{ pkgs ? import { }, name ? "user-env" }: with pkgs; buildEnv { inherit name; - extraOutputsToInstall = [ "out" "man" "lib" ]; # to get all needed symlinks + extraOutputsToInstall = [ "out" "man" "lib" ]; # to get all needed symlinks paths = [ #nix # if not on NixOS, this is needed direnv diff --git a/shell.nix b/shell.nix index 1282fbb..9bed82b 100755 --- a/shell.nix +++ b/shell.nix @@ -64,7 +64,7 @@ mkShell { nix shell --print-build-logs - nix develop - nix develop --build .#default --print-build-logs + nix develop --build .#default --print-build-logs nix develop --build -f derivation.nix -I .envrc --print-build-logs nix develop ; eval \$buildPhase -- cgit v1.2.3