Created
June 10, 2020 14:42
-
-
Save manveru/b04081bc29036f64587b4fa3d57daa0d to your computer and use it in GitHub Desktop.
Fetch Crystal dependencies on the lfy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ pkgs ? import ./nix { } }: | |
let | |
inherit (builtins) fromJSON readFile toFile elemAt split mapAttrs; | |
inherit (pkgs) | |
crystal runCommand stdenv lib coreutils inclusive pkgconfig openssl; | |
inherit (pkgs.lib) makeBinPath; | |
shardLock2JSON = shardLockFile: | |
runCommand "yaml2json" { buildInputs = [ crystal ]; } '' | |
crystal eval <<-EOF > $out | |
require "json" | |
require "yaml" | |
puts YAML.parse(File.read("${shardLockFile}")).to_json | |
EOF | |
''; | |
fetchShards = shardLockFile: | |
mapAttrs (name: value: | |
let | |
parts = split "\\+git\\.commit\\." value.version; | |
version = elemAt parts 0; | |
rev = elemAt parts 2; | |
in fetchGit { | |
url = value.git; | |
rev = rev; | |
}) (fromJSON (readFile (shardLock2JSON shardLockFile))).shards; | |
shardsDir = shardLockFile: | |
stdenv.mkDerivation { | |
name = "shard-libs"; | |
__structuredAttrs = true; | |
preferLocalBuild = true; | |
PATH = lib.makeBinPath [ coreutils ]; | |
shards = fetchShards shardLockFile; | |
builder = toFile "builder" '' | |
. .attrs.sh | |
out=''${outputs[out]} | |
mkdir $out | |
for name in "''${!shards[@]}"; do | |
echo "Linking shard $name ..." | |
ln -s "''${shards[$name]}" "$out/$name" | |
done | |
''; | |
}; | |
in crystal.buildCrystalPackage { | |
pname = "example"; | |
version = "0.1.0"; | |
format = "crystal"; | |
buildInputs = [ pkgconfig openssl ]; | |
src = inclusive ./. [ ./src ]; | |
preConfigure = '' | |
ln -s ${shardsDir ./shard.lock} lib | |
''; | |
crystalBinaries.example.src = "src/example.cr"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment