nim-unwrapped-1_0: move to pkgs/by-name from nim-unwrapped-1

This commit is contained in:
Emery Hemingway 2024-10-27 18:58:44 +00:00
parent 1e1bc01db7
commit 68347d5542
7 changed files with 36 additions and 90 deletions

View File

@ -0,0 +1,30 @@
{
lib,
stdenv,
fetchurl,
nim-unwrapped-2,
}:
nim-unwrapped-2.overrideAttrs (
finalAttrs: prevAttrs: {
version = "1.6.20";
src = fetchurl {
url = "https://nim-lang.org/download/nim-${finalAttrs.version}.tar.xz";
hash = "sha256-/+0EdQTR/K9hDw3Xzz4Ce+kaKSsMnFEWFQTC87mE/7k=";
};
patches =
builtins.filter (
p:
builtins.elem (builtins.baseNameOf p) [
"NIM_CONFIG_DIR.patch"
"nixbuild.patch"
]
) nim-unwrapped-2.patches
++ [
./extra-mangling.patch
# Mangle store paths of modules to prevent runtime dependence.
]
++ lib.optional (!stdenv.hostPlatform.isWindows) ./toLocation.patch;
}
)

View File

@ -1,23 +0,0 @@
diff --git a/compiler/nimconf.nim b/compiler/nimconf.nim
index a470179bd..73cfa1a23 100644
--- a/compiler/nimconf.nim
+++ b/compiler/nimconf.nim
@@ -225,10 +225,15 @@ proc getUserConfigPath*(filename: RelativeFile): AbsoluteFile =
proc getSystemConfigPath*(conf: ConfigRef; filename: RelativeFile): AbsoluteFile =
# try standard configuration file (installation did not distribute files
# the UNIX way)
- let p = getPrefixDir(conf)
- result = p / RelativeDir"config" / filename
+ let
+ prefix = getPrefixDir(conf)
+ env = getEnv("NIM_CONFIG_PATH")
+ if env != "":
+ result = env.toAbsoluteDir / filename
+ else:
+ result = prefix / RelativeDir"config" / filename
when defined(unix):
- if not fileExists(result): result = p / RelativeDir"etc/nim" / filename
+ if not fileExists(result): result = prefix / RelativeDir"etc/nim" / filename
if not fileExists(result): result = AbsoluteDir"/etc/nim" / filename
proc loadConfigs*(cfg: RelativeFile; cache: IdentCache; conf: ConfigRef) =

View File

@ -1,34 +1,12 @@
# https://nim-lang.github.io/Nim/packaging.html
# https://nim-lang.org/docs/nimc.html
{ lib, callPackage, buildPackages, stdenv, fetchurl, fetchgit
, makeWrapper, openssl, pcre, readline, boehmgc, sqlite, Security
, nim-unwrapped-2, nim-unwrapped-1 }:
{ lib, callPackage, buildPackages, stdenv
, makeWrapper, openssl, pcre, Security
, nim-unwrapped-1 }:
let
inherit (nim-unwrapped-2.passthru) nimHost nimTarget;
in {
nim-unwrapped-1 = nim-unwrapped-2.overrideAttrs (finalAttrs: prevAttrs: {
version = "1.6.20";
src = fetchurl {
url = "https://nim-lang.org/download/nim-${finalAttrs.version}.tar.xz";
hash = "sha256-/+0EdQTR/K9hDw3Xzz4Ce+kaKSsMnFEWFQTC87mE/7k=";
};
patches = [
./NIM_CONFIG_DIR.patch
# Override compiler configuration via an environmental variable
./nixbuild.patch
# Load libraries at runtime by absolute path
./extra-mangling.patch
# Mangle store paths of modules to prevent runtime dependence.
] ++ lib.optional (!stdenv.hostPlatform.isWindows) ./toLocation.patch;
});
} // (let
inherit (nim-unwrapped-1.passthru) nimHost nimTarget;
wrapNim = { nim', patches }:
let targetPlatformConfig = stdenv.targetPlatform.config;
in stdenv.mkDerivation (finalAttrs: {
@ -162,4 +140,4 @@ in {
patches = [ ./nim.cfg.patch ];
};
})
}

View File

@ -1,40 +0,0 @@
diff --git a/lib/pure/dynlib.nim b/lib/pure/dynlib.nim
index f31ae94dd..debed9c07 100644
--- a/lib/pure/dynlib.nim
+++ b/lib/pure/dynlib.nim
@@ -56,6 +56,9 @@
import strutils
+when defined(nixbuild) and not defined(windows):
+ import os
+
type
LibHandle* = pointer ## a handle to a dynamically loaded library
@@ -95,6 +98,25 @@ proc libCandidates*(s: string, dest: var seq[string]) =
libCandidates(prefix & middle & suffix, dest)
else:
add(dest, s)
+ when defined(nixbuild) and not defined(windows):
+ # Nix doesn't have a global library directory so
+ # load libraries using an absolute path if one
+ # can be derived from NIX_LDFLAGS.
+ #
+ # During Nix/NixOS packaging the line "define:nixbuild"
+ # should be appended to the ../../config/nim.cfg file
+ # to enable this behavior by default.
+ #
+ var libDirs = split(getEnv("LD_LIBRARY_PATH"), ':')
+ for flag in split(replace(getEnv("NIX_LDFLAGS"), "\\ ", " ")):
+ if flag.startsWith("-L"):
+ libDirs.add(flag[2..flag.high])
+ for lib in dest:
+ for dir in libDirs:
+ let abs = dir / lib
+ if existsFile(abs):
+ dest = @[abs]
+ return
proc loadLibPattern*(pattern: string, globalSymbols = false): LibHandle =
## loads a library with name matching `pattern`, similar to what `dlimport`

View File

@ -15330,6 +15330,7 @@ with pkgs;
nim = nim2;
nim2 = nim-2_2;
nim-unwrapped = nim-unwrapped-2_2;
nim-unwrapped-1 = nim-unwrapped-1_0;
nim-unwrapped-2 = nim-unwrapped-2_2;
buildNimPackage = callPackage ../development/compilers/nim/build-nim-package.nix { };