diff options
| -rw-r--r-- | .envrc | 15 | ||||
| -rw-r--r-- | default.nix | 7 | ||||
| -rw-r--r-- | dub.json | 29 | ||||
| -rw-r--r-- | dub.sdl | 87 | ||||
| -rw-r--r-- | dub.selections.nix | 50 | ||||
| -rw-r--r-- | mkDub.nix | 125 | ||||
| -rw-r--r-- | nixDevEnv/overlays/dmdVersion.nix | 17 | ||||
| -rw-r--r-- | nixDevEnv/shells/dmd.nix | 23 | ||||
| -rw-r--r-- | nixDevEnv/shells/ldc.nix | 27 | ||||
| -rw-r--r-- | org/spine_build_scaffold.org | 447 | ||||
| -rw-r--r-- | project.nix | 7 | ||||
| -rw-r--r-- | shell.nix | 24 | 
12 files changed, 739 insertions, 119 deletions
| @@ -1,2 +1,13 @@ -use nix -NIX_ENFORCE_PURITY=0 +if type lorri &>/dev/null; then +    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 +fi +# source an additional user-specific .envrc in ./.envrc-local +if [ -e .envrc-local ]; then +   source .envrc-local +fi diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..ab10c24 --- /dev/null +++ b/default.nix @@ -0,0 +1,7 @@ +{ pkgs ? import <nixpkgs> {}, }: +with import ./mkDub.nix { inherit pkgs; }; +mkDubDerivation { +  version = "0.11.1"; # optional +  src = ./.; +  buildInputs = [ pkgs.sqlite ]; +} @@ -4,6 +4,7 @@    ],    "copyright":                 "Copyright © 2015 - 2020 Ralph Amissah",    "name":                      "spine", +  "version":                   "0.11.1",    "description":               "a sisu like document parser",    "homepage":                  "http://sisudoc.org",    "license":                   "AGPL-3.0+", @@ -13,15 +14,24 @@    "buildRequirements":         [ "allowWarnings" ],    "targetType":                "executable",    "platforms":                 [ "posix" ], +  "buildTypes": { +    "dmd": { +      "dflags":                [ "-J=views", "-I=src/doc_reform" ], +      "buildOptions":          [ "verbose", "inline" ], +      "buildRequirements":     [ "allowWarnings" ] +    }, +    "ldc": { +      "dflags":                [ "-O2", "-J=views", "-I=src/doc_reform" ], +      "buildOptions":          [ "verbose", "optimize", "inline" ], +      "buildRequirements":     [ "allowWarnings" ] +    } +  },    "dependencies": {      "d2sqlite3":               "~>0.19.1",      "imageformats":            "~>7.0.2",      "dyaml":                   "~>0.8.0",      "tinyendian":              "~>0.2.0"    }, -  "subConfigurations": { -    "d2sqlite3":               "all-included" -  },    "configurations": [      {        "name":                  "default", @@ -36,16 +46,7 @@        "targetName":            "spine-dmd"      }    ], -  "buildTypes": { -    "dmd": { -      "dflags":                [ "-J=views", "-I=src/doc_reform" ], -      "buildOptions":          [ "verbose", "inline" ], -      "buildRequirements":     [ "allowWarnings" ] -    }, -    "ldc": { -      "dflags":                [ "-O2", "-J=views", "-I=src/doc_reform" ], -      "buildOptions":          [ "verbose", "optimize", "inline" ], -      "buildRequirements":     [ "allowWarnings" ] -    } +  "subConfigurations": { +    "d2sqlite3":               "with-lib"    }  } @@ -0,0 +1,87 @@ +#!/usr/bin/env dub +name                "spine" +description         "sisu document parser" +homepage            "http://sisudoc.org" +authors             "Ralph Amissah" +copyright           "Copyright (C) 2016 - 2020 Ralph Amissah" +license             "AGPL-3.0+" +targetPath          "./bin" +#sourcePath          "./src/doc_reform" +stringImportPaths   "./views" +buildRequirements   "allowWarnings" +targetType          "executable" +platforms           "posix" +dependency          "d2sqlite3"      version="~>0.19.1"      # https://code.dlang.org/packages/d2sqlite3     http://biozic.github.io/d2sqlite3/d2sqlite3 +  subconfiguration  "d2sqlite3"      "all-included" +dependency          "imageformats"   version="~>7.0.2"       # https://code.dlang.org/packages/imageformats  https://github.com/lgvz/imageformats +dependency          "dyaml"          version="~>0.8.0"       # https://code.dlang.org/packages/dyaml         https://github.com/dlang-community/D-YAML +dependency          "tinyendian"     version="~>0.2.0"       # http://code.dlang.org/packages/tinyendian     https://github.com/dlang-community/tinyendian // dyaml dependency +configuration "default" { +  targetName           "spine" +  #postGenerateCommands "notify-send -t 0 'D executable ready' 'spine'" +} +configuration "dmd" { +  targetName           "spine-dmd" +  #postGenerateCommands "notify-send -t 0 'D executable ready' 'spine-dmd'" +} +buildType     "dmd" { +  dflags               "-J=views" "-I=src/doc_reform" +  buildOptions         "verbose" "inline" +  buildRequirements    "allowWarnings" +} +buildType     "dmd-release" { +  dflags               "-J=views" "-I=src/doc_reform" +  buildOptions         "verbose" "releaseMode" "optimize" "inline" +} +configuration "dmd-version" { +  dflags               "-J=views" "-I=src/doc_reform" +  buildOptions         "verbose" "optimize" +  targetName           "spine-dmd-ver" +  #postGenerateCommands "notify-send -t 0 'D executable ready' 'spine-dmd-ver'" +} +configuration "ldc" { +  targetName           "spine-ldc" +  #postGenerateCommands "notify-send -t 0 'D executable ready' 'spine-ldc'" +} +buildType     "ldc" { +  dflags            "-O2" "-J=views" "-I=src/doc_reform" +  buildOptions      "verbose" "optimize" "inline" +  buildRequirements "allowWarnings" +} +buildType     "ldc-local" { +  dflags            "-O2" "-J=views" "-I=src/doc_reform" "-mcpu=native" +  buildOptions      "verbose" "optimize" "inline" +  buildRequirements "allowWarnings" +} +buildType     "ldc-release" { +  dflags               "-O2" "-J=views" "-I=src/doc_reform" +  buildOptions         "verbose" "optimize" "inline" "releaseMode" +} +configuration "ldc-version" { +  dflags               "-O2" "-J=views" "-I=src/doc_reform" +  buildOptions         "verbose" "optimize" "inline" "releaseMode" +  targetName           "spine-ldc-ver" +  #postGenerateCommands "notify-send -t 0 'D executable ready' 'spine-ldc-ver'" +} +configuration "gdc" { +  targetName           "spine-gdc" +  #postGenerateCommands "notify-send -t 0 'D executable ready' 'spine-gdc'" +} +buildType     "gdc" { +  dflags               "-O" "-J=views" "-I=src/doc_reform" +  lflags               "-lz" +  buildOptions         "inline" +  buildRequirements    "allowWarnings" +} +buildType     "gdc-release" { +  dflags               "-O2" "-J=views" "-I=src/doc_reform" +  lflags               "-lz" +  buildOptions         "verbose" "optimize" "inline" "releaseMode" +} +configuration "gdc-version" { +  dflags               "-O2" "-J=views" "-I=src/doc_reform" +  lflags               "-lz" +  buildOptions         "verbose" "optimize" "inline" "releaseMode" +  targetName           "spine-gdc-ver" +  #postGenerateCommands "notify-send -t 0 'D executable ready' 'spine-gdc-ver'" +} diff --git a/dub.selections.nix b/dub.selections.nix new file mode 100644 index 0000000..28f9d2e --- /dev/null +++ b/dub.selections.nix @@ -0,0 +1,50 @@ +# This file was generated by https://github.com/lionello/dub2nix v0.2.3 +[ { +  fetch = { +    type = "git"; +    url = "https://github.com/dlang-community/d2sqlite3.git"; +    rev = "v0.19.1"; +    sha256 = "0rnsgla6xyr8r34knf7v6dwhacra96q1b5rhxcz9246inwhvrk5k"; +    fetchSubmodules = false; +    date = "2020-07-21T12:32:51+02:00"; +    deepClone = false; +    leaveDotGit = false; +    path = "/nix/store/hsi8xvl15w6fwlqvs042m1z5i88yc72i-d2sqlite3"; +  }; +} { +  fetch = { +    type = "git"; +    url = "https://github.com/kiith-sa/tinyendian.git"; +    rev = "v0.2.0"; +    sha256 = "086gf5aga52wr5rj2paq54daj8lafn980x77b706vvvqaz2mlis8"; +    fetchSubmodules = false; +    date = "2018-06-10T11:04:28+02:00"; +    deepClone = false; +    leaveDotGit = false; +    path = "/nix/store/9c7fsmi5am84j6dq2mp3va306x3ay291-tinyendian"; +  }; +} { +  fetch = { +    type = "git"; +    url = "https://github.com/kiith-sa/D-YAML.git"; +    rev = "v0.8.3"; +    sha256 = "13wy304xjbwkpgg7ilql1lkxkm83s87jm59ffnrg26slp7cx149q"; +    fetchSubmodules = false; +    date = "2020-09-19T23:46:57+02:00"; +    deepClone = false; +    leaveDotGit = false; +    path = "/nix/store/3i8i56lkmw2xq3lxr5h66v909waq2mqg-D-YAML"; +  }; +} { +  fetch = { +    type = "git"; +    url = "https://github.com/lgvz/imageformats.git"; +    rev = "v7.0.2"; +    sha256 = "1mfbsmi4fs1xny4zqs6jyr04d5f4h03r9f6jadvkdqj5kd1k0ws7"; +    fetchSubmodules = false; +    date = "2019-10-10T07:54:45+03:00"; +    deepClone = false; +    leaveDotGit = false; +    path = "/nix/store/wn554pn21nzmpvw2hs7hvv9v9y0sgarg-imageformats"; +  }; +} ] diff --git a/mkDub.nix b/mkDub.nix new file mode 100644 index 0000000..8fe20a3 --- /dev/null +++ b/mkDub.nix @@ -0,0 +1,125 @@ +{ pkgs ? import <nixpkgs> {}, +  stdenv ? pkgs.stdenv, +  rdmd ? pkgs.rdmd, +  #dmd ? pkgs.dmd, +  #gcc ? pkgs.gcc, +  ldc ? pkgs.ldc, +  dub ? pkgs.dub +}: + +with stdenv; +let +  # Filter function to remove the .dub package folder from src +  filterDub = name: type: let baseName = baseNameOf (toString name); in ! ( +    type == "directory" && baseName == ".dub" +  ); + +  # Convert a GIT rev string (tag) to a simple semver version +  rev-to-version = builtins.replaceStrings ["v" "refs/tags/v"] ["" ""]; + +  dep2src = dubDep: pkgs.fetchgit { inherit (dubDep.fetch) url rev sha256 fetchSubmodules; }; + +  # Fetch a dependency (source only for now) +  fromDub = dubDep: mkDerivation rec { +    name = "${src.name}-${version}"; +    version = rev-to-version dubDep.fetch.rev; +    nativeBuildInputs = [ rdmd ldc dub ]; +    src = dep2src dubDep; + +    buildPhase = '' +      runHook preBuild +      export HOME=$PWD +      dub build -b=release +      runHook postBuild +    ''; + +    # outputs = [ "lib" ]; + +    # installPhase = '' +    #   runHook preInstall +    #   mkdir -p $out/bin +    #   runHook postInstall +    # ''; +  }; + +  # Adds a local package directory (e.g. a git repository) to Dub +  dub-add-local = dubDep: "dub add-local ${(fromDub dubDep).src.outPath} ${rev-to-version dubDep.fetch.rev}"; + +  # 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 rdmd dub ] ++ builtins.map dep2src deps; + +  removeExpr = refs: ''remove-references-to ${lib.concatMapStrings (ref: " -t ${ref}") refs}''; + +in { +  inherit fromDub; + +  mkDubDerivation = lib.makeOverridable ({ +    src, +    nativeBuildInputs ? [], +    dubJSON ? src + "/dub.json", +    selections ? src + "/dub.selections.nix", +    deps ? import selections, +    passthru ? {}, +    package ? lib.importJSON dubJSON, +    ... +  } @ attrs: stdenv.mkDerivation (attrs // { + +    pname = package.name; + +    nativeBuildInputs = [ rdmd ldc dub pkgs.removeReferencesTo ] ++ nativeBuildInputs; +    disallowedReferences = disallowedReferences deps; + +    passthru = passthru // { +      inherit dub ldc rdmd pkgs; +    }; + +    src = lib.cleanSourceWith { +      filter = filterDub; +      src = lib.cleanSource src; +    }; + +    preFixup = '' +      find $out/bin -type f -exec ${removeExpr (disallowedReferences deps)} '{}' + || true +    ''; + +    buildPhase = '' +      runHook preBuild + +      export HOME=$PWD +      ${lib.concatMapStringsSep "\n" dub-add-local deps} +      dub build --compiler=ldc2 --build=release --combined --skip-registry=all +      #dub build -b optimize -b inline --combined --skip-registry=all + +      runHook postBuild +    ''; + +    checkPhase = '' +      runHook preCheck + +      export HOME=$PWD +      ${lib.concatMapStringsSep "\n" dub-add-local deps} +      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)) { +    # Use name from dub.json, unless pname and version are specified +    name = package.name; +  })); +} diff --git a/nixDevEnv/overlays/dmdVersion.nix b/nixDevEnv/overlays/dmdVersion.nix deleted file mode 100644 index 51e1f67..0000000 --- a/nixDevEnv/overlays/dmdVersion.nix +++ /dev/null @@ -1,17 +0,0 @@ -self: super: rec { -  version = "2.094.0"; -  sha256 = "0xhm8m46ahfx3hcibi3vws02zaplny3226f3x8cd8584gzfqyzxp"; -  year = "2020"; -  dmd = super.dmd.overrideAttrs(oldAttrs: rec { -    inherit year version sha256; -    pname = oldAttrs.pname; -    name = "${pname}-${version}"; -    src = super.fetchurl { -      url = "http://downloads.dlang.org/releases/${year}/dmd.${version}.linux.tar.xz"; -      sha256 = sha256; -    }; -    # postUnpack = '' -    #   patchShebangs . -    # ''; -  }); -} diff --git a/nixDevEnv/shells/dmd.nix b/nixDevEnv/shells/dmd.nix index f3d126c..0c68cc0 100644 --- a/nixDevEnv/shells/dmd.nix +++ b/nixDevEnv/shells/dmd.nix @@ -1,10 +1,17 @@ -{ pkgs ? import <nixpkgs> { overlays = [ (import ../overlays/dmdVersion.nix) ]; } }: -  pkgs.mkShell { -    buildInputs = with pkgs; [ -      dub -      ninja -      dmd -      sqlite -      validatePkgConfig +{ pkgs ? import <nixpkgs> { overlays = []; } }: +let +  dub2nix-src = fetchTarball { +    url = "https://github.com/lionello/dub2nix/archive/master.tar.gz"; +  }; +  dub2nix = (import dub2nix-src) { inherit pkgs; }; +in pkgs.mkShell { +  buildInputs = with pkgs; [ +    nix +    dub +    dmd +    rdmd +    sqlite +    dub2nix +    nix-prefetch-git    ];  } diff --git a/nixDevEnv/shells/ldc.nix b/nixDevEnv/shells/ldc.nix index 1900112..31cfcfb 100644 --- a/nixDevEnv/shells/ldc.nix +++ b/nixDevEnv/shells/ldc.nix @@ -1,10 +1,21 @@ -{ pkgs ? import <nixpkgs> { overlays = [ (import ../overlays/ldcVersion.nix) ]; } }: -  pkgs.mkShell { -    buildInputs = with pkgs; [ -      dub -      ninja -      ldc -      sqlite -      validatePkgConfig +{ pkgs ? import <nixpkgs> { +  overlays = [ +    (import ./nixDevEnv/overlays/ldcVersion.nix) +  ]; } +}: +let +  dub2nix-src = fetchTarball { +    url = "https://github.com/lionello/dub2nix/archive/master.tar.gz"; +  }; +  dub2nix = (import dub2nix-src) { inherit pkgs; }; +in pkgs.mkShell { +  buildInputs = with pkgs; [ +    nix +    dub +    ldc +    rdmd +    sqlite +    dub2nix +    nix-prefetch-git    ];  } diff --git a/org/spine_build_scaffold.org b/org/spine_build_scaffold.org index 6a00b30..4470d00 100644 --- a/org/spine_build_scaffold.org +++ b/org/spine_build_scaffold.org @@ -971,6 +971,63 @@ gitsnapshot: distclean tangle    ],    "copyright":                 "Copyright © 2015 - 2020 Ralph Amissah",    "name":                      "spine", +  "version":                   "0.11.1", +  "description":               "a sisu like document parser", +  "homepage":                  "http://sisudoc.org", +  "license":                   "AGPL-3.0+", +  "targetPath":                "./bin", +  "sourcePaths":               [ "./src/doc_reform" ], +  "stringImportPaths":         [ "./views" ], +  "buildRequirements":         [ "allowWarnings" ], +  "targetType":                "executable", +  "platforms":                 [ "posix" ], +  "buildTypes": { +    "dmd": { +      "dflags":                [ "-J=views", "-I=src/doc_reform" ], +      "buildOptions":          [ "verbose", "inline" ], +      "buildRequirements":     [ "allowWarnings" ] +    }, +    "ldc": { +      "dflags":                [ "-O2", "-J=views", "-I=src/doc_reform" ], +      "buildOptions":          [ "verbose", "optimize", "inline" ], +      "buildRequirements":     [ "allowWarnings" ] +    } +  }, +  "dependencies": { +    "d2sqlite3":               "~>0.19.1", +    "imageformats":            "~>7.0.2", +    "dyaml":                   "~>0.8.0", +    "tinyendian":              "~>0.2.0" +  }, +  "configurations": [ +    { +      "name":                  "default", +      "targetName":            "spine" +    }, +    { +      "name":                  "ldc", +      "targetName":            "spine-ldc" +    }, +    { +      "name":                  "dmd", +      "targetName":            "spine-dmd" +    } +  ], +  "subConfigurations": { +    "d2sqlite3":               "with-lib" +  } +} +#+END_SRC + +** check dub.json + +#+BEGIN_SRC sh  :NO-tangle ../dub.json +{ +  "authors": [ +                               "Ralph Amissah" +  ], +  "copyright":                 "Copyright © 2015 - 2020 Ralph Amissah", +  "name":                      "spine",    "description":               "a sisu like document parser",    "homepage":                  "http://sisudoc.org",    "license":                   "AGPL-3.0+", @@ -1020,6 +1077,9 @@ gitsnapshot: distclean tangle  * dub.sdl                                                    :dub:sdl:config:  Every DUB package should contain a [[http://code.dlang.org/package-format?lang=json][dub.json]] (or [[http://code.dlang.org/package-format?lang=sdl][dub.sdl]]) + +not configured here using dub.json for the moment +  ** header (including dependencies)                                   :header:  #+BEGIN_SRC sh  :NO-tangle ../dub.sdl :tangle-mode (identity #o755) :shebang #!/usr/bin/env dub @@ -1563,93 +1623,357 @@ tinyendian_dep = declare_dependency(  #+END_SRC  * nix -** envrc +** dub2nix notes (from author (Lionello Lunesu) email reply, 2020-10-12) + +- https://github.com/lionello/dub2nix + +- see shell.nix minimal content: + +#+BEGIN_SRC nix :NO-tangle shell.nix +with import <nixpkgs> {}; +let +  dub2nix-src = fetchTarball { +    url = "https://github.com/lionello/dub2nix/archive/master.tar.gz"; +  }; +  dub2nix = (import dub2nix-src) { inherit pkgs; }; +in mkShell { +  buildInputs = [ +    dub dmd rdmd sqlite dub2nix nix-prefetch-git +  ]; +} +#+END_SRC -#+BEGIN_SRC nix :tangle ../.envrc -use nix -NIX_ENFORCE_PURITY=0 +- run: nix-shell + +- run: dub init + +- add d2sqlite3 dependency (provide as dependency during “dub init” or add it to +  the dub.json manually) + +#+BEGIN_SRC json :NO-tangle dub.json +{ +  "authors": [ +    "Ralph Amissah" +  ], +  "copyright": "Copyright © 2020, Ralph Amissah", +  "description": "A minimal D application.", +  "license": "AGPL-3", +    "name": "d2sqlite3_dub2nix", +  "dependencies": { +    "d2sqlite3": "~>0.19.1" +  }, +  "subConfigurations": { +    "d2sqlite3": "with-lib" +  } +}  #+END_SRC -** shells +- run: dub build + +- run: dub2nix save +  creates: dub.selections.nix + +- Create a new file default.nix with this content: + +#+BEGIN_SRC nix :NO-tangle default.nix +{ pkgs ? import <nixpkgs> {} }: +with import ./mkDub.nix { inherit pkgs; }; +mkDubDerivation { +    src = ./.; +    buildInputs = [ pkgs.sqlite ]; +} +#+END_SRC + +- Copy mkDub.nix from the dub2nix project. + +#+BEGIN_SRC sh +aria2c https://raw.githubusercontent.com/lionello/dub2nix/master/mkDub.nix +#+END_SRC + +make modificatons if desired + +- run: nix-build + +** envrc + +#+BEGIN_SRC nix :tangle ../.envrc +if type lorri &>/dev/null; then +    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 +fi +# source an additional user-specific .envrc in ./.envrc-local +if [ -e .envrc-local ]; then +   source .envrc-local +fi +#+END_SRC + +** shells shell.nix  *** nix-shell shell.nix  #+BEGIN_SRC nix :tangle ../shell.nix +<<nix_shell_with_compiler_ldc>> +#+END_SRC + +*** ldc shell + +#+BEGIN_SRC nix :tangle ../nixDevEnv/shells/ldc.nix +<<nix_shell_with_compiler_ldc>> +#+END_SRC + +#+NAME: nix_shell_with_compiler_ldc +#+BEGIN_SRC nix  { pkgs ? import <nixpkgs> {    overlays = [      (import ./nixDevEnv/overlays/ldcVersion.nix) -    (import ./nixDevEnv/overlays/dmdVersion.nix)    ]; }  }: -  pkgs.mkShell { -    buildInputs = with pkgs; [ -      dub -      ninja -      #meson -      dmd -      ldc -      sqlite -      validatePkgConfig +let +  dub2nix-src = fetchTarball { +    url = "https://github.com/lionello/dub2nix/archive/master.tar.gz"; +  }; +  dub2nix = (import dub2nix-src) { inherit pkgs; }; +in pkgs.mkShell { +  buildInputs = with pkgs; [ +    nix +    dub +    ldc +    rdmd +    sqlite +    dub2nix +    nix-prefetch-git    ];  }  #+END_SRC -*** ldc shell +*** dmd shell -#+BEGIN_SRC nix :tangle ../nixDevEnv/shells/ldc.nix -{ pkgs ? import <nixpkgs> { overlays = [ (import ../overlays/ldcVersion.nix) ]; } }: -  pkgs.mkShell { -    buildInputs = with pkgs; [ -      dub -      ninja -      ldc -      sqlite -      validatePkgConfig +#+BEGIN_SRC nix :tangle ../nixDevEnv/shells/dmd.nix +<<nix_shell_with_compiler_dmd>> +#+END_SRC + +#+NAME: nix_shell_with_compiler_dmd +#+BEGIN_SRC nix +{ pkgs ? import <nixpkgs> { overlays = []; } }: +let +  dub2nix-src = fetchTarball { +    url = "https://github.com/lionello/dub2nix/archive/master.tar.gz"; +  }; +  dub2nix = (import dub2nix-src) { inherit pkgs; }; +in pkgs.mkShell { +  buildInputs = with pkgs; [ +    nix +    dub +    dmd +    rdmd +    sqlite +    dub2nix +    nix-prefetch-git    ];  }  #+END_SRC -*** dmd shell +*** dmd & ldc -#+BEGIN_SRC nix :tangle ../nixDevEnv/shells/dmd.nix -{ pkgs ? import <nixpkgs> { overlays = [ (import ../overlays/dmdVersion.nix) ]; } }: -  pkgs.mkShell { -    buildInputs = with pkgs; [ -      dub -      ninja -      dmd -      sqlite -      validatePkgConfig +#+NAME: nix_shell_with_compilers_dmd_and_ldc +#+BEGIN_SRC nix +{ pkgs ? import <nixpkgs> { +  overlays = [ +    (import ./nixDevEnv/overlays/ldcVersion.nix) +  ]; } +}: +let +  dub2nix-src = fetchTarball { +    url = "https://github.com/lionello/dub2nix/archive/master.tar.gz"; +  }; +  dub2nix = (import dub2nix-src) { inherit pkgs; }; +in pkgs.mkShell { +  buildInputs = with pkgs; [ +    nix +    dub +    dmd +    ldc +    rdmd +    sqlite +    dub2nix +    nix-prefetch-git    ];  }  #+END_SRC -**** OLD nix-shell shell.nix +*** dub2nix version -#+BEGIN_SRC nix :NO-tangle ../shell.nix -{ pkgs ? import <nixpkgs> {} }: +#+BEGIN_SRC nix +  dub2nix-src = fetchTarball { +    url = "https://github.com/lionello/dub2nix/archive/8e7c65f1fd8c1ef5b32e2bf63ba80fe4f059ec15.tar.gz"; +    sha256 = "0imlbpv40h303h4mq4vijc9psl401n4sdxn3yp6k4gp2n0853xpm"; +  }; +#+END_SRC -with pkgs; +** default.nix -mkShell { -  buildInputs = with pkgs; [ -    ninja dub -    meson git -    ldc #ldc dmd gdc -    sqlite -    validatePkgConfig -    #gnumake gcc gdc cmake -    #clang -    #dzen2 -  ]; -  shellHook = '' -    echo `ldc2 --version` -  ''; -  COMPILER = "ldc2"; +#+BEGIN_SRC txt :tangle ../default.nix +<<nix_project>> +#+END_SRC + +#+BEGIN_SRC txt :tangle ../project.nix +<<nix_project>> +#+END_SRC + +#+NAME: nix_project +#+BEGIN_SRC nix +{ pkgs ? import <nixpkgs> {}, }: +with import ./mkDub.nix { inherit pkgs; }; +mkDubDerivation { +  version = "0.11.1"; # optional +  src = ./.; +  buildInputs = [ pkgs.sqlite ]; +} +#+END_SRC + +** mkDub.nix TODO + +Get current mkDub.nix from the dub2nix project: + +#+BEGIN_SRC sh +aria2c https://raw.githubusercontent.com/lionello/dub2nix/master/mkDub.nix +#+END_SRC + +#+BEGIN_SRC nix :tangle ../mkDub.nix +{ pkgs ? import <nixpkgs> {}, +  stdenv ? pkgs.stdenv, +  rdmd ? pkgs.rdmd, +  #dmd ? pkgs.dmd, +  #gcc ? pkgs.gcc, +  ldc ? pkgs.ldc, +  dub ? pkgs.dub +}: + +with stdenv; +let +  # Filter function to remove the .dub package folder from src +  filterDub = name: type: let baseName = baseNameOf (toString name); in ! ( +    type == "directory" && baseName == ".dub" +  ); + +  # Convert a GIT rev string (tag) to a simple semver version +  rev-to-version = builtins.replaceStrings ["v" "refs/tags/v"] ["" ""]; + +  dep2src = dubDep: pkgs.fetchgit { inherit (dubDep.fetch) url rev sha256 fetchSubmodules; }; + +  # Fetch a dependency (source only for now) +  fromDub = dubDep: mkDerivation rec { +    name = "${src.name}-${version}"; +    version = rev-to-version dubDep.fetch.rev; +    nativeBuildInputs = [ rdmd ldc dub ]; +    src = dep2src dubDep; + +    buildPhase = '' +      runHook preBuild +      export HOME=$PWD +      dub build -b=release +      runHook postBuild +    ''; + +    # outputs = [ "lib" ]; + +    # installPhase = '' +    #   runHook preInstall +    #   mkdir -p $out/bin +    #   runHook postInstall +    # ''; +  }; + +  # Adds a local package directory (e.g. a git repository) to Dub +  dub-add-local = dubDep: "dub add-local ${(fromDub dubDep).src.outPath} ${rev-to-version dubDep.fetch.rev}"; + +  # 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 rdmd dub ] ++ builtins.map dep2src deps; + +  removeExpr = refs: ''remove-references-to ${lib.concatMapStrings (ref: " -t ${ref}") refs}''; + +in { +  inherit fromDub; + +  mkDubDerivation = lib.makeOverridable ({ +    src, +    nativeBuildInputs ? [], +    dubJSON ? src + "/dub.json", +    selections ? src + "/dub.selections.nix", +    deps ? import selections, +    passthru ? {}, +    package ? lib.importJSON dubJSON, +    ... +  } @ attrs: stdenv.mkDerivation (attrs // { + +    pname = package.name; + +    nativeBuildInputs = [ rdmd ldc dub pkgs.removeReferencesTo ] ++ nativeBuildInputs; +    disallowedReferences = disallowedReferences deps; + +    passthru = passthru // { +      inherit dub ldc rdmd pkgs; +    }; + +    src = lib.cleanSourceWith { +      filter = filterDub; +      src = lib.cleanSource src; +    }; + +    preFixup = '' +      find $out/bin -type f -exec ${removeExpr (disallowedReferences deps)} '{}' + || true +    ''; + +    buildPhase = '' +      runHook preBuild + +      export HOME=$PWD +      ${lib.concatMapStringsSep "\n" dub-add-local deps} +      dub build --compiler=ldc2 --build=release --combined --skip-registry=all +      #dub build -b optimize -b inline --combined --skip-registry=all + +      runHook postBuild +    ''; + +    checkPhase = '' +      runHook preCheck + +      export HOME=$PWD +      ${lib.concatMapStringsSep "\n" dub-add-local deps} +      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)) { +    # Use name from dub.json, unless pname and version are specified +    name = package.name; +  }));  }  #+END_SRC  ** overlays -*** ldcVersion.nix overlay +*** compilers (latest versions) [version information set elsewhere] +**** ldcVersion.nix overlay  #+BEGIN_SRC nix :tangle ../nixDevEnv/overlays/ldcVersion.nix  self: super: rec { @@ -1669,9 +1993,11 @@ self: super: rec {  }  #+END_SRC -*** dmdVersion.nix overlay +**** dmdVersion.nix overlay + +no working overlay -#+BEGIN_SRC nix :tangle ../nixDevEnv/overlays/dmdVersion.nix +#+BEGIN_SRC nix :NO-tangle ../nixDevEnv/overlays/dmdVersion.nix  self: super: rec {    <<dmd_version_info>>    dmd = super.dmd.overrideAttrs(oldAttrs: rec { @@ -1692,7 +2018,8 @@ self: super: rec {  ** version info TODO  https://dlang.org/download.html -*** ldc TODO +*** compilers (set latest versions) TODO +**** ldc  https://github.com/ldc-developers/ldc/releases  #+NAME: ldc_version_info @@ -1701,7 +2028,7 @@ version = "1.23.0";  sha256 = "1fdgj222x29as466vdxy9c0m82zzlsb7vnvvh89n2riszcrx463d";  #+END_SRC -*** dmd TODO +**** dmd  https://dlang.org/changelog/index.html  https://dlang.org/changelog/pending.html  http://downloads.dlang.org/releases/ @@ -1791,7 +2118,7 @@ tmp/**  #.reggae/**  #+END_SRC -* sh script to batch process _emacs org babel tangle_   :shell_script:tangle: +* sh script to batch process _emacs org babel tangle_     :shell_script:tangle:    [[http://orgmode.org/manual/Batch-execution.html]]  creates a shell batch script called "tangle", that will tangle (emacs org  babel tangle) org files in ./org/ to create .d source files in ./src/doc_reform/ diff --git a/project.nix b/project.nix new file mode 100644 index 0000000..ab10c24 --- /dev/null +++ b/project.nix @@ -0,0 +1,7 @@ +{ pkgs ? import <nixpkgs> {}, }: +with import ./mkDub.nix { inherit pkgs; }; +mkDubDerivation { +  version = "0.11.1"; # optional +  src = ./.; +  buildInputs = [ pkgs.sqlite ]; +} @@ -1,17 +1,21 @@  { pkgs ? import <nixpkgs> {    overlays = [      (import ./nixDevEnv/overlays/ldcVersion.nix) -    (import ./nixDevEnv/overlays/dmdVersion.nix)    ]; }  }: -  pkgs.mkShell { -    buildInputs = with pkgs; [ -      dub -      ninja -      #meson -      dmd -      ldc -      sqlite -      validatePkgConfig +let +  dub2nix-src = fetchTarball { +    url = "https://github.com/lionello/dub2nix/archive/master.tar.gz"; +  }; +  dub2nix = (import dub2nix-src) { inherit pkgs; }; +in pkgs.mkShell { +  buildInputs = with pkgs; [ +    nix +    dub +    ldc +    rdmd +    sqlite +    dub2nix +    nix-prefetch-git    ];  } | 
