Skip to content

Instantly share code, notes, and snippets.

@Pitometsu
Last active June 19, 2019 13:27
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 Pitometsu/34743536a65f6f33c2d14c81e91807bf to your computer and use it in GitHub Desktop.
Save Pitometsu/34743536a65f6f33c2d14c81e91807bf to your computer and use it in GitHub Desktop.
Local overrides

When

$ nix repl
> channel = import ./nix/channel
> overlay = import ./nix
> n = import (
  builtins.trace "Use channel: ${channel}"
    channel
) {
  config.allowUnfree = true;
  overlays = [ overlay ];
}

Now n.ocaml-ng.ocamlPackages_4_05.ezjsonm.buildInputs should contain dune-1.9.3
And n.ocaml-ng.ocamlPackages_4_05.ppx_protocol_conv_jsonm.buildInputs should contain ezjsonm-1.1.0


See nix/default.nix: question and main problem here, why overrideAttrs do not change required dependencies recursively?

{ channel ? let pkgsPath = builtins.tryEval <nixpkgs>;
in if pkgsPath.success
then pkgsPath.value
else import ./nix/channel
}:
# usage: nix-build -I nixpkgs=./nix/channel
# also might be explicitly imported with { channel = <nixpkgs> }
let
overlay = import ./nix;
in with import (
builtins.trace "Use channel: ${channel}"
channel
) {
config.allowUnfree = true;
overlays = [ overlay ];
};
ocaml-ng.ocamlPackages_4_05.mainnet
let
channel = with builtins; fromJSON
(readFile ./lock);
in fetchTarball {
url = "https://github.com/NixOS/nixpkgs-channels/archive/" +
"${channel.rev}.tar.gz";
inherit (channel) sha256;
}
{
"url": "https://github.com/NixOS/nixpkgs-channels",
"rev": "acbdaa569f4ee387386ebe1b9e60b9f95b4ab21b",
"date": "2019-04-04T19:44:54+02:00",
"sha256": "0xzyghyxk3hwhicgdbi8yv8b8ijy1rgdsj5wb26y5j322v96zlpz",
"fetchSubmodules": false
}
self: super: with self; {
ocaml-ng = (super.ocaml-ng or {}) // (with super.ocaml-ng; {
ocamlPackages_4_05 =
(ocamlPackages_4_05.overrideScope' (self: super: with super; {
lwt = lwt4;
dune = dune.overrideAttrs (drv: rec {
pname = "dune";
version = "1.9.3";
name = "${pname}-${version}";
src = fetchurl {
url = "https://github.com/ocaml/dune/releases/download/${version}/dune-${version}.tbz";
sha256 = "1jlhnx580v6i1d451z5cl8ibfd0m9qln963y2pp5v6s2winyqyri";
};
});
ezjsonm = ezjsonm.overrideAttrs (drv: rec {
inherit (drv) pname;
version = "1.1.0";
name = "${pname}-${version}";
src = fetchzip {
url = "https://github.com/mirage/${pname}/releases/download/v${version}/${pname}-v${version}.tbz";
sha256 = "091cjc70r33j3a5l683jf865vf895wqn6j7x9gllzqzckdxblw23";
};
});
})).overrideScope' (import ./ocaml);
});
}
self: super: with self; {
ppx_protocol_conv = callPackage ./ppx_protocol_conv.nix {};
ppx_protocol_conv_jsonm = callPackage ./ppx_protocol_conv_jsonm.nix {};
}
{ stdenv, lib, ocaml-ng, fetchzip }:
with ocaml-ng.ocamlPackages_4_05; buildDunePackage rec {
pname = "ppx_protocol_conv";
version = "4.0.0";
propagatedBuildInputs = [
base
ppxlib
];
minimumOCamlVersion = ocaml.version;
src = fetchzip {
url = with builtins;
"https://github.com/${(head meta.maintainers).github}/" +
"${pname}/archive/${version}.tar.gz";
sha256 = "1zhcljhasi27zgpyk32vn2nc7gqm0di75m8nicavr2fy0885xmfr";
};
meta = with stdenv.lib; {
homepage = https://github.com/andersfugmann/ppx_protocol_conv;
description = "Ppx for generating serialisation and de-serialisation functions of ocaml types";
longDescription = ''
Ppx_protocol_conv generates code to serialise and de-serialise
types. The ppx itself does not contain any protocol specific code,
but relies on 'drivers' that defines serialisation and
de-serialisation of basic types and structures.
Pre-defined drivers are available in separate packages:
ppx_protocol_conv_json (Yojson.Safe.json)
ppx_protocol_conv_jsonm (Ezjson.value)
ppx_protocol_conv_msgpack (Msgpck.t)(Xml.xml)
ppx_protocol_conv_xml-light (Xml.xml)
ppx_protocol_conv_yaml (Yaml.t).
'';
license = licenses.bsd3;
maintainers = [ {
email = "anders@fugmann.net";
github = "andersfugmann";
name = "Anders Fugmann";
} ];
};
}
{ stdenv, lib, ocaml-ng, fetchzip, ppx_protocol_conv }:
with ocaml-ng.ocamlPackages_4_05; buildDunePackage rec {
pname = "${ppx_protocol_conv.pname}_jsonm";
inherit (ppx_protocol_conv) version minimumOCamlVersion src;
propagatedBuildInputs = [ ezjsonm ppx_protocol_conv ];
meta = with stdenv.lib; {
inherit (ppx_protocol_conv) homepage license maintainers;
description = "Jsonm driver for Ppx_protocol_conv";
longDescription = ''
This package provides a driver for json (Ezjson.value)
serialization and de-serialization using the Ezjson library.
'';
};
}
@balsoft
Copy link

balsoft commented Jun 19, 2019

self: super: with self; {
  ocaml-ng = (super.ocaml-ng or {}) // (with super.ocaml-ng; {
    ocamlPackages_4_05 =
    (ocamlPackages_4_05.overrideScope' (self: super: with super; {
      lwt = lwt4; 
      dune = super.dune.overrideAttrs (drv: rec {
        pname = "dune";
        version = "1.9.3";
        name = "${pname}-${version}";
        src = fetchurl {
          url = "https://github.com/ocaml/dune/releases/download/${version}/dune-${version}.tbz";
          sha256 = "1jlhnx580v6i1d451z5cl8ibfd0m9qln963y2pp5v6s2winyqyri";
        };
      });
      ezjsonm = ezjsonm.overrideAttrs (drv: rec {
        inherit (drv) pname;
        version = "1.1.0";
        name = "${pname}-${version}";
        src = fetchzip {
        url = "https://github.com/mirage/${pname}/releases/download/v${version}/${pname}-v${version}.tbz";
        sha256 = "091cjc70r33j3a5l683jf865vf895wqn6j7x9gllzqzckdxblw23";
        };
      });
      })).overrideScope' (import ./ocaml);
  });
}

@Pitometsu
Copy link
Author

@balsoft you saved my day, again, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment