Skip to content

Instantly share code, notes, and snippets.

@offlinehacker
Created December 23, 2014 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save offlinehacker/b45735e7dc1bf0d3d568 to your computer and use it in GitHub Desktop.
Save offlinehacker/b45735e7dc1bf0d3d568 to your computer and use it in GitHub Desktop.
Creates nix file from composer.lock
{ pkgs ? import <nixpkgs> {}, file ? ./composer.lock }:
with pkgs.lib;
let
deps = builtins.fromJSON (builtins.readFile file);
in pkgs.stdenv.mkDerivation {
__noChroot = true;
name = "composer2nix";
impureEnvVars = [
"http_proxy" "https_proxy" "ftp_proxy" "all_proxy" "no_proxy"
];
buildInputs = [pkgs.curl];
CURL_CA_BUNDLE="${pkgs.cacert}/etc/ca-bundle.crt";
buildCommand = ''
echo "[" > $out
${concatMapStrings (p: ''
echo "{" >> $out
echo " name=\"${p.name}\";" >> $out
echo " src=\"${p.dist.url}\";" >> $out
echo " sha256=\"$(curl -L ${p.dist.url} | sha256sum | cut -d ' ' -f 1)\";" >> $out
echo " reference=\"${p.dist.reference}\";" >> $out
echo " type=\"${p.dist.type}\";" >> $out
echo "}" >> $out
'') deps.packages}
echo "]" >> $out
'';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment