about summary refs log tree commit diff
path: root/pkgs/development/compilers/crystal
diff options
context:
space:
mode:
authorPeter Hoeg <peter@hoeg.com>2020-12-22 12:08:30 +0800
committerPeter Hoeg <peter@hoeg.com>2020-12-28 16:21:23 +0800
commit61626d70e5f3fe0967542935f9be810544341b13 (patch)
treeca74a63f19f699076c542b3cf4c51b94e0abd052 /pkgs/development/compilers/crystal
parent7505046458748594dcd8cb9bf1c182a33de24d06 (diff)
buildCrystalPackage: support shards v0.12 properly
Diffstat (limited to 'pkgs/development/compilers/crystal')
-rw-r--r--pkgs/development/compilers/crystal/build-package.nix71
1 files changed, 46 insertions, 25 deletions
diff --git a/pkgs/development/compilers/crystal/build-package.nix b/pkgs/development/compilers/crystal/build-package.nix
index 856c6e58bc18e..bcac4eeb9c463 100644
--- a/pkgs/development/compilers/crystal/build-package.nix
+++ b/pkgs/development/compilers/crystal/build-package.nix
@@ -1,6 +1,7 @@
 { stdenv, lib, crystal, shards, git, pkgconfig, which, linkFarm, fetchFromGitHub, installShellFiles }:
 
-{ # Some projects do not include a lock file, so you can pass one
+{
+  # Some projects do not include a lock file, so you can pass one
   lockFile ? null
   # Generate shards.nix with `nix-shell -p crystal2nix --run crystal2nix` in the projects root
 , shardsFile ? null
@@ -10,10 +11,11 @@
 , installManPages ? true
   # Specify binaries to build in the form { foo.src = "src/foo.cr"; }
   # The default `crystal build` options can be overridden with { foo.options = [ "--no-debug" ]; }
-, crystalBinaries ? { }, ... }@args:
+, crystalBinaries ? { }
+, ...
+}@args:
 
 assert (builtins.elem format [ "make" "crystal" "shards" ]);
-
 let
   mkDerivationArgs = builtins.removeAttrs args [
     "format"
@@ -23,22 +25,34 @@ let
     "crystalBinaries"
   ];
 
-  crystalLib = linkFarm "crystal-lib" (lib.mapAttrsToList (name: value: {
-    inherit name;
-    path = fetchFromGitHub value;
-  }) (import shardsFile));
+  crystalLib = linkFarm "crystal-lib" (lib.mapAttrsToList
+    (name: value: {
+      inherit name;
+      path = fetchFromGitHub value;
+    })
+    (import shardsFile));
 
   # we previously had --no-debug here but that is not recommended by upstream
   defaultOptions = [ "--release" "--progress" "--verbose" ];
 
   buildDirectly = shardsFile == null || crystalBinaries != { };
-in stdenv.mkDerivation (mkDerivationArgs // {
 
-  configurePhase = args.configurePhase or lib.concatStringsSep "\n" ([
-    "runHook preConfigure"
-  ] ++ lib.optional (lockFile != null)   "ln -s ${lockFile} ./shard.lock"
-    ++ lib.optional (shardsFile != null) "ln -s ${crystalLib} lib"
-    ++ [ "runHook postConfigure "]);
+in
+stdenv.mkDerivation (mkDerivationArgs // {
+
+  configurePhase = args.configurePhase or lib.concatStringsSep "\n"
+    (
+      [
+        "runHook preConfigure"
+      ]
+      ++ lib.optional (lockFile != null) "cp ${lockFile} ./shard.lock"
+      ++ lib.optionals (shardsFile != null) [
+        "test -e lib || mkdir lib"
+        "for d in ${crystalLib}/*; do ln -s $d lib/; done"
+        "cp shard.lock lib/.shards.info"
+      ]
+      ++ [ "runHook postConfigure" ]
+    );
 
   CRFLAGS = lib.concatStringsSep " " defaultOptions;
 
@@ -53,24 +67,31 @@ in stdenv.mkDerivation (mkDerivationArgs // {
     "runHook preBuild"
   ] ++ lib.optional (format == "make")
     ''make ''${buildTargets:-build} $makeFlags''
-  ++ lib.optionals (format == "crystal") (lib.mapAttrsToList (bin: attrs: ''
-        crystal ${lib.escapeShellArgs (["build" "-o" bin
-            (attrs.src or (throw "No source file for crystal binary ${bin} provided"))
-        ] ++ (attrs.options or defaultOptions))}
-      '') crystalBinaries)
+  ++ lib.optionals (format == "crystal") (lib.mapAttrsToList
+    (bin: attrs: ''
+      crystal ${lib.escapeShellArgs ([
+        "build"
+        "-o"
+        bin
+        (attrs.src or (throw "No source file for crystal binary ${bin} provided"))
+      ] ++ (attrs.options or defaultOptions))}
+    '')
+    crystalBinaries)
   ++ lib.optional (format == "shards")
-      "shards build --local --production ${lib.concatStringsSep " " defaultOptions}"
+    "shards build --local --production ${lib.concatStringsSep " " defaultOptions}"
   ++ [ "runHook postBuild" ]));
 
   installPhase = args.installPhase or (lib.concatStringsSep "\n" ([
     "runHook preInstall"
   ] ++ lib.optional (format == "make")
     ''make ''${installTargets:-install} $installFlags''
-  ++ lib.optionals (format == "crystal") (map (bin: ''
+  ++ lib.optionals (format == "crystal") (map
+    (bin: ''
       install -Dm555 ${lib.escapeShellArgs [ bin "${placeholder "out"}/bin/${bin}" ]}
-    '') (lib.attrNames crystalBinaries))
+    '')
+    (lib.attrNames crystalBinaries))
   ++ lib.optional (format == "shards")
-      ''install -Dm555 bin/* -t $out/bin''
+    ''install -Dm555 bin/* -t $out/bin''
   ++ [
     ''
       for f in README* *.md LICENSE; do
@@ -78,9 +99,9 @@ in stdenv.mkDerivation (mkDerivationArgs // {
       done
     ''
   ] ++ (lib.optional installManPages ''
-      if [ -d man ]; then
-        installManPage man/*.?
-      fi
+    if [ -d man ]; then
+      installManPage man/*.?
+    fi
   '') ++ [
     "runHook postInstall"
   ]));