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-08-23 10:09:14 +0000
committerAlyssa Ross <hi@alyssa.is>2023-08-26 09:07:03 +0000
commit63dabcc77ef9a56655e1ca2ab2e25e6163a72c1f (patch)
treed58934cb48f9c953b19a0d0d5cffc0d0c5561471 /nixpkgs/pkgs/development/compilers/nim
parentc4eef3dacb2a3d359561f30917d9e3cc4e041be9 (diff)
parent91a22f76cd1716f9d0149e8a5c68424bb691de15 (diff)
downloadnixlib-63dabcc77ef9a56655e1ca2ab2e25e6163a72c1f.tar
nixlib-63dabcc77ef9a56655e1ca2ab2e25e6163a72c1f.tar.gz
nixlib-63dabcc77ef9a56655e1ca2ab2e25e6163a72c1f.tar.bz2
nixlib-63dabcc77ef9a56655e1ca2ab2e25e6163a72c1f.tar.lz
nixlib-63dabcc77ef9a56655e1ca2ab2e25e6163a72c1f.tar.xz
nixlib-63dabcc77ef9a56655e1ca2ab2e25e6163a72c1f.tar.zst
nixlib-63dabcc77ef9a56655e1ca2ab2e25e6163a72c1f.zip
Merge branch 'nixos-unstable' of https://github.com/NixOS/nixpkgs
Conflicts:
	nixpkgs/pkgs/build-support/go/module.nix
	nixpkgs/pkgs/development/python-modules/django-mailman3/default.nix
Diffstat (limited to 'nixpkgs/pkgs/development/compilers/nim')
-rw-r--r--nixpkgs/pkgs/development/compilers/nim/default.nix332
-rw-r--r--nixpkgs/pkgs/development/compilers/nim/nim2.cfg.patch41
2 files changed, 221 insertions, 152 deletions
diff --git a/nixpkgs/pkgs/development/compilers/nim/default.nix b/nixpkgs/pkgs/development/compilers/nim/default.nix
index 131a27b6f544..f18671242130 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, nim-unwrapped
-, nimble-unwrapped, Security }:
+, makeWrapper, openssl, pcre, readline, boehmgc, sqlite, Security, nim-unwrapped
+, nim-unwrapped-2, nimble-unwrapped, nim }:
 
 let
   parseCpu = platform:
@@ -72,25 +72,15 @@ let
   nimHost = parsePlatform stdenv.hostPlatform;
   nimTarget = parsePlatform stdenv.targetPlatform;
 
-  bootstrapCompiler = stdenv.mkDerivation {
-    pname = "nim-bootstrap";
-    inherit (nim-unwrapped) version src preBuild;
-    enableParallelBuilding = true;
-    installPhase = ''
-      runHook preInstall
-      install -Dt $out/bin bin/nim
-      runHook postInstall
-    '';
-  };
 in {
 
-  nim-unwrapped = stdenv.mkDerivation rec {
+  nim-unwrapped = stdenv.mkDerivation (finalAttrs: {
     pname = "nim-unwrapped";
     version = "1.6.14";
     strictDeps = true;
 
     src = fetchurl {
-      url = "https://nim-lang.org/download/nim-${version}.tar.xz";
+      url = "https://nim-lang.org/download/nim-${finalAttrs.version}.tar.xz";
       hash = "sha256-0HDS8oriQA33/kpJ7OufRc1TmQaxB0gYVqCveo+oLck=";
     };
 
@@ -108,7 +98,18 @@ in {
       # Mangle store paths of modules to prevent runtime dependence.
     ] ++ lib.optional (!stdenv.hostPlatform.isWindows) ./toLocation.patch;
 
-    configurePhase = ''
+    configurePhase = let
+      bootstrapCompiler = stdenv.mkDerivation {
+        pname = "nim-bootstrap";
+        inherit (finalAttrs) version src preBuild;
+        enableParallelBuilding = true;
+        installPhase = ''
+          runHook preInstall
+          install -Dt $out/bin bin/nim
+          runHook postInstall
+        '';
+      };
+    in ''
       runHook preConfigure
       cp ${bootstrapCompiler}/bin/nim bin/
       echo 'define:nixbuild' >> config/nim.cfg
@@ -154,7 +155,25 @@ in {
       mainProgram = "nim";
       maintainers = with maintainers; [ ehmry ];
     };
-  };
+  });
+
+  nim-unwrapped-2 = nim-unwrapped.overrideAttrs (finalAttrs: rec {
+    version = "2.0.0";
+    src = fetchurl {
+      url = "https://nim-lang.org/download/nim-${version}.tar.xz";
+      hash = "sha256-vWEB2EADb7eOk6ad9s8/n9DCHNdUtpX/hKO0rdjtCvc=";
+    };
+    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.
+    ];
+  });
 
   nimble-unwrapped = stdenv.mkDerivation rec {
     pname = "nimble-unwrapped";
@@ -169,8 +188,7 @@ in {
     };
 
     depsBuildBuild = [ nim-unwrapped ];
-    buildInputs = [ openssl ]
-      ++ lib.optional stdenv.isDarwin Security;
+    buildInputs = [ openssl ] ++ lib.optional stdenv.isDarwin Security;
 
     nimFlags = [ "--cpu:${nimHost.cpu}" "--os:${nimHost.os}" "-d:release" ];
 
@@ -194,147 +212,157 @@ in {
       mainProgram = "nimble";
     };
   };
