about summary refs log tree commit diff
path: root/nixpkgs/pkgs/development/compilers/nim
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2023-12-01 19:00:09 +0100
committerAlyssa Ross <hi@alyssa.is>2023-12-01 19:00:09 +0100
commit9e9b07490d5bab5d115c66b80bdb10ff0c11ed8d (patch)
tree4368f9e4cb2d5b93a956c085337e45cb70f1e331 /nixpkgs/pkgs/development/compilers/nim
parenta9cbfb6941b47d6f50129e6e36927882392daed7 (diff)
parent2344fe1da14cb08b0c18743b207995f9b8597915 (diff)
downloadnixlib-9e9b07490d5bab5d115c66b80bdb10ff0c11ed8d.tar
nixlib-9e9b07490d5bab5d115c66b80bdb10ff0c11ed8d.tar.gz
nixlib-9e9b07490d5bab5d115c66b80bdb10ff0c11ed8d.tar.bz2
nixlib-9e9b07490d5bab5d115c66b80bdb10ff0c11ed8d.tar.lz
nixlib-9e9b07490d5bab5d115c66b80bdb10ff0c11ed8d.tar.xz
nixlib-9e9b07490d5bab5d115c66b80bdb10ff0c11ed8d.tar.zst
nixlib-9e9b07490d5bab5d115c66b80bdb10ff0c11ed8d.zip
Merge https://github.com/NixOS/nixpkgs
Diffstat (limited to 'nixpkgs/pkgs/development/compilers/nim')
-rw-r--r--nixpkgs/pkgs/development/compilers/nim/build-nim-package.nix114
-rw-r--r--nixpkgs/pkgs/development/compilers/nim/default.nix46
2 files changed, 135 insertions, 25 deletions
diff --git a/nixpkgs/pkgs/development/compilers/nim/build-nim-package.nix b/nixpkgs/pkgs/development/compilers/nim/build-nim-package.nix
new file mode 100644
index 000000000000..5085edf90a76
--- /dev/null
+++ b/nixpkgs/pkgs/development/compilers/nim/build-nim-package.nix
@@ -0,0 +1,114 @@
+{ lib
+, buildPackages
+, callPackage
+, stdenv
+, nim1
+, nim2
+, nim_builder
+, defaultNimVersion ? 2
+, nimOverrides
+}:
+
+let
+  baseAttrs = {
+    strictDeps = true;
+    enableParallelBuilding = true;
+    doCheck = true;
+    configurePhase = ''
+      runHook preConfigure
+      export NIX_NIM_BUILD_INPUTS=''${pkgsHostTarget[@]} $NIX_NIM_BUILD_INPUTS
+      nim_builder --phase:configure
+      runHook postConfigure
+    '';
+    buildPhase = ''
+      runHook preBuild
+      nim_builder --phase:build
+      runHook postBuild
+    '';
+    checkPhase = ''
+      runHook preCheck
+      nim_builder --phase:check
+      runHook postCheck
+    '';
+    installPhase = ''
+      runHook preInstall
+      nim_builder --phase:install
+      runHook postInstall
+    '';
+    meta = { inherit (nim2.meta) maintainers platforms; };
+  };
+
+  fodFromLockEntry =
+    let
+      methods = {
+        fetchzip = { url, sha256, ... }:
+          buildPackages.fetchzip {
+            name = "source";
+            inherit url sha256;
+          };
+        git = { fetchSubmodules, leaveDotGit, rev, sha256, url, ... }:
+          buildPackages.fetchgit {
+            inherit fetchSubmodules leaveDotGit rev sha256 url;
+          };
+      };
+    in
+    attrs@{ method, ... }:
+    let fod = methods.${method} attrs;
+    in ''--path:"${fod.outPath}/${attrs.srcDir}"'';
+
+  callAnnotations = { packages, ... }@lockAttrs:
+    map (packageName: nimOverrides.${packageName} or (_: [ ]) lockAttrs)
+      packages;
+
+  asFunc = x: if builtins.isFunction x then x else (_: x);
+
+in
+buildNimPackageArgs:
+let
+  composition = finalAttrs:
+    let
+      postPkg = baseAttrs
+        // (asFunc ((asFunc buildNimPackageArgs) finalAttrs)) baseAttrs;
+
+      lockAttrs =
+        lib.attrsets.optionalAttrs (builtins.hasAttr "lockFile" postPkg)
+          (builtins.fromJSON (builtins.readFile postPkg.lockFile));
+
+      lockDepends = lockAttrs.depends or [ ];
+
+      lockFileNimFlags = map fodFromLockEntry lockDepends;
+
+      annotationOverlays = lib.lists.flatten (map callAnnotations lockDepends);
+
+      postLock = builtins.foldl'
+        (prevAttrs: overlay: prevAttrs // (overlay finalAttrs prevAttrs))
+        postPkg
+        annotationOverlays;
+
+      finalOverride =
+        { depsBuildBuild ? [ ]
+        , nativeBuildInputs ? [ ]
+        , nimFlags ? [ ]
+        , requiredNimVersion ? defaultNimVersion
+        , ...
+        }:
+        (if requiredNimVersion == 1 then {
+          depsBuildBuild = [ nim_builder ] ++ depsBuildBuild;
+          nativeBuildInputs = [ nim1 ] ++ nativeBuildInputs;
+        } else if requiredNimVersion == 2 then {
+          depsBuildBuild = [ nim_builder ] ++ depsBuildBuild;
+          nativeBuildInputs = [ nim2 ] ++ nativeBuildInputs;
+        } else
+          throw
+            "requiredNimVersion ${toString requiredNimVersion} is not valid") // {
+          nimFlags = lockFileNimFlags ++ nimFlags;
+        };
+
+      attrs = postLock // finalOverride postLock;
+    in
+    lib.trivial.warnIf (builtins.hasAttr "nimBinOnly" attrs)
+      "the nimBinOnly attribute is deprecated for buildNimPackage"
+      attrs;
+
+in
+stdenv.mkDerivation composition
diff --git a/nixpkgs/pkgs/development/compilers/nim/default.nix b/nixpkgs/pkgs/development/compilers/nim/default.nix
index f0ffa4309f9f..425eda585c27 100644
--- a/nixpkgs/pkgs/development/compilers/nim/default.nix
+++ b/nixpkgs/pkgs/development/compilers/nim/default.nix
@@ -2,8 +2,8 @@
 # https://nim-lang.org/docs/nimc.html
 
 { lib, callPackage, buildPackages, stdenv, fetchurl, fetchgit, fetchFromGitHub
-, makeWrapper, openssl, pcre, readline, boehmgc, sqlite, Security, nim-unwrapped
-, nim-unwrapped-2, nim }:
+, makeWrapper, openssl, pcre, readline, boehmgc, sqlite, Security
+, nim-unwrapped-2, nim-unwrapped-1, nim }:
 
 let
   parseCpu = platform:
@@ -74,14 +74,14 @@ let
 
 in {
 
-  nim-unwrapped = stdenv.mkDerivation (finalAttrs: {
+  nim-unwrapped-2 = stdenv.mkDerivation (finalAttrs: {
     pname = "nim-unwrapped";
-    version = "1.6.14";
+    version = "2.0.0";
     strictDeps = true;
 
     src = fetchurl {
       url = "https://nim-lang.org/download/nim-${finalAttrs.version}.tar.xz";
-      hash = "sha256-0HDS8oriQA33/kpJ7OufRc1TmQaxB0gYVqCveo+oLck=";
+      hash = "sha256-vWEB2EADb7eOk6ad9s8/n9DCHNdUtpX/hKO0rdjtCvc=";
     };
 
     buildInputs = [ boehmgc openssl pcre readline sqlite ]
@@ -96,7 +96,10 @@ in {
 
       ./extra-mangling.patch
       # Mangle store paths of modules to prevent runtime dependence.
-    ] ++ lib.optional (!stdenv.hostPlatform.isWindows) ./toLocation.patch;
+
+      ./openssl.patch
+      # dlopen is widely used by Python, Ruby, Perl, ... what you're really telling me here is that your OS is fundamentally broken. That might be news for you, but it isn't for me.
+    ];
 
     configurePhase = let
       bootstrapCompiler = stdenv.mkDerivation {
@@ -157,11 +160,11 @@ in {
     };
   });
 
-  nim-unwrapped-2 = nim-unwrapped.overrideAttrs (finalAttrs: rec {
-    version = "2.0.0";
+  nim-unwrapped-1 = nim-unwrapped-2.overrideAttrs (finalAttrs: prevAttrs: {
+    version = "1.6.14";
     src = fetchurl {
-      url = "https://nim-lang.org/download/nim-${version}.tar.xz";
-      hash = "sha256-vWEB2EADb7eOk6ad9s8/n9DCHNdUtpX/hKO0rdjtCvc=";
+      url = "https://nim-lang.org/download/nim-${finalAttrs.version}.tar.xz";
+      hash = "sha256-0HDS8oriQA33/kpJ7OufRc1TmQaxB0gYVqCveo+oLck=";
     };
 
     patches = [
@@ -173,17 +176,13 @@ in {
 
       ./extra-mangling.patch
       # Mangle store paths of modules to prevent runtime dependence.
-
-      ./openssl.patch
-      # dlopen is widely used by Python, Ruby, Perl, ... what you're really telling me here is that your OS is fundamentally broken. That might be news for you, but it isn't for me.
-    ];
+    ] ++ lib.optional (!stdenv.hostPlatform.isWindows) ./toLocation.patch;
   });
 
 } // (let
   wrapNim = { nim', patches }:
-    let
-      targetPlatformConfig = stdenv.targetPlatform.config;
-      self = stdenv.mkDerivation (finalAttrs: {
+    let targetPlatformConfig = stdenv.targetPlatform.config;
+    in stdenv.mkDerivation (finalAttrs: {
         name = "${targetPlatformConfig}-nim-wrapper-${nim'.version}";
         inherit (nim') version;
         preferLocalBuild = true;
@@ -307,19 +306,16 @@ in {
           platforms = with lib.platforms; unix ++ genode;
         };
       });
-    in self // {
-      pkgs = callPackage ../../../top-level/nim-packages.nix { nim = self; };
-    };
 in {
 
-  nim = wrapNim {
-    nim' = buildPackages.nim-unwrapped;
-    patches = [ ./nim.cfg.patch ];
-  };
-
   nim2 = wrapNim {
     nim' = buildPackages.nim-unwrapped-2;
     patches = [ ./nim2.cfg.patch ];
   };
 
+  nim1 = wrapNim {
+    nim' = buildPackages.nim-unwrapped-1;
+    patches = [ ./nim.cfg.patch ];
+  };
+
 })