Skip to content

Commit

Permalink
Support multiple opam repositories.
Browse files Browse the repository at this point in the history
  • Loading branch information
rizo committed Nov 20, 2022
1 parent 983425a commit 5beb604
Show file tree
Hide file tree
Showing 19 changed files with 260 additions and 191 deletions.
1 change: 0 additions & 1 deletion .ocamlformat
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version = 0.24.1
profile = conventional

leading-nested-match-parens = false
Expand Down
1 change: 1 addition & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
- Support easy building of any package without nix lock.
- Support offline mode.
- Prefetch packages to compute sha256 when md5 is used.
- Support multiple opam repositories.
- [ ] Help debug nix paths (eg show opam repo path)
- [x] When the scope is built but there was a pkg override do we still build the pkg? Must not.
- [x] Replace hardcoded ocaml nix versions with a call to get currently available version from ocaml-ng.
Expand Down
4 changes: 2 additions & 2 deletions bootstrap.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

let
ocamlPackages = pkgs.ocaml-ng.ocamlPackages_4_14;
onix = import ../default.nix { inherit pkgs; };
onix = import ./default.nix { inherit pkgs; };
in {
scope = onix.build { lockFile = ../onix-lock.nix; };
scope = onix.build { lockFile = ./onix-lock.nix; };
lock = onix.lock {
repoUrl =
"https://github.com/ocaml/opam-repository.git#f3dcd527e82e83facb92cd2727651938cb9fecf9";
Expand Down
18 changes: 13 additions & 5 deletions nix/api.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ pkgs ? import <nixpkgs> { }, onix }:

let
defaultRepoUrl = "https://github.com/ocaml/opam-repository.git";
defaultRepos = [ "https://github.com/ocaml/opam-repository.git" ];
defaultLockFile = "onix-lock.json";
defaultLogLevel = "debug";
defaultOverlay = import ./overlays/default.nix pkgs;
Expand Down Expand Up @@ -283,6 +283,12 @@ let
self: super: defaultOverlay self super // overrides self super;
in scope.overrideScope' overlay;

joinRepositories = repositories:
pkgs.symlinkJoin {
name = "onix-opam-repo";
paths = map builtins.fetchGit repositories;
};

in rec {
private = { };

Expand All @@ -291,24 +297,26 @@ in rec {
, withDoc ? false, withDevSetup ? false }:
let
onixLock = lib.importJSON lockFile;
repoPath = builtins.fetchGit onixLock.repository;
repositories = onixLock.repositories;
repoPath = joinRepositories repositories;
deps = onixLock.packages;
scope = buildScope {
inherit projectRoot repoPath withTest withDoc withDevSetup;
} deps;
in applyOverrides scope overrides;

lock = { repoUrl ? defaultRepoUrl, resolutions ? null
lock = { repositories ? defaultRepos, resolutions ? null
, lockFile ? defaultLockFile, logLevel ? defaultLogLevel, withTest ? false
, withDoc ? false, withDevSetup ? false, opamFiles ? [ ] }:
let
repositoriesStr = lib.strings.concatStringsSep "," repositories;
opamFilesStr = lib.strings.concatStrings
(map (f: " " + builtins.toString f) opamFiles);
in pkgs.mkShell {
buildInputs = [ onix ];
shellHook = if isNull resolutions then ''
onix lock \
--repo-url='${repoUrl}' \
--repositories='${repositoriesStr}' \
--lock-file='${builtins.toString lockFile}' \
--with-test=${builtins.toJSON withTest} \
--with-doc=${builtins.toJSON withDoc} \
Expand All @@ -317,7 +325,7 @@ in rec {
exit $?
'' else ''
onix lock \
--repo-url='${repoUrl}' \
--repositories='${repositoriesStr}' \
--resolutions='${mkResolutionsArg resolutions}' \
--lock-file='${builtins.toString lockFile}' \
--with-test=${builtins.toJSON withTest} \
Expand Down
13 changes: 0 additions & 13 deletions nix/bootstrap.nix

This file was deleted.

7 changes: 7 additions & 0 deletions nix/overlays/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ let
# '';
# });

num = super.num.overrideAttrs (selfAttrs: superAttrs: {
postInstall = ''
mkdir -p "$out/lib/ocaml/4.14.0/site-lib/stublibs"
mv $out/lib/ocaml/4.14.0/site-lib/num/*.so "$out/lib/ocaml/4.14.0/site-lib/stublibs"
'';
});

};

darwin = {
Expand Down
Loading

0 comments on commit 5beb604

Please sign in to comment.