diff options
author | Guillaume Girol <symphorien@users.noreply.github.com> | 2021-09-22 18:35:38 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-22 18:35:38 +0000 |
commit | 4bc83aaffa715e2bc34842c9516b68debff03cd6 (patch) | |
tree | 9a8a5e36c7e483a018fe5884855f73c2e2d4965c /pkgs/development | |
parent | f9fc7ee26e42f4295ffb38e1749d53e3d317a5df (diff) | |
parent | bea75890b777e299a6b0709c33686bb69d21dbd4 (diff) |
Merge pull request #136489 from ehmry/nimPackages
nimpackages / buildNimPackage
Diffstat (limited to 'pkgs/development')
39 files changed, 673 insertions, 161 deletions
diff --git a/pkgs/development/compilers/nim/default.nix b/pkgs/development/compilers/nim/default.nix index 49e18097ab9a7..7434347f2a28f 100644 --- a/pkgs/development/compilers/nim/default.nix +++ b/pkgs/development/compilers/nim/default.nix @@ -1,8 +1,9 @@ # https://nim-lang.github.io/Nim/packaging.html # https://nim-lang.org/docs/nimc.html -{ lib, buildPackages, stdenv, fetchurl, fetchgit, fetchFromGitHub, makeWrapper -, openssl, pcre, readline, boehmgc, sqlite, nim-unwrapped }: +{ lib, callPackage, buildPackages, stdenv, fetchurl, fetchgit, fetchFromGitHub +, makeWrapper, openssl, pcre, readline, boehmgc, sqlite, nim-unwrapped +, nimble-unwrapped }: let parseCpu = platform: @@ -186,138 +187,141 @@ in { nim' = buildPackages.nim-unwrapped; nimble' = buildPackages.nimble-unwrapped; inherit (stdenv) targetPlatform; - in stdenv.mkDerivation { - name = "${targetPlatform.config}-nim-wrapper-${nim'.version}"; - inherit (nim') version; - preferLocalBuild = true; - strictDeps = true; - - nativeBuildInputs = [ makeWrapper ]; - - patches = [ - ./nim.cfg.patch - # Remove configurations that clash with ours - ]; - - unpackPhase = '' - runHook preUnpack - tar xf ${nim'.src} nim-$version/config - cd nim-$version - runHook postUnpack - ''; - - dontConfigure = true; - - buildPhase = - # Configure the Nim compiler to use $CC and $CXX as backends - # The compiler is configured by two configuration files, each with - # a different DSL. The order of evaluation matters and that order - # is not documented, so duplicate the configuration across both files. - '' - runHook preBuild - cat >> config/config.nims << WTF - - switch("os", "${nimTarget.os}") - switch("cpu", "${nimTarget.cpu}") - switch("define", "nixbuild") - - # Configure the compiler using the $CC set by Nix at build time - import strutils - let cc = getEnv"CC" - if cc.contains("gcc"): - switch("cc", "gcc") - elif cc.contains("clang"): - switch("cc", "clang") - WTF - - mv config/nim.cfg config/nim.cfg.old - cat > config/nim.cfg << WTF - os = "${nimTarget.os}" - cpu = "${nimTarget.cpu}" - define:"nixbuild" - WTF - - cat >> config/nim.cfg < config/nim.cfg.old - rm config/nim.cfg.old - - cat >> config/nim.cfg << WTF - - clang.cpp.exe %= "\$CXX" - clang.cpp.linkerexe %= "\$CXX" - clang.exe %= "\$CC" - clang.linkerexe %= "\$CC" - gcc.cpp.exe %= "\$CXX" - gcc.cpp.linkerexe %= "\$CXX" - gcc.exe %= "\$CC" - gcc.linkerexe %= "\$CC" - WTF - - runHook postBuild + self = stdenv.mkDerivation { + name = "${targetPlatform.config}-nim-wrapper-${nim'.version}"; + inherit (nim') version; + preferLocalBuild = true; + strictDeps = true; + + nativeBuildInputs = [ makeWrapper ]; + + patches = [ + ./nim.cfg.patch + # Remove configurations that clash with ours + ]; + + unpackPhase = '' + runHook preUnpack + tar xf ${nim'.src} nim-$version/config + cd nim-$version + runHook postUnpack ''; - wrapperArgs = [ - "--prefix PATH : ${lib.makeBinPath [ buildPackages.gdb ]}:${ - placeholder "out" - }/bin" - # Used by nim-gdb - - "--prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath [ openssl pcre ]}" - # These libraries may be referred to by the standard library. - # This is broken for cross-compilation because the package - # set will be shifted back by nativeBuildInputs. - - "--set NIM_CONFIG_PATH ${placeholder "out"}/etc/nim" - # Use the custom configuration - - ''--set NIX_HARDENING_ENABLE "''${NIX_HARDENING_ENABLE/fortify}"'' - # Fortify hardening appends -O2 to gcc flags which is unwanted for unoptimized nim builds. - ]; - - installPhase = '' - runHook preInstall - - mkdir -p $out/bin $out/etc + dontConfigure = true; + + buildPhase = + # Configure the Nim compiler to use $CC and $CXX as backends + # The compiler is configured by two configuration files, each with + # a different DSL. The order of evaluation matters and that order + # is not documented, so duplicate the configuration across both files. + '' + runHook preBuild + cat >> config/config.nims << WTF + + switch("os", "${nimTarget.os}") + switch("cpu", "${nimTarget.cpu}") + switch("define", "nixbuild") + + # Configure the compiler using the $CC set by Nix at build time + import strutils + let cc = getEnv"CC" + if cc.contains("gcc"): + switch("cc", "gcc") + elif cc.contains("clang"): + switch("cc", "clang") + WTF + + mv config/nim.cfg config/nim.cfg.old + cat > config/nim.cfg << WTF + os = "${nimTarget.os}" + cpu = "${nimTarget.cpu}" + define:"nixbuild" + WTF + + cat >> config/nim.cfg < config/nim.cfg.old + rm config/nim.cfg.old + + cat >> config/nim.cfg << WTF + + clang.cpp.exe %= "\$CXX" + clang.cpp.linkerexe %= "\$CXX" + clang.exe %= "\$CC" + clang.linkerexe %= "\$CC" + gcc.cpp.exe %= "\$CXX" + gcc.cpp.linkerexe %= "\$CXX" + gcc.exe %= "\$CC" + gcc.linkerexe %= "\$CC" + WTF + + runHook postBuild + ''; + + wrapperArgs = [ + "--prefix PATH : ${lib.makeBinPath [ buildPackages.gdb ]}:${ + placeholder "out" + }/bin" + # Used by nim-gdb + + "--prefix LD_LIBRARY_PATH : ${lib.makeLibraryPath [ openssl pcre ]}" + # These libraries may be referred to by the standard library. + # This is broken for cross-compilation because the package + # set will be shifted back by nativeBuildInputs. + + "--set NIM_CONFIG_PATH ${placeholder "out"}/etc/nim" + # Use the custom configuration + + ''--set NIX_HARDENING_ENABLE "''${NIX_HARDENING_ENABLE/fortify}"'' + # Fortify hardening appends -O2 to gcc flags which is unwanted for unoptimized nim builds. + ]; + + installPhase = '' + runHook preInstall + + mkdir -p $out/bin $out/etc + + cp -r config $out/etc/nim + + for binpath in ${nim'}/bin/nim?*; do + local binname=`basename $binpath` + makeWrapper \ + $binpath $out/bin/${targetPlatform.config}-$binname \ + $wrapperArgs + ln -s $out/bin/${targetPlatform.config}-$binname $out/bin/$binname + done - cp -r config $out/etc/nim + makeWrapper \ + ${nim'}/nim/bin/nim $out/bin/${targetPlatform.config}-nim \ + --set-default CC $(command -v $CC) \ + --set-default CXX $(command -v $CXX) \ + $wrapperArgs + ln -s $out/bin/${targetPlatform.config}-nim $out/bin/nim - for binpath in ${nim'}/bin/nim?*; do - local binname=`basename $binpath` makeWrapper \ - $binpath $out/bin/${targetPlatform.config}-$binname \ + ${nim'}/bin/testament $out/bin/${targetPlatform.config}-testament \ $wrapperArgs - ln -s $out/bin/${targetPlatform.config}-$binname $out/bin/$binname - done - - makeWrapper \ - ${nim'}/nim/bin/nim $out/bin/${targetPlatform.config}-nim \ - --set-default CC $(command -v $CC) \ - --set-default CXX $(command -v $CXX) \ - $wrapperArgs - ln -s $out/bin/${targetPlatform.config}-nim $out/bin/nim - - makeWrapper \ - ${nim'}/bin/testament $out/bin/${targetPlatform.config}-testament \ - $wrapperArgs - ln -s $out/bin/${targetPlatform.config}-testament $out/bin/testament - - makeWrapper \ - ${nimble'}/bin/nimble $out/bin/${targetPlatform.config}-nimble \ - --suffix PATH : $out/bin - ln -s $out/bin/${targetPlatform.config}-nimble $out/bin/nimble + ln -s $out/bin/${targetPlatform.config}-testament $out/bin/testament - runHook postInstall - ''; + makeWrapper \ + ${nimble'}/bin/nimble $out/bin/${targetPlatform.config}-nimble \ + --suffix PATH : $out/bin + ln -s $out/bin/${targetPlatform.config}-nimble $out/bin/nimble - passthru = { - nim = nim'; - nimble = nimble'; - }; + runHook postInstall + ''; + + passthru = { + nim = nim'; + nimble = nimble'; + }; - meta = nim'.meta // { - description = nim'.meta.description - + " (${targetPlatform.config} wrapper)"; - platforms = with lib.platforms; unix ++ genode; + meta = nim'.meta // { + description = nim'.meta.description + + " (${targetPlatform.config} wrapper)"; + platforms = with lib.platforms; unix ++ genode; + }; }; + in self // { + pkgs = callPackage ../../../top-level/nim-packages.nix { nim = self; }; }; } diff --git a/pkgs/development/nim-packages/astpatternmatching/default.nix b/pkgs/development/nim-packages/astpatternmatching/default.nix new file mode 100644 index 0000000000000..6f1137ac70456 --- /dev/null +++ b/pkgs/development/nim-packages/astpatternmatching/default.nix @@ -0,0 +1,8 @@ +{ fetchFromGitHub }: + +fetchFromGitHub { + owner = "krux02"; + repo = "ast-pattern-matching"; + rev = "87f7d163421af5a4f5e5cb6da7b93278e6897e96"; + sha256 = "19mb5bb6riia8380p5dpc3q0vwgrj958dd6p7vw8vkvwiqrzg6zq"; +} diff --git a/pkgs/development/nim-packages/build-nim-package/default.nix b/pkgs/development/nim-packages/build-nim-package/default.nix new file mode 100644 index 0000000000000..6c7aafd22c81e --- /dev/null +++ b/pkgs/development/nim-packages/build-nim-package/default.nix @@ -0,0 +1,43 @@ +{ lib, stdenv, nim, nim_builder }: + +{ strictDeps ? true, nativeBuildInputs ? [ ], configurePhase ? null +, buildPhase ? null, checkPhase ? null, installPhase ? null, meta ? { }, ... +}@attrs: + +stdenv.mkDerivation (attrs // { + inherit strictDeps; + nativeBuildInputs = [ nim nim_builder ] ++ nativeBuildInputs; + + configurePhase = if isNull configurePhase then '' + runHook preConfigure + find $NIX_BUILD_TOP -name .attrs.json + nim_builder --phase:configure + runHook postConfigure + '' else + buildPhase; + + buildPhase = if isNull buildPhase then '' + runHook preBuild + nim_builder --phase:build + runHook postBuild + '' else + buildPhase; + + checkPhase = if isNull checkPhase then '' + runHook preCheck + nim_builder --phase:check + runHook postCheck + '' else + checkPhase; + + installPhase = if isNull installPhase then '' + runHook preInstall + nim_builder --phase:install + runHook postInstall + '' else + installPhase; + + meta = meta // { + maintainers = (meta.maintainers or [ ]) ++ [ lib.maintainers.ehmry ]; + }; +}) diff --git a/pkgs/development/nim-packages/bumpy/default.nix b/pkgs/development/nim-packages/bumpy/default.nix new file mode 100644 index 0000000000000..9579d87d9d5d4 --- /dev/null +++ b/pkgs/development/nim-packages/bumpy/default.nix @@ -0,0 +1,7 @@ +{ fetchNimble }: + +fetchNimble { + pname = "bumpy"; + version = "1.0.3"; + hash = "sha256-mDmDlhOGoYYjKgF5j808oT2NqRlfcOdLSDE3WtdJFQ0="; +} diff --git a/pkgs/development/nim-packages/c2nim/default.nix b/pkgs/development/nim-packages/c2nim/default.nix new file mode 100644 index 0000000000000..408e4fbee96e7 --- /dev/null +++ b/pkgs/development/nim-packages/c2nim/default.nix @@ -0,0 +1,19 @@ +{ lib, buildNimPackage, fetchFromGitHub, SDL2 }: + +buildNimPackage rec { + pname = "c2nim"; + version = "0.9.18"; + nimBinOnly = true; + src = fetchFromGitHub { + owner = "nim-lang"; + repo = pname; + rev = version; + hash = "sha256-127ux36mfC+PnS2HIQffw+z0TSvzdQXnKRxqYV3XahU="; + }; + meta = with lib; + src.meta // { + description = "Tool to translate Ansi C code to Nim"; + license = licenses.mit; + maintainers = [ maintainers.ehmry ]; + }; +} diff --git a/pkgs/development/nim-packages/chroma/default.nix b/pkgs/development/nim-packages/chroma/default.nix new file mode 100644 index 0000000000000..266cd0645f367 --- /dev/null +++ b/pkgs/development/nim-packages/chroma/default.nix @@ -0,0 +1,7 @@ +{ fetchNimble }: + +fetchNimble { + pname = "chroma"; + version = "0.2.5"; + hash = "sha256-6lNHpO2aMorgkaPfo6kRcOs9r5R6T/kislVmkeoulw8="; +} diff --git a/pkgs/development/nim-packages/docopt/default.nix b/pkgs/development/nim-packages/docopt/default.nix new file mode 100644 index 0000000000000..38465384fbdef --- /dev/null +++ b/pkgs/development/nim-packages/docopt/default.nix @@ -0,0 +1,8 @@ +{ fetchFromGitHub }: + +fetchFromGitHub { + owner = "docopt"; + repo = "docopt.nim"; + rev = "v0.6.7"; + sha256 = "1ga7ckg21fzwwvh26jp2phn2h3pvkn8g8sm13dxif33rp471bv37"; +} diff --git a/pkgs/development/nim-packages/fetch-nimble/builder.sh b/pkgs/development/nim-packages/fetch-nimble/builder.sh new file mode 100644 index 0000000000000..693ab339408ed --- /dev/null +++ b/pkgs/development/nim-packages/fetch-nimble/builder.sh @@ -0,0 +1,12 @@ +source $stdenv/setup +export HOME=$NIX_BUILD_TOP + +nimble --accept --noSSLCheck develop "${pkgname}@${version}" +# TODO: bring in the certificates for Nimble to verify the fetch of +# the package list. + +pkgdir=${NIX_BUILD_TOP}/${pkgname} + +find "$pkgdir" -name .git -print0 | xargs -0 rm -rf + +cp -a "$pkgdir" "$out" diff --git a/pkgs/development/nim-packages/fetch-nimble/default.nix b/pkgs/development/nim-packages/fetch-nimble/default.nix new file mode 100644 index 0000000000000..ccdacc8e27b9b --- /dev/null +++ b/pkgs/development/nim-packages/fetch-nimble/default.nix @@ -0,0 +1,20 @@ +{ lib, makeOverridable, stdenv, gitMinimal, nim, cacert }: + +makeOverridable ( + + { pname, version, hash ? lib.fakeHash, + + meta ? { }, passthru ? { }, preferLocalBuild ? true }: + stdenv.mkDerivation { + inherit version meta passthru preferLocalBuild; + pname = pname + "-src"; + pkgname = pname; + builder = ./builder.sh; + nativeBuildInputs = [ gitMinimal nim ]; + outputHash = hash; + outputHashAlgo = null; + outputHashMode = "recursive"; + impureEnvVars = lib.fetchers.proxyImpureEnvVars + ++ [ "GIT_PROXY_COMMAND" "SOCKS_SERVER" ]; + GIT_SSL_CAINFO = "${cacert}/etc/ssl/certs/ca-bundle.crt"; + }) diff --git a/pkgs/development/nim-packages/flatty/default.nix b/pkgs/development/nim-packages/flatty/default.nix new file mode 100644 index 0000000000000..241b59f8230f1 --- /dev/null +++ b/pkgs/development/nim-packages/flatty/default.nix @@ -0,0 +1,7 @@ +{ fetchNimble }: + +fetchNimble { + pname = "flatty"; + version = "0.2.1"; + hash = "sha256-TqNnRh2+i6n98ktLRVQxt9CVw17FGLNYq29rJoMus/0="; +} diff --git a/pkgs/development/nim-packages/frosty/default.nix b/pkgs/development/nim-packages/frosty/default.nix new file mode 100644 index 0000000000000..6394c455d07ff --- /dev/null +++ b/pkgs/development/nim-packages/frosty/default.nix @@ -0,0 +1,8 @@ +{ fetchFromGitHub }: + +fetchFromGitHub { + owner = "disruptek"; + repo = "frosty"; + rev = "0.3.1"; + sha256 = "0hd6484ihjgl57gmqyp5xfq5prycb49k0313fqky600mhz71nmyz"; +} diff --git a/pkgs/development/nim-packages/hts-nim/default.nix b/pkgs/development/nim-packages/hts-nim/default.nix new file mode 100644 index 0000000000000..960a9e63d215f --- /dev/null +++ b/pkgs/development/nim-packages/hts-nim/default.nix @@ -0,0 +1,13 @@ +{ buildNimPackage, fetchFromGitHub, htslib }: + +buildNimPackage rec { + pname = "hts-nim"; + version = "0.3.4"; + src = fetchFromGitHub { + owner = "brentp"; + repo = pname; + rev = "v${version}"; + sha256 = "0670phk1bq3l9j2zaa8i5wcpc5dyfrc0l2a6c21g0l2mmdczffa7"; + }; + propagatedBuildInputs = [ htslib ]; +} diff --git a/pkgs/development/nim-packages/jester/default.nix b/pkgs/development/nim-packages/jester/default.nix new file mode 100644 index 0000000000000..21646f3667f03 --- /dev/null +++ b/pkgs/development/nim-packages/jester/default.nix @@ -0,0 +1,8 @@ +{ fetchFromGitHub }: + +fetchFromGitHub { + owner = "dom96"; + repo = "jester"; + rev = "v0.5.0"; + sha256 = "0m8a4ss4460jd2lcbqcbdd68jhcy35xg7qdyr95mh8rflwvmcvhk"; +} diff --git a/pkgs/development/nim-packages/jsonschema/default.nix b/pkgs/development/nim-packages/jsonschema/default.nix new file mode 100644 index 0000000000000..8dc195b8b8229 --- /dev/null +++ b/pkgs/development/nim-packages/jsonschema/default.nix @@ -0,0 +1,8 @@ +{ fetchFromGitHub }: + +fetchFromGitHub { + owner = "PMunch"; + repo = "jsonschema"; + rev = "7b41c03e3e1a487d5a8f6b940ca8e764dc2cbabf"; + sha256 = "1js64jqd854yjladxvnylij4rsz7212k31ks541pqrdzm6hpblbz"; +} diff --git a/pkgs/development/nim-packages/karax/default.nix b/pkgs/development/nim-packages/karax/default.nix new file mode 100644 index 0000000000000..35a5c78ee56a1 --- /dev/null +++ b/pkgs/development/nim-packages/karax/default.nix @@ -0,0 +1,8 @@ +{ fetchFromGitHub }: + +fetchFromGitHub { + owner = "karaxnim"; + repo = "karax"; + rev = "1.1.2"; + sha256 = "07ykrd21hd76vlmkqpvv5xvaxw6aaq87bky47p2420ni85a6d94j"; +} diff --git a/pkgs/development/nim-packages/lscolors/default.nix b/pkgs/development/nim-packages/lscolors/default.nix new file mode 100644 index 0000000000000..5a72c46e4c503 --- /dev/null +++ b/pkgs/development/nim-packages/lscolors/default.nix @@ -0,0 +1,8 @@ +{ fetchFromGitHub }: + +fetchFromGitHub { + owner = "joachimschmidt557"; + repo = "nim-lscolors"; + rev = "v0.3.3"; + sha256 = "0526hqh46lcfsvymb67ldsc8xbfn24vicn3b8wrqnh6mag8wynf4"; +} diff --git a/pkgs/development/nim-packages/markdown/default.nix b/pkgs/development/nim-packages/markdown/default.nix new file mode 100644 index 0000000000000..c893ff0e41485 --- /dev/null +++ b/pkgs/development/nim-packages/markdown/default.nix @@ -0,0 +1,8 @@ +{ fetchFromGitHub }: + +fetchFromGitHub { + owner = "soasme"; + repo = "nim-markdown"; + rev = "abdbe5e"; + sha256 = "0f3c1sxvhbbds43c9l8cz69pfpf984msj1lv4pb7bzpxb5zil2wy"; +} diff --git a/pkgs/development/nim-packages/nim_builder/default.nix b/pkgs/development/nim-packages/nim_builder/default.nix new file mode 100644 index 0000000000000..34da4dfa61a07 --- /dev/null +++ b/pkgs/development/nim-packages/nim_builder/default.nix @@ -0,0 +1,19 @@ +{ lib, stdenv, nim }: + +stdenv.mkDerivation { + pname = "nim_builder"; + inherit (nim) version; + dontUnpack = true; + nativeBuildInputs = [ nim ]; + buildPhase = '' + cp ${./nim_builder.nim} nim_builder.nim + nim c --nimcache:$TMPDIR nim_builder + ''; + installPhase = '' + install -Dt $out/bin nim_builder + ''; + meta = { + description = "Internal Nixpkgs utility for buildNimPackage."; + maintainers = [ lib.maintainers.ehmry ]; + }; +} diff --git a/pkgs/development/nim-packages/nim_builder/nim_builder.nim b/pkgs/development/nim-packages/nim_builder/nim_builder.nim new file mode 100644 index 0000000000000..b8881b700047f --- /dev/null +++ b/pkgs/development/nim-packages/nim_builder/nim_builder.nim @@ -0,0 +1,166 @@ +# SPDX-FileCopyrightText: 2021 Nixpkgs/NixOS contributors +## Custom Nim builder for Nixpkgs. + +import std/[os, osproc, parseutils, sequtils, streams, strutils] + +proc findNimbleFile(): string = + ## Copied from Nimble. + ## Copyright (c) 2015, Dominik Picheta + ## BSD3 + let dir = getCurrentDir() + result = "" + var hits = 0 + for kind, path in walkDir(dir): + if kind in {pcFile, pcLinkToFile}: + let ext = path.splitFile.ext + if ext == ".nimble": + result = path + inc hits + if hits >= 2: + quit("Only one .nimble file should be present in " & dir) + elif hits == 0: + quit("Could not find a file with a .nimble extension in " & dir) + +proc getEnvBool(key: string; default = false): bool = + ## Parse a boolean environmental variable. + let val = getEnv(key) + if val == "": default + else: parseBool(val) + +proc getNimbleFilePath(): string = + ## Get the Nimble file for the current package. + if existsEnv"nimbleFile": + getEnv"nimbleFile" + else: + findNimbleFile() + +proc getNimbleValue(filePath, key: string; default = ""): string = + ## Extract a string value from the Nimble file at ``filePath``. + var + fs = newFileStream(filePath, fmRead) + line: string + if fs.isNil: + quit("could not open " & filePath) + while fs.readline(line): + if line.startsWith(key): + var i = key.len + i.inc skipWhile(line, Whitespace, i) + if line[i] == '=': + inc i + i.inc skipWhile(line, Whitespace, i) + discard parseUntil(line, result, Newlines, i) + if result.len > 0 and result[0] == '"': + result = result.unescape + return + default + +proc getNimbleValues(filePath, key: string): seq[string] = + ## Extract a string sequence from the Nimble file at ``filePath``. + var gunk = getNimbleValue(filePath, key) + result = gunk.strip(chars = {'@', '[', ']'}).split(',') + if result == @[""]: reset result + apply(result) do (s: var string): + s = s.strip() + if s.len > 0 and s[0] == '"': + s = s.unescape() + +proc configurePhase*() = + ## Generate "config.nims" which will be read by the Nim + ## compiler during later phases. + const configFilePath = "config.nims" + echo "generating ", configFilePath + let + nf = getNimbleFilePath() + mode = + if fileExists configFilePath: fmAppend + else: fmWrite + var cfg = newFileStream(configFilePath, mode) + proc switch(key, val: string) = + cfg.writeLine("switch(", key.escape, ",", val.escape, ")") + switch("backend", nf.getNimbleValue("backend", "c")) + switch("nimcache", getEnv("NIX_BUILD_TOP", ".") / "nimcache") + if getEnvBool("nimRelease", true): + switch("define", "release") + for def in getEnv("nimDefines").split: + if def != "": + switch("define", def) + for input in getEnv("buildInputs").split: + if input != "": + for nimbleFile in walkFiles(input / "*.nimble"): + let inputSrc = normalizedPath( + input / nimbleFile.getNimbleValue("srcDir", ".")) + echo "found nimble input ", inputSrc + switch("path", inputSrc) + close(cfg) + +proc buildPhase*() = + ## Build the programs listed in the Nimble file and + ## optionally some documentation. + var cmds: seq[string] + proc before(idx: int) = + echo "build job ", idx, ": ", cmds[idx] + let + nf = getNimbleFilePath() + bins = nf.getNimbleValues("bin") + srcDir = nf.getNimbleValue("srcDir", ".") + binDir = getenv("outputBin", getenv("out", "/dev/null")) / "bin" + if bins != @[]: + for bin in bins: + cmds.add("nim compile $# --outdir:$# $#" % + [getenv"nimFlags", binDir, normalizedPath(srcDir / bin)]) + if getEnvBool"nimDoc": + echo "generating documentation" + let docDir = getenv("outputDoc", (getenv("out", "/dev/null") / "doc")) + for path in walkFiles(srcDir / "*.nim"): + cmds.add("nim doc --outdir:$# $#" % [docDir, path]) + if cmds.len > 0: + let err = execProcesses( + cmds, n = 1, + beforeRunEvent = before) + if err != 0: quit("build phase failed", err) + +proc installPhase*() = + ## Install the Nim sources if ``nimBinOnly`` is not + ## set in the environment. + if not getEnvBool"nimBinOnly": + let + nf = getNimbleFilePath() + srcDir = nf.getNimbleValue("srcDir", ".") + devDir = getenv("outputDev", getenv("out", "/dev/null")) + echo "Install ", srcDir, " to ", devDir + copyDir(normalizedPath(srcDir), normalizedPath(devDir / srcDir)) + copyFile(nf, devDir / nf.extractFilename) + +proc checkPhase*() = + ## Build and run the tests in ``tests``. + var cmds: seq[string] + proc before(idx: int) = + echo "check job ", idx, ": ", cmds[idx] + for path in walkPattern("tests/t*.nim"): + cmds.add("nim r $#" % [path]) + let err = execProcesses( + cmds, n = 1, + beforeRunEvent = before) + if err != 0: quit("check phase failed", err) + +when isMainModule: + import std/parseopt + var phase: string + + for kind, key, val in getopt(): + case kind + of cmdLongOption: + case key.toLowerAscii + of "phase": + if phase != "": quit("only a single phase may be specified") + phase = val + else: quit("unhandled argument " & key) + of cmdEnd: discard + else: quit("unhandled argument " & key) + + case phase + of "configure": configurePhase() + of "build": buildPhase() + of "install": installPhase() + of "check": checkPhase() + else: quit("unhandled phase " & phase) diff --git a/pkgs/development/nim-packages/nimbox/default.nix b/pkgs/development/nim-packages/nimbox/default.nix new file mode 100644 index 0000000000000..53663c6428105 --- /dev/null +++ b/pkgs/development/nim-packages/nimbox/default.nix @@ -0,0 +1,8 @@ +{ fetchFromGitHub }: + +fetchFromGitHub { + owner = "dom96"; + repo = "nimbox"; + rev = "6a56e76c01481176f16ae29b7d7c526bd83f229b"; + sha256 = "15x1sdfxa1xcqnr68705jfnlv83lm0xnp2z9iz3pgc4bz5vwn4x1"; +} diff --git a/pkgs/development/nim-packages/nimcrypto/default.nix b/pkgs/development/nim-packages/nimcrypto/default.nix new file mode 100644 index 0000000000000..6c212ef45f1a6 --- /dev/null +++ b/pkgs/development/nim-packages/nimcrypto/default.nix @@ -0,0 +1,8 @@ +{ fetchFromGitHub }: + +fetchFromGitHub { + owner = "cheatfate"; + repo = "nimcrypto"; + rev = "a5742a9a214ac33f91615f3862c7b099aec43b00"; + sha256 = "0al0jsaicm8vyr63n909dq1glhvpra1n9sllmj0r7lsjsdb59wsz"; +} diff --git a/pkgs/development/nim-packages/nimsimd/default.nix b/pkgs/development/nim-packages/nimsimd/default.nix new file mode 100644 index 0000000000000..9ccd96453572c --- /dev/null +++ b/pkgs/development/nim-packages/nimsimd/default.nix @@ -0,0 +1,7 @@ +{ fetchNimble }: + +fetchNimble { + pname = "nimsimd"; + version = "1.0.0"; + hash = "sha256-kp61fylAJ6MSN9hLYLi7CU2lxVR/lbrNCvZTe0LJLGo="; +} diff --git a/pkgs/development/nim-packages/noise/default.nix b/pkgs/development/nim-packages/noise/default.nix new file mode 100644 index 0000000000000..7931467dbbd5a --- /dev/null +++ b/pkgs/development/nim-packages/noise/default.nix @@ -0,0 +1,8 @@ +{ fetchFromGitHub }: + +fetchFromGitHub { + owner = "jangko"; + repo = "nim-noise"; + rev = "v0.1.14"; + sha256 = "0wndiphznfyb1pac6zysi3bqljwlfwj6ziarcwnpf00sw2zni449"; +} diff --git a/pkgs/development/nim-packages/packedjson/default.nix b/pkgs/development/nim-packages/packedjson/default.nix new file mode 100644 index 0000000000000..9edad962d589b --- /dev/null +++ b/pkgs/development/nim-packages/packedjson/default.nix @@ -0,0 +1,8 @@ +{ fetchFromGitHub }: + +fetchFromGitHub { + owner = "Araq"; + repo = "packedjson"; + rev = "7198cc8"; + sha256 = "1ay2zd88q8hvpvigsg8h0y5vc65hk3lk0d48fy9hwg4lcng19mp1"; +} diff --git a/pkgs/development/nim-packages/pixie/default.nix b/pkgs/development/nim-packages/pixie/default.nix new file mode 100644 index 0000000000000..2262ccf23721b --- /dev/null +++ b/pkgs/development/nim-packages/pixie/default.nix @@ -0,0 +1,7 @@ +{ fetchNimble }: + +fetchNimble { + pname = "pixie"; + version = "1.1.3"; + hash = "sha256-xKIejVxOd19mblL1ZwpJH91dgKQS5g8U08EL8lGGelA="; +} diff --git a/pkgs/development/nim-packages/redis/default.nix b/pkgs/development/nim-packages/redis/default.nix new file mode 100644 index 0000000000000..1768bf1976f52 --- /dev/null +++ b/pkgs/development/nim-packages/redis/default.nix @@ -0,0 +1,8 @@ +{ fetchFromGitHub }: + +fetchFromGitHub { + owner = "zedeus"; + repo = "redis"; + rev = "94bcbf1"; + sha256 = "1p9zv4f4lqrjqa8fk98cb89b9fzlf866jc584ll9sws14904i80j"; +} diff --git a/pkgs/development/nim-packages/redpool/default.nix b/pkgs/development/nim-packages/redpool/default.nix new file mode 100644 index 0000000000000..ef14854b32dcb --- /dev/null +++ b/pkgs/development/nim-packages/redpool/default.nix @@ -0,0 +1,8 @@ +{ fetchFromGitHub }: + +fetchFromGitHub { + owner = "zedeus"; + repo = "redpool"; + rev = "57aeb25"; + sha256 = "0fph7qlia6fvya1zqzbgvww2hk5pd0vq1wlf9ij9jyn655mg0w3q"; +} diff --git a/pkgs/development/nim-packages/regex/default.nix b/pkgs/development/nim-packages/regex/default.nix new file mode 100644 index 0000000000000..d89fbdd605387 --- /dev/null +++ b/pkgs/development/nim-packages/regex/default.nix @@ -0,0 +1,8 @@ +{ fetchFromGitHub }: + +fetchFromGitHub { + owner = "nitely"; + repo = "nim-regex"; + rev = "2e32fdc"; + sha256 = "1hrl40mwql7nh4wc7sdhmk8bj5728b93v5a93j49v660l0rn4qx8"; +} diff --git a/pkgs/development/nim-packages/sass/default.nix b/pkgs/development/nim-packages/sass/default.nix new file mode 100644 index 0000000000000..79885ed9ec5a6 --- /dev/null +++ b/pkgs/development/nim-packages/sass/default.nix @@ -0,0 +1,13 @@ +{ buildNimPackage, fetchFromGitHub, libsass }: + +buildNimPackage rec { + pname = "sass"; + version = "e683aa1"; + src = fetchFromGitHub { + owner = "dom96"; + repo = pname; + rev = version; + sha256 = "0qvly5rilsqqsyvr67pqhglm55ndc4nd6v90jwswbnigxiqf79lc"; + }; + propagatedBuildInputs = [ libsass ]; +} diff --git a/pkgs/development/nim-packages/sdl2/default.nix b/pkgs/development/nim-packages/sdl2/default.nix new file mode 100644 index 0000000000000..ddcdf072c6b4f --- /dev/null +++ b/pkgs/development/nim-packages/sdl2/default.nix @@ -0,0 +1,17 @@ +{ lib, buildNimPackage, fetchNimble, SDL2 }: + +buildNimPackage rec { + pname = "sdl2"; + version = "2.0.4"; + src = fetchNimble { + inherit pname version; + hash = "sha256-Vtcj8goI4zZPQs2TbFoBFlcR5UqDtOldaXSH/+/xULk="; + }; + propagatedBuildInputs = [ SDL2 ]; + doCheck = true; + meta = { + description = "Nim wrapper for SDL 2.x"; + platforms = lib.platforms.linux; # Problems with Darwin. + license = [ lib.licenses.mit ]; + }; +} diff --git a/pkgs/development/nim-packages/segmentation/default.nix b/pkgs/development/nim-packages/segmentation/default.nix new file mode 100644 index 0000000000000..c695cd00ca92b --- /dev/null +++ b/pkgs/development/nim-packages/segmentation/default.nix @@ -0,0 +1,8 @@ +{ fetchFromGitHub }: + +fetchFromGitHub { + owner = "nitely"; + repo = "nim-segmentation"; + rev = "v0.1.0"; + sha256 = "007bkx8dwy8n340zbp6wyqfsq9bh6q5ykav1ywdlwykyp1n909bh"; +} diff --git a/pkgs/development/nim-packages/supersnappy/default.nix b/pkgs/development/nim-packages/supersnappy/default.nix new file mode 100644 index 0000000000000..471543eca4115 --- /dev/null +++ b/pkgs/development/nim-packages/supersnappy/default.nix @@ -0,0 +1,8 @@ +{ fetchFromGitHub }: + +fetchFromGitHub { + owner = "guzba"; + repo = "supersnappy"; + rev = "1.1.5"; + sha256 = "1y26sgnszvdf5sn7j0jx2dpd4i03mvbk9i9ni9kbyrs798bjwi6z"; +} diff --git a/pkgs/development/nim-packages/typography/default.nix b/pkgs/development/nim-packages/typography/default.nix new file mode 100644 index 0000000000000..59037cbd9dd33 --- /dev/null +++ b/pkgs/development/nim-packages/typography/default.nix @@ -0,0 +1,7 @@ +{ fetchNimble }: + +fetchNimble { + pname = "typography"; + version = "0.7.9"; + hash = "sha256-IYjw3PCp5XzVed2fGGCt9Hb60cxFeF0BUZ7L5PedTLU="; +} diff --git a/pkgs/development/nim-packages/unicodedb/default.nix b/pkgs/development/nim-packages/unicodedb/default.nix new file mode 100644 index 0000000000000..8b60710e82106 --- /dev/null +++ b/pkgs/development/nim-packages/unicodedb/default.nix @@ -0,0 +1,8 @@ +{ fetchFromGitHub }: + +fetchFromGitHub { + owner = "nitely"; + repo = "nim-unicodedb"; + rev = "v0.9.0"; + sha256 = "06j8d0bjbpv1iibqlmrac4qb61ggv17hvh6nv4pbccqk1rlpxhsq"; +} diff --git a/pkgs/development/nim-packages/unicodeplus/default.nix b/pkgs/development/nim-packages/unicodeplus/default.nix new file mode 100644 index 0000000000000..772524eaf94b5 --- /dev/null +++ b/pkgs/development/nim-packages/unicodeplus/default.nix @@ -0,0 +1,8 @@ +{ fetchFromGitHub }: + +fetchFromGitHub { + owner = "nitely"; + repo = "nim-unicodeplus"; + rev = "v0.8.0"; + sha256 = "181wzwivfgplkqn5r4crhnaqgsza7x6fi23i86djb2dxvm7v6qxk"; +} diff --git a/pkgs/development/nim-packages/vmath/default.nix b/pkgs/development/nim-packages/vmath/default.nix new file mode 100644 index 0000000000000..9ca48c43d7f4f --- /dev/null +++ b/pkgs/development/nim-packages/vmath/default.nix @@ -0,0 +1,7 @@ +{ fetchNimble }: + +fetchNimble { + pname = "vmath"; + version = "1.0.3"; + hash = "sha256-zzSKXjuTZ46HTFUs0N47mxEKTKIdS3dwr+60sQYSdn0="; +} diff --git a/pkgs/development/nim-packages/zippy/default.nix b/pkgs/development/nim-packages/zippy/default.nix new file mode 100644 index 0000000000000..230892b688992 --- /dev/null +++ b/pkgs/development/nim-packages/zippy/default.nix @@ -0,0 +1,7 @@ +{ fetchNimble }: + +fetchNimble { + pname = "zippy"; + version = "0.5.6"; + hash = "sha256-axp4t9+8TFSpvnATlRKZyuOGLA0e/XKfvrVSwreXpC4="; +} diff --git a/pkgs/development/tools/misc/nimlsp/default.nix b/pkgs/development/tools/misc/nimlsp/default.nix index b1d59c9450acc..0e837b8fd614d 100644 --- a/pkgs/development/tools/misc/nimlsp/default.nix +++ b/pkgs/development/tools/misc/nimlsp/default.nix @@ -1,22 +1,9 @@ -{ lib, stdenv, fetchFromGitHub, srcOnly, nim }: -let - astpatternmatching = fetchFromGitHub { - owner = "krux02"; - repo = "ast-pattern-matching"; - rev = "87f7d163421af5a4f5e5cb6da7b93278e6897e96"; - sha256 = "19mb5bb6riia8380p5dpc3q0vwgrj958dd6p7vw8vkvwiqrzg6zq"; - }; +{ lib, nimPackages, fetchFromGitHub, srcOnly, nim }: - jsonschema = fetchFromGitHub { - owner = "PMunch"; - repo = "jsonschema"; - rev = "7b41c03e3e1a487d5a8f6b940ca8e764dc2cbabf"; - sha256 = "1js64jqd854yjladxvnylij4rsz7212k31ks541pqrdzm6hpblbz"; - }; -in -stdenv.mkDerivation rec { +nimPackages.buildNimPackage rec { pname = "nimlsp"; version = "0.3.2"; + nimBinOnly = true; src = fetchFromGitHub { owner = "PMunch"; @@ -25,18 +12,15 @@ stdenv.mkDerivation rec { sha256 = "1lm823nvpp3bj9527jd8n1jxh6y8p8ngkfkj91p94m7ffai6jazq"; }; - nativeBuildInputs = [ nim ]; + buildInputs = with nimPackages; [ astpatternmatching jsonschema ]; - buildPhase = '' - export HOME=$TMPDIR - nim -d:release -p:${astpatternmatching}/src -p:${jsonschema}/src \ - c --threads:on -d:nimcore -d:nimsuggest -d:debugCommunication \ - -d:debugLogging -d:explicitSourcePath=${srcOnly nim.passthru.nim} -d:tempDir=/tmp src/nimlsp - ''; + nimFlags = [ + "--threads:on" + "-d:explicitSourcePath=${srcOnly nimPackages.nim.passthru.nim}" + "-d:tempDir=/tmp" + ]; - installPhase = '' - install -Dt $out/bin src/nimlsp - ''; + nimDefines = [ "nimcore" "nimsuggest" "debugCommunication" "debugLogging" ]; meta = with lib; { description = "Language Server Protocol implementation for Nim"; diff --git a/pkgs/development/tools/nrpl/default.nix b/pkgs/development/tools/nrpl/default.nix index 67a86ca8dec59..84147faf74e5a 100644 --- a/pkgs/development/tools/nrpl/default.nix +++ b/pkgs/development/tools/nrpl/default.nix @@ -1,8 +1,9 @@ -{ stdenv, lib, fetchFromGitHub, fetchpatch, makeWrapper, nim, pcre, tinycc }: +{ lib, nimPackages, fetchFromGitHub, fetchpatch, makeWrapper, pcre, tinycc }: -stdenv.mkDerivation { +nimPackages.buildNimPackage { pname = "nrpl"; version = "20150522"; + nimBinOnly = true; src = fetchFromGitHub { owner = "wheineman"; @@ -12,7 +13,7 @@ stdenv.mkDerivation { }; nativeBuildInputs = [ makeWrapper ]; - buildInputs = [ nim pcre ]; + buildInputs = [ pcre ]; patches = [ (fetchpatch { @@ -24,16 +25,9 @@ stdenv.mkDerivation { NIX_LDFLAGS = "-lpcre"; - buildPhase = '' - HOME=$TMPDIR - nim c -d:release nrpl.nim - ''; - - installPhase = "install -Dt $out/bin nrpl"; - postFixup = '' wrapProgram $out/bin/nrpl \ - --prefix PATH : ${lib.makeBinPath [ nim tinycc ]} + --prefix PATH : ${lib.makeBinPath [ nimPackages.nim tinycc ]} ''; meta = with lib; { |