Merge master into staging-next
This commit is contained in:
@@ -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"
|
||||
]));
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
require "yaml"
|
||||
require "json"
|
||||
|
||||
class PrefetchJSON
|
||||
JSON.mapping(sha256: String)
|
||||
end
|
||||
|
||||
class ShardLock
|
||||
YAML.mapping(
|
||||
version: Float32,
|
||||
shards: Hash(String, Hash(String, String))
|
||||
)
|
||||
end
|
||||
|
||||
File.open "shards.nix", "w+" do |file|
|
||||
file.puts %({)
|
||||
yaml = ShardLock.from_yaml(File.read("shard.lock"))
|
||||
yaml.shards.each do |key, value|
|
||||
owner, repo = value["github"].split("/")
|
||||
url = "https://github.com/#{value["github"]}"
|
||||
rev = if value["version"]?
|
||||
"v#{value["version"]}"
|
||||
else
|
||||
value["commit"]
|
||||
end
|
||||
|
||||
sha256 = ""
|
||||
args = ["--url", url, "--rev", rev]
|
||||
Process.run("@nixPrefetchGit@", args: args) do |x|
|
||||
x.error.each_line { |e| puts e }
|
||||
sha256 = PrefetchJSON.from_json(x.output).sha256
|
||||
end
|
||||
|
||||
file.puts %( #{key} = {)
|
||||
file.puts %( owner = "#{owner}";)
|
||||
file.puts %( repo = "#{repo}";)
|
||||
file.puts %( rev = "#{rev}";)
|
||||
file.puts %( sha256 = "#{sha256}";)
|
||||
file.puts %( };)
|
||||
end
|
||||
file.puts %(})
|
||||
end
|
||||
@@ -1,22 +0,0 @@
|
||||
{ lib, crystal, nix-prefetch-git }:
|
||||
|
||||
crystal.buildCrystalPackage {
|
||||
pname = "crystal2nix";
|
||||
version = "unstable-2018-07-31";
|
||||
|
||||
nixPrefetchGit = "${lib.getBin nix-prefetch-git}/bin/nix-prefetch-git";
|
||||
unpackPhase = "substituteAll ${./crystal2nix.cr} crystal2nix.cr";
|
||||
|
||||
format = "crystal";
|
||||
|
||||
crystalBinaries.crystal2nix.src = "crystal2nix.cr";
|
||||
|
||||
# it will blow up without a shard.yml file
|
||||
doInstallCheck = false;
|
||||
|
||||
meta = with lib; {
|
||||
description = "Utility to convert Crystal's shard.lock files to a Nix file";
|
||||
license = licenses.mit;
|
||||
maintainers = with maintainers; [ manveru ];
|
||||
};
|
||||
}
|
||||
36
pkgs/development/compilers/crystal2nix/default.nix
Normal file
36
pkgs/development/compilers/crystal2nix/default.nix
Normal file
@@ -0,0 +1,36 @@
|
||||
{ lib, fetchFromGitHub, fetchgit, crystal, makeWrapper, nix-prefetch-git }:
|
||||
|
||||
crystal.buildCrystalPackage rec {
|
||||
pname = "crystal2nix";
|
||||
version = "0.1.0";
|
||||
|
||||
src = fetchFromGitHub {
|
||||
owner = "peterhoeg";
|
||||
repo = "crystal2nix";
|
||||
rev = "v${version}";
|
||||
sha256 = "sha256-K1ElG8VC/D0axmSRaufH3cE50xNQisAmFucDkV+5O0s=";
|
||||
};
|
||||
|
||||
format = "shards";
|
||||
|
||||
shardsFile = ./shards.nix;
|
||||
|
||||
nativeBuildInputs = [ makeWrapper ];
|
||||
|
||||
postInstall = ''
|
||||
wrapProgram $out/bin/crystal2nix \
|
||||
--prefix PATH : ${lib.makeBinPath [ nix-prefetch-git ]}
|
||||
'';
|
||||
|
||||
# temporarily off. We need the checks to execute the wrapped binary
|
||||
doCheck = false;
|
||||
|
||||
# it requires an internet connection when run
|
||||
doInstallCheck = false;
|
||||
|
||||
meta = with lib; {
|
||||
description = "Utility to convert Crystal's shard.lock files to a Nix file";
|
||||
license = licenses.mit;
|
||||
maintainers = with maintainers; [ manveru peterhoeg ];
|
||||
};
|
||||
}
|
||||
14
pkgs/development/compilers/crystal2nix/shards.nix
Normal file
14
pkgs/development/compilers/crystal2nix/shards.nix
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
json_mapping = {
|
||||
owner = "crystal-lang";
|
||||
repo = "json_mapping.cr";
|
||||
rev = "v0.1.0";
|
||||
sha256 = "1qq5vs2085x7cwmp96rrjns0yz9kiz1lycxynfbz5psxll6b8p55";
|
||||
};
|
||||
yaml_mapping = {
|
||||
owner = "crystal-lang";
|
||||
repo = "yaml_mapping.cr";
|
||||
rev = "v0.1.0";
|
||||
sha256 = "02spz1521g59ar6rp0znnr01di766kknbjxjnygs39yn0cmpzqc1";
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user