diff options
Diffstat (limited to 'nixpkgs/pkgs/development/tools/ocaml/opam')
4 files changed, 471 insertions, 0 deletions
diff --git a/nixpkgs/pkgs/development/tools/ocaml/opam/1.2.2.nix b/nixpkgs/pkgs/development/tools/ocaml/opam/1.2.2.nix new file mode 100644 index 000000000000..a128f2144e9f --- /dev/null +++ b/nixpkgs/pkgs/development/tools/ocaml/opam/1.2.2.nix @@ -0,0 +1,92 @@ +{ stdenv, lib, fetchurl, makeWrapper, + ocaml, unzip, ncurses, curl, aspcud +}: + +assert lib.versionAtLeast ocaml.version "3.12.1"; + +let + srcs = { + cudf = fetchurl { + url = "https://gforge.inria.fr/frs/download.php/file/33593/cudf-0.7.tar.gz"; + sha256 = "92c8a9ed730bbac73f3513abab41127d966c9b9202ab2aaffcd02358c030a701"; + }; + extlib = fetchurl { + url = "http://ocaml-extlib.googlecode.com/files/extlib-1.5.3.tar.gz"; + sha256 = "c095eef4202a8614ff1474d4c08c50c32d6ca82d1015387785cf03d5913ec021"; + }; + ocaml_re = fetchurl { + url = "https://github.com/ocaml/ocaml-re/archive/ocaml-re-1.2.0.tar.gz"; + sha256 = "a34dd9d6136731436a963bbab5c4bbb16e5d4e21b3b851d34887a3dec451999f"; + }; + ocamlgraph = fetchurl { + url = "http://ocamlgraph.lri.fr/download/ocamlgraph-1.8.5.tar.gz"; + sha256 = "d167466435a155c779d5ec25b2db83ad851feb42ebc37dca8ffa345ddaefb82f"; + }; + dose3 = fetchurl { + url = "https://gforge.inria.fr/frs/download.php/file/34277/dose3-3.3.tar.gz"; + sha256 = "8dc4dae9b1a81bb3a42abb283df785ba3eb00ade29b13875821c69f03e00680e"; + }; + cmdliner = fetchurl { + url = "https://erratique.ch/software/cmdliner/releases/cmdliner-0.9.7.tbz"; + sha256 = "9c19893cffb5d3c3469ee0cce85e3eeeba17d309b33b9ace31aba06f68f0bf7a"; + }; + uutf = fetchurl { + url = "https://erratique.ch/software/uutf/releases/uutf-0.9.3.tbz"; + sha256 = "1f364f89b1179e5182a4d3ad8975f57389d45548735d19054845e06a27107877"; + }; + jsonm = fetchurl { + url = "https://erratique.ch/software/jsonm/releases/jsonm-0.9.1.tbz"; + sha256 = "3fd4dca045d82332da847e65e981d8b504883571d299a3f7e71447d46bc65f73"; + }; + opam = fetchurl { + url = "https://github.com/ocaml/opam/archive/1.2.2.zip"; + sha256 = "c590ce55ae69ec74f46215cf16a156a02b23c5f3ecb22f23a3ad9ba3d91ddb6e"; + }; + }; +in stdenv.mkDerivation { + pname = "opam"; + version = "1.2.2"; + + buildInputs = [ unzip curl ncurses ocaml makeWrapper ]; + + src = srcs.opam; + + postUnpack = '' + ln -sv ${srcs.cudf} $sourceRoot/src_ext/${srcs.cudf.name} + ln -sv ${srcs.extlib} $sourceRoot/src_ext/${srcs.extlib.name} + ln -sv ${srcs.ocaml_re} $sourceRoot/src_ext/${srcs.ocaml_re.name} + ln -sv ${srcs.ocamlgraph} $sourceRoot/src_ext/${srcs.ocamlgraph.name} + ln -sv ${srcs.dose3} $sourceRoot/src_ext/${srcs.dose3.name} + ln -sv ${srcs.cmdliner} $sourceRoot/src_ext/${srcs.cmdliner.name} + ln -sv ${srcs.uutf} $sourceRoot/src_ext/${srcs.uutf.name} + ln -sv ${srcs.jsonm} $sourceRoot/src_ext/${srcs.jsonm.name} + ''; + + preConfigure = '' + substituteInPlace ./src_ext/Makefile --replace "%.stamp: %.download" "%.stamp:" + ''; + + postConfigure = "make lib-ext"; + + # Dirty, but apparently ocp-build requires a TERM + makeFlags = ["TERM=screen"]; + + # change argv0 to "opam" as a workaround for + # https://github.com/ocaml/opam/issues/2142 + postInstall = '' + mv $out/bin/opam $out/bin/.opam-wrapped + makeWrapper $out/bin/.opam-wrapped $out/bin/opam \ + --argv0 "opam" \ + --suffix PATH : ${aspcud}/bin:${unzip}/bin:${curl}/bin + ''; + + doCheck = false; + + meta = with lib; { + description = "A package manager for OCaml"; + homepage = "http://opam.ocamlpro.com/"; + maintainers = [ maintainers.henrytill ]; + platforms = platforms.all; + license = licenses.lgpl21Plus; + }; +} diff --git a/nixpkgs/pkgs/development/tools/ocaml/opam/default.nix b/nixpkgs/pkgs/development/tools/ocaml/opam/default.nix new file mode 100644 index 000000000000..4fe408fb77f0 --- /dev/null +++ b/nixpkgs/pkgs/development/tools/ocaml/opam/default.nix @@ -0,0 +1,120 @@ +{ stdenv, lib, fetchurl, makeWrapper, getconf, + ocaml, unzip, ncurses, curl, aspcud, bubblewrap +}: + +assert lib.versionAtLeast ocaml.version "4.02.3"; + +let + srcs = { + cmdliner = fetchurl { + url = "http://erratique.ch/software/cmdliner/releases/cmdliner-1.0.2.tbz"; + sha256 = "18jqphjiifljlh9jg8zpl6310p3iwyaqphdkmf89acyaix0s4kj1"; + }; + cppo = fetchurl { + url = "https://github.com/mjambon/cppo/archive/v1.6.5.tar.gz"; + sha256 = "1dkm3d5h6h56y937gcdk2wixlpzl59vv5pmiafglr89p20kf7gqf"; + }; + cudf = fetchurl { + url = "https://gforge.inria.fr/frs/download.php/36602/cudf-0.9.tar.gz"; + sha256 = "0771lwljqwwn3cryl0plny5a5dyyrj4z6bw66ha5n8yfbpcy8clr"; + }; + dose3 = fetchurl { + url = "https://gforge.inria.fr/frs/download.php/file/36063/dose3-5.0.1.tar.gz"; + sha256 = "00yvyfm4j423zqndvgc1ycnmiffaa2l9ab40cyg23pf51qmzk2jm"; + }; + dune-local = fetchurl { + url = "https://github.com/ocaml/dune/releases/download/1.6.3/dune-1.6.3.tbz"; + sha256 = "0dmf0wbfmgdy5plz1bjiisc2hjgblvxsnrqjmw2c8y45v1h23mdz"; + }; + extlib = fetchurl { + url = "http://ygrek.org.ua/p/release/ocaml-extlib/extlib-1.7.5.tar.gz"; + sha256 = "19slqf5bdj0rrph2w41giwmn6df2qm07942jn058pjkjrnk30d4s"; + }; + mccs = fetchurl { + url = "https://github.com/AltGr/ocaml-mccs/archive/1.1+11.tar.gz"; + sha256 = "0mswapf37rav8nvvbjc4c7c7wnl6qwgd3c5v0nfifmr910qygz72"; + }; + ocamlgraph = fetchurl { + url = "http://ocamlgraph.lri.fr/download/ocamlgraph-1.8.8.tar.gz"; + sha256 = "0m9g16wrrr86gw4fz2fazrh8nkqms0n863w7ndcvrmyafgxvxsnr"; + }; + opam-file-format = fetchurl { + url = "https://github.com/ocaml/opam-file-format/archive/2.0.0.tar.gz"; + sha256 = "0cjw69r7iilidi7b6arr92kjnjspchvwnmwr1b1gyaxqxpr2s98m"; + }; + re = fetchurl { + url = "https://github.com/ocaml/ocaml-re/releases/download/1.8.0/re-1.8.0.tbz"; + sha256 = "0qkv42a4hpqpxvqa4kdkkcbhbg7aym9kv4mqgm3m51vxbd0pq0lv"; + }; + result = fetchurl { + url = "https://github.com/janestreet/result/releases/download/1.3/result-1.3.tbz"; + sha256 = "1lrnbxdq80gbhnp85mqp1kfk0bkh6q1c93sfz2qgnq2qyz60w4sk"; + }; + seq = fetchurl { + url = "https://github.com/c-cube/seq/archive/0.1.tar.gz"; + sha256 = "02lb2d9i12bxrz2ba5wygk2bycan316skqlyri0597q7j9210g8r"; + }; + opam = fetchurl { + url = "https://github.com/ocaml/opam/archive/2.0.7.zip"; + sha256 = "03yxj4hw9p5dh34b1yzl3xd0l1v2l2az0n7ix453yjrkn0wn0xic"; + }; + }; +in stdenv.mkDerivation { + pname = "opam"; + version = "2.0.7"; + + buildInputs = [ unzip curl ncurses ocaml makeWrapper getconf ] ++ lib.optional stdenv.isLinux bubblewrap; + + src = srcs.opam; + + postUnpack = '' + ln -sv ${srcs.cmdliner} $sourceRoot/src_ext/cmdliner.tbz + ln -sv ${srcs.cppo} $sourceRoot/src_ext/cppo.tar.gz + ln -sv ${srcs.cudf} $sourceRoot/src_ext/cudf.tar.gz + ln -sv ${srcs.dose3} $sourceRoot/src_ext/dose3.tar.gz + ln -sv ${srcs.dune-local} $sourceRoot/src_ext/dune-local.tbz + ln -sv ${srcs.extlib} $sourceRoot/src_ext/extlib.tar.gz + ln -sv ${srcs.mccs} $sourceRoot/src_ext/mccs.tar.gz + ln -sv ${srcs.ocamlgraph} $sourceRoot/src_ext/ocamlgraph.tar.gz + ln -sv ${srcs.opam-file-format} $sourceRoot/src_ext/opam-file-format.tar.gz + ln -sv ${srcs.re} $sourceRoot/src_ext/re.tbz + ln -sv ${srcs.result} $sourceRoot/src_ext/result.tbz + ln -sv ${srcs.seq} $sourceRoot/src_ext/seq.tar.gz + ''; + + patches = [ ./opam-shebangs.patch ]; + + preConfigure = '' + substituteInPlace ./src_ext/Makefile --replace "%.stamp: %.download" "%.stamp:" + patchShebangs src/state/shellscripts + ''; + + postConfigure = "make lib-ext"; + + # Dirty, but apparently ocp-build requires a TERM + makeFlags = ["TERM=screen"]; + + outputs = [ "out" "installer" ]; + setOutputFlags = false; + + # change argv0 to "opam" as a workaround for + # https://github.com/ocaml/opam/issues/2142 + postInstall = '' + mv $out/bin/opam $out/bin/.opam-wrapped + makeWrapper $out/bin/.opam-wrapped $out/bin/opam \ + --argv0 "opam" \ + --suffix PATH : ${aspcud}/bin:${unzip}/bin:${curl}/bin:${lib.optionalString stdenv.isLinux "${bubblewrap}/bin:"}${getconf}/bin \ + --set OPAM_USER_PATH_RO /run/current-system/sw/bin:/nix/ + $out/bin/opam-installer --prefix=$installer opam-installer.install + ''; + + doCheck = false; + + meta = with lib; { + description = "A package manager for OCaml"; + homepage = "https://opam.ocaml.org/"; + maintainers = [ maintainers.henrytill maintainers.marsam ]; + platforms = platforms.all; + }; +} +# Generated by: ./opam.nix.pl -v 2.0.7 -p opam-shebangs.patch diff --git a/nixpkgs/pkgs/development/tools/ocaml/opam/opam-shebangs.patch b/nixpkgs/pkgs/development/tools/ocaml/opam/opam-shebangs.patch new file mode 100644 index 000000000000..13aa7a895708 --- /dev/null +++ b/nixpkgs/pkgs/development/tools/ocaml/opam/opam-shebangs.patch @@ -0,0 +1,128 @@ +diff --git a/src/client/opamInitDefaults.ml b/src/client/opamInitDefaults.ml +index eca13a7c..1fd66f43 100644 +--- a/src/client/opamInitDefaults.ml ++++ b/src/client/opamInitDefaults.ml +@@ -35,11 +35,15 @@ let eval_variables = [ + let os_filter os = + FOp (FIdent ([], OpamVariable.of_string "os", None), `Eq, FString os) + ++let os_distribution_filter distro = ++ FOp (FIdent ([], OpamVariable.of_string "os-distribution", None), `Eq, FString distro) ++ + let linux_filter = os_filter "linux" + let macos_filter = os_filter "macos" + let openbsd_filter = os_filter "openbsd" + let freebsd_filter = os_filter "freebsd" + let sandbox_filter = FOr (linux_filter, macos_filter) ++let nixos_filter = os_distribution_filter "nixos" + + let gpatch_filter = FOr (openbsd_filter, freebsd_filter) + let patch_filter = FNot gpatch_filter +@@ -50,6 +54,11 @@ let wrappers ~sandboxing () = + CString t, None; + ] in + let w = OpamFile.Wrappers.empty in ++ let w = { w with ++ OpamFile.Wrappers. ++ pre_build = [[CString "%{hooks}%/shebangs.sh", None], Some nixos_filter]; ++ } ++ in + if sandboxing then + { w with + OpamFile.Wrappers. +@@ -113,6 +122,7 @@ let required_tools ~sandboxing () = + let init_scripts () = [ + ("sandbox.sh", OpamScript.bwrap), Some bwrap_filter; + ("sandbox.sh", OpamScript.sandbox_exec), Some macos_filter; ++ ("shebangs.sh", OpamScript.patch_shebangs), Some nixos_filter; + ] + + module I = OpamFile.InitConfig +diff --git a/src/state/opamScript.mli b/src/state/opamScript.mli +index 03449970..83de0b53 100644 +--- a/src/state/opamScript.mli ++++ b/src/state/opamScript.mli +@@ -20,3 +20,4 @@ val env_hook : string + val env_hook_zsh : string + val env_hook_csh : string + val env_hook_fish : string ++val patch_shebangs : string +diff --git a/src/state/shellscripts/patch_shebangs.sh b/src/state/shellscripts/patch_shebangs.sh +new file mode 100755 +index 00000000..3ea84e2d +--- /dev/null ++++ b/src/state/shellscripts/patch_shebangs.sh +@@ -0,0 +1,73 @@ ++#!/usr/bin/env bash ++# This setup hook causes the fixup phase to rewrite all script ++# interpreter file names (`#! /path') to paths found in $PATH. E.g., ++# /bin/sh will be rewritten to /nix/store/<hash>-some-bash/bin/sh. ++# /usr/bin/env gets special treatment so that ".../bin/env python" is ++# rewritten to /nix/store/<hash>/bin/python. Interpreters that are ++# already in the store are left untouched. ++ ++header() { echo "$1"; } ++stopNest() { true; } ++ ++fixupOutputHooks+=('if [ -z "${dontPatchShebangs-}" -a -e "$prefix" ]; then patchShebangs "$prefix"; fi') ++ ++patchShebangs() { ++ local dir="$1" ++ header "patching script interpreter paths in $dir" ++ local f ++ local oldPath ++ local newPath ++ local arg0 ++ local args ++ local oldInterpreterLine ++ local newInterpreterLine ++ ++ find "$dir" -type f -perm -0100 | while read f; do ++ if [ "$(head -1 "$f" | head -c+2)" != '#!' ]; then ++ # missing shebang => not a script ++ continue ++ fi ++ ++ oldInterpreterLine=$(head -1 "$f" | tail -c+3) ++ read -r oldPath arg0 args <<< "$oldInterpreterLine" ++ ++ if $(echo "$oldPath" | grep -q "/bin/env$"); then ++ # Check for unsupported 'env' functionality: ++ # - options: something starting with a '-' ++ # - environment variables: foo=bar ++ if $(echo "$arg0" | grep -q -- "^-.*\|.*=.*"); then ++ echo "unsupported interpreter directive \"$oldInterpreterLine\" (set dontPatchShebangs=1 and handle shebang patching yourself)" ++ exit 1 ++ fi ++ newPath="$(command -v "$arg0" || true)" ++ else ++ if [ "$oldPath" = "" ]; then ++ # If no interpreter is specified linux will use /bin/sh. Set ++ # oldpath="/bin/sh" so that we get /nix/store/.../sh. ++ oldPath="/bin/sh" ++ fi ++ newPath="$(command -v "$(basename "$oldPath")" || true)" ++ args="$arg0 $args" ++ fi ++ ++ # Strip trailing whitespace introduced when no arguments are present ++ newInterpreterLine="$(echo "$newPath $args" | sed 's/[[:space:]]*$//')" ++ ++ if [ -n "$oldPath" -a "${oldPath:0:${#NIX_STORE}}" != "$NIX_STORE" ]; then ++ if [ -n "$newPath" -a "$newPath" != "$oldPath" ]; then ++ echo "$f: interpreter directive changed from \"$oldInterpreterLine\" to \"$newInterpreterLine\"" ++ # escape the escape chars so that sed doesn't interpret them ++ escapedInterpreterLine=$(echo "$newInterpreterLine" | sed 's|\\|\\\\|g') ++ # Preserve times, see: https://github.com/NixOS/nixpkgs/pull/33281 ++ touch -r "$f" "$f.timestamp" ++ sed -i -e "1 s|.*|#\!$escapedInterpreterLine|" "$f" ++ touch -r "$f.timestamp" "$f" ++ rm "$f.timestamp" ++ fi ++ fi ++ done ++ ++ stopNest ++} ++ ++patchShebangs . diff --git a/nixpkgs/pkgs/development/tools/ocaml/opam/opam.nix.pl b/nixpkgs/pkgs/development/tools/ocaml/opam/opam.nix.pl new file mode 100755 index 000000000000..1cbad6f5f44e --- /dev/null +++ b/nixpkgs/pkgs/development/tools/ocaml/opam/opam.nix.pl @@ -0,0 +1,131 @@ +#!/usr/bin/env perl + +use strict; +use warnings qw<all>; +use Getopt::Std; + +my $gencmd = "# Generated by: " . join(" ", $0, @ARGV) . "\n"; + +our $opt_v; +our $opt_p; +our $opt_r; +our $opt_t; +getopts "v:p:t:r:"; + +my $OPAM_RELEASE = $opt_v // "2.0.0"; +my $OPAM_TAG = $opt_t // $OPAM_RELEASE; +my $OPAM_GITHUB_REPO = $opt_r // "ocaml/opam"; +my $OPAM_RELEASE_URL = "https://github.com/$OPAM_GITHUB_REPO/archive/$OPAM_TAG.zip"; +my $OPAM_RELEASE_SHA256 = `nix-prefetch-url \Q$OPAM_RELEASE_URL\E`; +chomp $OPAM_RELEASE_SHA256; + +my $OPAM_BASE_URL = "https://raw.githubusercontent.com/$OPAM_GITHUB_REPO/$OPAM_TAG"; +my $OPAM_OPAM = `curl -L --url \Q$OPAM_BASE_URL\E/opam-devel.opam`; +my($OCAML_MIN_VERSION) = $OPAM_OPAM =~ /^available: ocaml-version >= "(.*)"$/m + or die "could not parse ocaml version bound\n"; + +print <<"EOF"; +{ stdenv, lib, fetchurl, makeWrapper, getconf, + ocaml, unzip, ncurses, curl, aspcud, bubblewrap +}: + +assert lib.versionAtLeast ocaml.version "$OCAML_MIN_VERSION"; + +let + srcs = { +EOF + +my %urls = (); +my %md5s = (); + +open(SOURCES, "-|", "curl", "-L", "--url", "$OPAM_BASE_URL/src_ext/Makefile.sources"); +while (<SOURCES>) { + if (/^URL_(?!PKG_)([-\w]+)\s*=\s*(\S+)$/) { + $urls{$1} = $2; + } elsif (/^MD5_(?!PKG_)([-\w]+)\s*=\s*(\S+)$/) { + $md5s{$1} = $2; + } +} +for my $src (sort keys %urls) { + my ($sha256,$store_path) = split /\n/, `nix-prefetch-url --print-path \Q$urls{$src}\E`; + system "echo \Q$md5s{$src}\E' *'\Q$store_path\E | md5sum -c 1>&2"; + die "md5 check failed for $urls{$src}\n" if $?; + print <<"EOF"; + $src = fetchurl { + url = "$urls{$src}"; + sha256 = "$sha256"; + }; +EOF +} + +print <<"EOF"; + opam = fetchurl { + url = "$OPAM_RELEASE_URL"; + sha256 = "$OPAM_RELEASE_SHA256"; + }; + }; +in stdenv.mkDerivation { + pname = "opam"; + version = "$OPAM_RELEASE"; + + buildInputs = [ unzip curl ncurses ocaml makeWrapper getconf ] ++ lib.optional stdenv.isLinux bubblewrap; + + src = srcs.opam; + + postUnpack = '' +EOF +for my $src (sort keys %urls) { + my($ext) = $urls{$src} =~ /(\.(?:t(?:ar\.|)|)(?:gz|bz2?))$/ + or die "could not find extension for $urls{$src}\n"; + print <<"EOF"; + ln -sv \${srcs.$src} \$sourceRoot/src_ext/$src$ext +EOF +} +print <<'EOF'; + ''; + +EOF +if (defined $opt_p) { + print " patches = [ "; + for my $patch (split /[, ]/, $opt_p) { + $patch =~ s/^(?=[^\/]*$)/.\//; + print "$patch "; + } + print "];\n\n"; +} +print <<'EOF'; + preConfigure = '' + substituteInPlace ./src_ext/Makefile --replace "%.stamp: %.download" "%.stamp:" + patchShebangs src/state/shellscripts + ''; + + postConfigure = "make lib-ext"; + + # Dirty, but apparently ocp-build requires a TERM + makeFlags = ["TERM=screen"]; + + outputs = [ "out" "installer" ]; + setOutputFlags = false; + + # change argv0 to "opam" as a workaround for + # https://github.com/ocaml/opam/issues/2142 + postInstall = '' + mv $out/bin/opam $out/bin/.opam-wrapped + makeWrapper $out/bin/.opam-wrapped $out/bin/opam \ + --argv0 "opam" \ + --suffix PATH : ${aspcud}/bin:${unzip}/bin:${curl}/bin:${lib.optionalString stdenv.isLinux "${bubblewrap}/bin:"}${getconf}/bin \ + --set OPAM_USER_PATH_RO /run/current-system/sw/bin:/nix/ + $out/bin/opam-installer --prefix=$installer opam-installer.install + ''; + + doCheck = false; + + meta = with lib; { + description = "A package manager for OCaml"; + homepage = "https://opam.ocaml.org/"; + maintainers = [ maintainers.henrytill maintainers.marsam ]; + platforms = platforms.all; + }; +} +EOF +print $gencmd; |