-
-  nim = let
-    nim' = buildPackages.nim-unwrapped;
-    nimble' = buildPackages.nimble-unwrapped;
-    inherit (stdenv) targetPlatform;
-    self = stdenv.mkDerivation {
-      name = "${targetPlatform.config}-nim-wrapper-${nim'.version}";
-      inherit (nim') version;
-      preferLocalBuild = true;
-      strictDeps = true;
-
-      nativeBuildInputs = [ makeWrapper ];
-
-      # Needed for any nim package that uses the standard library's
-      # 'std/sysrand' module.
-      depsTargetTargetPropagated = lib.optional stdenv.isDarwin Security;
-
-      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
+} // (let
+  wrapNim = { nim', nimble', patches }:
+    let
+      targetPlatformConfig = stdenv.targetPlatform.config;
+      self = stdenv.mkDerivation (finalAttrs: {
+        name = "${targetPlatformConfig}-nim-wrapper-${nim'.version}";
+        inherit (nim') version;
+        preferLocalBuild = true;
+        strictDeps = true;
+
+        nativeBuildInputs = [ makeWrapper ];
+
+        # Needed for any nim package that uses the standard library's
+        # 'std/sysrand' module.
+        depsTargetTargetPropagated = lib.optional stdenv.isDarwin Security;
+
+        inherit patches;
+
+        unpackPhase = ''
+          runHook preUnpack
+          tar xf ${nim'.src} nim-$version/config
+          cd nim-$version
+          runHook postUnpack
         '';
 
-      wrapperArgs = lib.optionals (!(stdenv.isDarwin && stdenv.isAarch64)) [
-        "--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
-      ];
+        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 = lib.optionals (!(stdenv.isDarwin && stdenv.isAarch64)) [
+          "--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
+        ];
+
+        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/${targetPlatformConfig}-$binname \
+              $wrapperArgs
+            ln -s $out/bin/${targetPlatformConfig}-$binname $out/bin/$binname
+          done
 
-      installPhase = ''
-        runHook preInstall
-
-        mkdir -p $out/bin $out/etc
-
-        cp -r config $out/etc/nim
+          makeWrapper \
+            ${nim'}/nim/bin/nim $out/bin/${targetPlatformConfig}-nim \
+            --set-default CC $(command -v $CC) \
+            --set-default CXX $(command -v $CXX) \
+            $wrapperArgs
+          ln -s $out/bin/${targetPlatformConfig}-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/${targetPlatformConfig}-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
-
-        runHook postInstall
-      '';
-
-      passthru = {
-        nim = nim';
-        nimble = nimble';
-      };
+          ln -s $out/bin/${targetPlatformConfig}-testament $out/bin/testament
 
-      meta = nim'.meta // {
-        description = nim'.meta.description
-          + " (${targetPlatform.config} wrapper)";
-        platforms = with lib.platforms; unix ++ genode;
-      };
+        '' + lib.strings.optionalString (nimble' != null) ''
+          makeWrapper \
+            ${nimble'}/bin/nimble $out/bin/${targetPlatformConfig}-nimble \
+            --suffix PATH : $out/bin
+          ln -s $out/bin/${targetPlatformConfig}-nimble $out/bin/nimble
+
+        '' + ''
+          runHook postInstall
+        '';
+
+        passthru = {
+          nim = nim';
+          nimble = nimble';
+        };
+
+        meta = nim'.meta // {
+          description = nim'.meta.description
+            + " (${targetPlatformConfig} wrapper)";
+          platforms = with lib.platforms; unix ++ genode;
+        };
+      });
+    in self // {
+      pkgs = callPackage ../../../top-level/nim-packages.nix { nim = self; };
     };
-  in self // {
-    pkgs = callPackage ../../../top-level/nim-packages.nix { nim = self; };
+in {
+
+  nim = wrapNim {
+    nim' = buildPackages.nim-unwrapped;
+    nimble' = buildPackages.nimble-unwrapped;
+    patches = [ ./nim.cfg.patch ];
   };
 
-}
+  nim2 = wrapNim {
+    nim' = buildPackages.nim-unwrapped-2;
+    nimble' = null;
+    patches = [ ./nim2.cfg.patch ];
+  };
+})
diff --git a/nixpkgs/pkgs/development/compilers/nim/nim2.cfg.patch b/nixpkgs/pkgs/development/compilers/nim/nim2.cfg.patch
new file mode 100644
index 000000000000..ef23d3a84623
--- /dev/null
+++ b/nixpkgs/pkgs/development/compilers/nim/nim2.cfg.patch
@@ -0,0 +1,41 @@
+diff --git a/config/nim.cfg b/config/nim.cfg
+index 1470de780..8a12f741a 100644
+--- a/config/nim.cfg
++++ b/config/nim.cfg
+@@ -9,8 +9,6 @@
+ # Environment variables can be accessed like so:
+ #  gcc.path %= "$CC_PATH"
+
+-cc = gcc
+-
+ # additional options always passed to the compiler:
+ --parallel_build: "0" # 0 to auto-detect number of processors
+
+@@ -22,27 +20,6 @@ cc = gcc
+
+ threads:on
+
+-# Examples of how to setup a cross-compiler:
+-# Nim can target architectures and OSes different than the local host
+-# Syntax: <arch>.<os>.gcc.exe = "<compiler executable>"
+-#         <arch>.<os>.gcc.linkerexe = "<linker executable>"
+-
+-# ARM e.g. Raspberry Pi 2: gcc-arm-linux-gnueabihf package on Debian/Ubuntu
+-arm.linux.gcc.exe = "arm-linux-gnueabihf-gcc"
+-arm.linux.gcc.linkerexe = "arm-linux-gnueabihf-gcc"
+-# ARM64/aarch64 e.g. Raspberry Pi 3: gcc-aarch64-linux-gnu package on Debian/Ubuntu
+-arm64.linux.gcc.exe = "aarch64-linux-gnu-gcc"
+-arm64.linux.gcc.linkerexe = "aarch64-linux-gnu-gcc"
+-# RISC-V: gcc-riscv64-linux-gnu package on Debian/Ubuntu
+-riscv32.linux.gcc.exe = "riscv64-linux-gnu-gcc"
+-riscv32.linux.gcc.linkerexe = "riscv64-linux-gnu-gcc"
+-riscv64.linux.gcc.exe = "riscv64-linux-gnu-gcc"
+-riscv64.linux.gcc.linkerexe = "riscv64-linux-gnu-gcc"
+-
+-# For OpenWRT, you will also need to adjust PATH to point to your toolchain.
+-mips.linux.gcc.exe = "mips-openwrt-linux-gcc"
+-mips.linux.gcc.linkerexe = "mips-openwrt-linux-gcc"
+-
+
+ path="$lib/deprecated/core"
+ path="$lib/deprecated/pure"