From d0465e3837a71afae2f1a6f42eb923350d826e27 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Wed, 27 Jan 2021 10:45:51 -0500 Subject: shell.nix project.nix spine.nix mkDub.nix --- .envrc | 14 ++++---- default.nix | 2 +- flake.nix | 21 +++++++----- nix/mkDub.nix | 25 ++++++++++---- nix/pkglst/meson-pkgs.nix | 17 +++++++++ nix/pkglst/shell-pkgs.nix | 16 +++++++++ nix/shell-packages.nix | 15 -------- nix/shell/meson.nix | 10 ++++++ org/spine_build_scaffold.org | 82 ++++++++++++++++++++++++++++---------------- project.nix | 1 + shell.nix | 3 +- spine.nix | 27 +++++++++++---- 12 files changed, 160 insertions(+), 73 deletions(-) create mode 100644 nix/pkglst/meson-pkgs.nix create mode 100644 nix/pkglst/shell-pkgs.nix delete mode 100644 nix/shell-packages.nix create mode 100755 nix/shell/meson.nix diff --git a/.envrc b/.envrc index dd2752c..2721ba3 100644 --- a/.envrc +++ b/.envrc @@ -1,13 +1,13 @@ if type lorri &>/dev/null; then - echo "direnv: using lorri from PATH ($(type -p lorri))" - eval "$(lorri direnv)" + echo "direnv: using lorri from PATH ($(type -p lorri))" + eval "$(lorri direnv)" else - # fall back to using direnv's builtin nix support - # to prevent bootstrapping problems. - use nix - NIX_ENFORCE_PURITY=0 + # fall back to using direnv's builtin nix support + # to prevent bootstrapping problems. + use nix + NIX_ENFORCE_PURITY=0 fi # source an additional user-specific .envrc in ./.envrc-local if [ -e .envrc-local ]; then - source .envrc-local + source .envrc-local fi diff --git a/default.nix b/default.nix index fa6adad..5826a65 100755 --- a/default.nix +++ b/default.nix @@ -9,7 +9,7 @@ mkDubDerivation rec { src = ./.; buildInputs = [ pkgs.sqlite - (import ./nix/shell-packages.nix { inherit pkgs; }) + (import ./nix/pkglst/shell-pkgs.nix { inherit pkgs; }) ]; # installPhase = '' # install -m755 -D spine $out/bin/spine diff --git a/flake.nix b/flake.nix index a392048..3a1282b 100644 --- a/flake.nix +++ b/flake.nix @@ -3,9 +3,6 @@ inputs = { flake-utils.url = "github:numtide/flake-utils"; nixpkgs.url = "/nixpkgs-ra/nixpkgs/.gitworktree/ra/nixpkgs"; - # pkgs /nixpkgs-ra/nixpkgs/.gitworktree/ra/nixpkgs {} - #spine.url = "/grotto-ra/repo/git.repo/projects/project-spine/doc-reform"; - #spine.url = "./."; d2sqlite3 = { url = "github:dlang-community/d2sqlite3"; flake = false; @@ -27,11 +24,19 @@ flake = false; }; }; - outputs = { self, nixpkgs, flake-utils }: - flake-utils.lib.simpleFlake { - #flake-utils.lib.spine { - inherit self nixpkgs; + outputs = { self, d2sqlite3, tinyendian, dyaml, imageformats, dub2nix-src, nixpkgs, flake-utils }: + let + pkgs = nixpkgs.legacyPackages.x86_64-linux; + in { + packages.x86_64-linux.spine = pkgs.stdenv.mkDerivation { name = "spine"; - #shell = ./shell.nix; + inherit self; + src = self; + shell = ./shell.nix; + installPhase = '' + install -m755 spine $out/bin/spine + ''; }; + defaultPackage.x86_64-linux = self.packages.x86_64-linux.spine; + }; } diff --git a/nix/mkDub.nix b/nix/mkDub.nix index 8f4014b..2a6570f 100644 --- a/nix/mkDub.nix +++ b/nix/mkDub.nix @@ -1,8 +1,10 @@ { pkgs ? import {}, stdenv ? pkgs.stdenv, - ldc ? pkgs.ldc, + ldc ? null, + dcompiler ? pkgs.ldc, dub ? pkgs.dub }: +assert dcompiler != null; with stdenv; let # Filter function to remove the .dub package folder from src @@ -16,7 +18,7 @@ let fromDub = dubDep: mkDerivation rec { name = "${src.name}-${version}"; version = rev-to-version dubDep.fetch.rev; - nativeBuildInputs = [ ldc dub ]; + nativeBuildInputs = [ dcompiler dub ]; src = dep2src dubDep; buildPhase = '' runHook preBuild @@ -37,7 +39,7 @@ let # The target output of the Dub package targetOf = package: "${package.targetPath or "."}/${package.targetName or package.name}"; # Remove reference to build tools and library sources - disallowedReferences = deps: [ ldc dub ] ++ builtins.map dep2src deps; + disallowedReferences = deps: [ dcompiler dub ] ++ builtins.map dep2src deps; removeExpr = refs: ''remove-references-to ${lib.concatMapStrings (ref: " -t ${ref}") refs}''; in { inherit fromDub; @@ -52,10 +54,10 @@ in { ... } @ attrs: stdenv.mkDerivation (attrs // { pname = package.name; - nativeBuildInputs = [ ldc dub pkgs.removeReferencesTo ] ++ nativeBuildInputs; + nativeBuildInputs = [ dcompiler dub pkgs.removeReferencesTo ] ++ nativeBuildInputs; disallowedReferences = disallowedReferences deps; passthru = passthru // { - inherit dub ldc pkgs; + inherit dub dcompiler pkgs; }; src = lib.cleanSourceWith { filter = filterDub; @@ -68,7 +70,18 @@ in { runHook preBuild export HOME=$PWD ${lib.concatMapStringsSep "\n" dub-add-local deps} - dub build --compiler=ldc2 --build=release --combined --skip-registry=all + 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 = '' diff --git a/nix/pkglst/meson-pkgs.nix b/nix/pkglst/meson-pkgs.nix new file mode 100644 index 0000000..0066e34 --- /dev/null +++ b/nix/pkglst/meson-pkgs.nix @@ -0,0 +1,17 @@ +{ pkgs ? import {} }: +let + dub2nix-src = fetchTarball { + url = "https://github.com/lionello/dub2nix/archive/master.tar.gz"; + }; + dub2nix = (import dub2nix-src) { inherit pkgs; }; +in +with pkgs; [ + nix + meson + ninja + dub + ldc + sqlite + nix-prefetch-git + validatePkgConfig +] diff --git a/nix/pkglst/shell-pkgs.nix b/nix/pkglst/shell-pkgs.nix new file mode 100644 index 0000000..7587c02 --- /dev/null +++ b/nix/pkglst/shell-pkgs.nix @@ -0,0 +1,16 @@ +{ pkgs ? import {} }: +let + dub2nix-src = fetchTarball { + url = "https://github.com/lionello/dub2nix/archive/master.tar.gz"; + }; + dub2nix = (import dub2nix-src) { inherit pkgs; }; +in +with pkgs; [ + nixFlakes + dub + ldc + sqlite + nix-prefetch-git + validatePkgConfig + jq +] diff --git a/nix/shell-packages.nix b/nix/shell-packages.nix deleted file mode 100644 index 9e40e24..0000000 --- a/nix/shell-packages.nix +++ /dev/null @@ -1,15 +0,0 @@ -{ pkgs ? import {} }: -let - dub2nix-src = fetchTarball { - url = "https://github.com/lionello/dub2nix/archive/master.tar.gz"; - }; - dub2nix = (import dub2nix-src) { inherit pkgs; }; -in -with pkgs; [ - nixFlakes - dub - ldc - sqlite - nix-prefetch-git - validatePkgConfig -] diff --git a/nix/shell/meson.nix b/nix/shell/meson.nix new file mode 100755 index 0000000..8c06eb8 --- /dev/null +++ b/nix/shell/meson.nix @@ -0,0 +1,10 @@ +{ pkgs ? import {} }: +pkgs.mkShell { + buildInputs = with pkgs; [ + (import ../pkgs/meson-pkgs.nix { inherit pkgs; }) + ]; + shellHook = '' + meson setup --wipe build && ninja -v -C build + ''; +} +# nix-shell nix/shell/meson.nix diff --git a/org/spine_build_scaffold.org b/org/spine_build_scaffold.org index ace6bc7..79ecff7 100644 --- a/org/spine_build_scaffold.org +++ b/org/spine_build_scaffold.org @@ -1757,17 +1757,17 @@ make modificatons if desired #+BEGIN_SRC nix :tangle ../.envrc if type lorri &>/dev/null; then - echo "direnv: using lorri from PATH ($(type -p lorri))" - eval "$(lorri direnv)" + echo "direnv: using lorri from PATH ($(type -p lorri))" + eval "$(lorri direnv)" else - # fall back to using direnv's builtin nix support - # to prevent bootstrapping problems. - use nix - NIX_ENFORCE_PURITY=0 + # fall back to using direnv's builtin nix support + # to prevent bootstrapping problems. + use nix + NIX_ENFORCE_PURITY=0 fi # source an additional user-specific .envrc in ./.envrc-local if [ -e .envrc-local ]; then - source .envrc-local + source .envrc-local fi #+END_SRC @@ -1842,8 +1842,8 @@ nix-instantiate --find-file nixpkgs /nixpkgs-ra/nixpkgs/.gitworktree/ra/nixpkgs ./shell.nix - shell.nix - ./shell-packages.nix - - shell-packages.nix + ./pkgs/shell-pkgs.nix + - pkgs/shell-pkgs.nix - default.nix ./nix/mkDub.nix - mkdub.nix @@ -1852,15 +1852,14 @@ nix-instantiate --find-file nixpkgs nix develop +nix flake update --recreate-lock-file + #+BEGIN_SRC nix :tangle ../flake.nix { description = "a sisu like document parser"; inputs = { flake-utils.url = "github:numtide/flake-utils"; nixpkgs.url = "/nixpkgs-ra/nixpkgs/.gitworktree/ra/nixpkgs"; - # pkgs /nixpkgs-ra/nixpkgs/.gitworktree/ra/nixpkgs {} - #spine.url = "/grotto-ra/repo/git.repo/projects/project-spine/doc-reform"; - #spine.url = "./."; d2sqlite3 = { url = "github:dlang-community/d2sqlite3"; flake = false; @@ -1882,13 +1881,21 @@ nix develop flake = false; }; }; - outputs = { self, nixpkgs, flake-utils }: - flake-utils.lib.simpleFlake { - #flake-utils.lib.spine { - inherit self nixpkgs; + outputs = { self, d2sqlite3, tinyendian, dyaml, imageformats, dub2nix-src, nixpkgs, flake-utils }: + let + pkgs = nixpkgs.legacyPackages.x86_64-linux; + in { + packages.x86_64-linux.spine = pkgs.stdenv.mkDerivation { name = "spine"; - #shell = ./shell.nix; + inherit self; + src = self; + shell = ./shell.nix; + installPhase = '' + install -m755 spine $out/bin/spine + ''; }; + defaultPackage.x86_64-linux = self.packages.x86_64-linux.spine; + }; } #+END_SRC @@ -1950,11 +1957,12 @@ nix develop { pkgs ? import {} }: pkgs.mkShell { buildInputs = with pkgs; [ - (import ./nix/shell-packages.nix { inherit pkgs; }) + (import ./nix/pkglst/shell-pkgs.nix { inherit pkgs; }) ]; shellHook = '' nix-build echo "built spine @ ./result/bin/spine" + nix-instantiate | nix show-derivation | jq ''; } #+END_SRC @@ -1972,7 +1980,7 @@ mkDubDerivation rec { version = "0.11.1"; src = ./.; buildInputs = with pkgs; [( - import ./nix/shell-packages.nix + import ./nix/pkglst/shell-pkgs.nix { inherit pkgs; } )]; meta = with stdenv.lib; { @@ -2059,7 +2067,7 @@ mkDubDerivation rec { src = ./.; buildInputs = [ pkgs.sqlite - (import ./nix/shell-packages.nix { inherit pkgs; }) + (import ./nix/pkglst/shell-pkgs.nix { inherit pkgs; }) ]; # installPhase = '' # install -m755 -D spine $out/bin/spine @@ -2104,9 +2112,11 @@ mkDubDerivation rec { #+BEGIN_SRC nix :tangle ../spine.nix :tangle-mode (identity #o755) :shebang "#!/usr/bin/env -S nix-build" { pkgs ? import {}, stdenv ? pkgs.stdenv, - ldc ? pkgs.ldc, + ldc ? null, + dcompiler ? pkgs.ldc, dub ? pkgs.dub }: +assert dcompiler != null; #with import ./nix/mkDub.nix { inherit pkgs; }; with ( # mkDub.nix <> @@ -2168,7 +2178,7 @@ aria2c https://raw.githubusercontent.com/lionello/dub2nix/master/mkDub.nix ./nix *** dub2nix -#+BEGIN_SRC nix :tangle ../nix/shell-packages.nix +#+BEGIN_SRC nix :tangle ../nix/pkglst/shell-pkgs.nix { pkgs ? import {} }: <> #+END_SRC @@ -2178,7 +2188,8 @@ aria2c https://raw.githubusercontent.com/lionello/dub2nix/master/mkDub.nix ./nix #+BEGIN_SRC nix :tangle ../nix/mkDub.nix { pkgs ? import {}, stdenv ? pkgs.stdenv, - ldc ? pkgs.ldc, + ldc ? null, + dcompiler ? pkgs.ldc, dub ? pkgs.dub }: <> @@ -2188,6 +2199,7 @@ aria2c https://raw.githubusercontent.com/lionello/dub2nix/master/mkDub.nix ./nix #+NAME: mkDub_nix #+BEGIN_SRC nix +assert dcompiler != null; with stdenv; let # Filter function to remove the .dub package folder from src @@ -2201,7 +2213,7 @@ let fromDub = dubDep: mkDerivation rec { name = "${src.name}-${version}"; version = rev-to-version dubDep.fetch.rev; - nativeBuildInputs = [ ldc dub ]; + nativeBuildInputs = [ dcompiler dub ]; src = dep2src dubDep; buildPhase = '' runHook preBuild @@ -2222,7 +2234,7 @@ let # The target output of the Dub package targetOf = package: "${package.targetPath or "."}/${package.targetName or package.name}"; # Remove reference to build tools and library sources - disallowedReferences = deps: [ ldc dub ] ++ builtins.map dep2src deps; + disallowedReferences = deps: [ dcompiler dub ] ++ builtins.map dep2src deps; removeExpr = refs: ''remove-references-to ${lib.concatMapStrings (ref: " -t ${ref}") refs}''; in { inherit fromDub; @@ -2237,10 +2249,10 @@ in { ... } @ attrs: stdenv.mkDerivation (attrs // { pname = package.name; - nativeBuildInputs = [ ldc dub pkgs.removeReferencesTo ] ++ nativeBuildInputs; + nativeBuildInputs = [ dcompiler dub pkgs.removeReferencesTo ] ++ nativeBuildInputs; disallowedReferences = disallowedReferences deps; passthru = passthru // { - inherit dub ldc pkgs; + inherit dub dcompiler pkgs; }; src = lib.cleanSourceWith { filter = filterDub; @@ -2253,7 +2265,18 @@ in { runHook preBuild export HOME=$PWD ${lib.concatMapStringsSep "\n" dub-add-local deps} - dub build --compiler=ldc2 --build=release --combined --skip-registry=all + 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 = '' @@ -2312,6 +2335,7 @@ ldc sqlite nix-prefetch-git validatePkgConfig +jq #+END_SRC * .gitignore :gitignore: @@ -2766,7 +2790,7 @@ stdenv.mkDerivation rec { if [ "$dc" == "" ]; then exit "Error: could not find D compiler" fi - echo "$dc_ used as D compiler to build dub" + echo "$dc_ used as D compiler to build $pname" $dc ./build.d ./build ''; diff --git a/project.nix b/project.nix index 1877443..8acb093 100755 --- a/project.nix +++ b/project.nix @@ -23,6 +23,7 @@ mkDubDerivation rec { sqlite nix-prefetch-git validatePkgConfig + jq ] ) ]; diff --git a/shell.nix b/shell.nix index 4edc4bd..941a217 100755 --- a/shell.nix +++ b/shell.nix @@ -2,10 +2,11 @@ { pkgs ? import {} }: pkgs.mkShell { buildInputs = with pkgs; [ - (import ./nix/shell-packages.nix { inherit pkgs; }) + (import ./nix/pkglst/shell-pkgs.nix { inherit pkgs; }) ]; shellHook = '' nix-build echo "built spine @ ./result/bin/spine" + nix-instantiate | nix show-derivation | jq ''; } diff --git a/spine.nix b/spine.nix index 0dc3f67..690fb09 100755 --- a/spine.nix +++ b/spine.nix @@ -1,11 +1,14 @@ #!/usr/bin/env -S nix-build { pkgs ? import {}, stdenv ? pkgs.stdenv, - ldc ? pkgs.ldc, + ldc ? null, + dcompiler ? pkgs.ldc, dub ? pkgs.dub }: +assert dcompiler != null; #with import ./nix/mkDub.nix { inherit pkgs; }; with ( # mkDub.nix + assert dcompiler != null; with stdenv; let # Filter function to remove the .dub package folder from src @@ -19,7 +22,7 @@ with ( # mkDub.nix fromDub = dubDep: mkDerivation rec { name = "${src.name}-${version}"; version = rev-to-version dubDep.fetch.rev; - nativeBuildInputs = [ ldc dub ]; + nativeBuildInputs = [ dcompiler dub ]; src = dep2src dubDep; buildPhase = '' runHook preBuild @@ -40,7 +43,7 @@ with ( # mkDub.nix # The target output of the Dub package targetOf = package: "${package.targetPath or "."}/${package.targetName or package.name}"; # Remove reference to build tools and library sources - disallowedReferences = deps: [ ldc dub ] ++ builtins.map dep2src deps; + disallowedReferences = deps: [ dcompiler dub ] ++ builtins.map dep2src deps; removeExpr = refs: ''remove-references-to ${lib.concatMapStrings (ref: " -t ${ref}") refs}''; in { inherit fromDub; @@ -55,10 +58,10 @@ with ( # mkDub.nix ... } @ attrs: stdenv.mkDerivation (attrs // { pname = package.name; - nativeBuildInputs = [ ldc dub pkgs.removeReferencesTo ] ++ nativeBuildInputs; + nativeBuildInputs = [ dcompiler dub pkgs.removeReferencesTo ] ++ nativeBuildInputs; disallowedReferences = disallowedReferences deps; passthru = passthru // { - inherit dub ldc pkgs; + inherit dub dcompiler pkgs; }; src = lib.cleanSourceWith { filter = filterDub; @@ -71,7 +74,18 @@ with ( # mkDub.nix runHook preBuild export HOME=$PWD ${lib.concatMapStringsSep "\n" dub-add-local deps} - dub build --compiler=ldc2 --build=release --combined --skip-registry=all + 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 = '' @@ -116,6 +130,7 @@ mkDubDerivation rec { sqlite nix-prefetch-git validatePkgConfig + jq ] ) ]; -- cgit v1.2.3