Initializing a project from flake template fails
Describe the bug A clear and concise description of what the bug is.
I just wanted to start a new ocaml project but following the guide in the readme throws an error.
To Reproduce Steps to reproduce the behavior.
nix flake init -t github:tweag/opam-nix
git init .
git add -A
nix develop
error:
… while evaluating the attribute 'legacyPackages.aarch64-linux.ocaml-test'
at /nix/store/01x5k4nlxcpyd85nnr0b9gm89rm8ff4x-source/lib.nix:44:11:
43| ${key} = (attrs.${key} or { }) // {
44| ${system} = ret.${key};
| ^
45| };
… while evaluating the attribute 'legacyPackages'
at /nix/store/jfa59xcdf7fjyijd4q166qdikishkc0y-source/flake.nix:29:9:
28| {
29| legacyPackages = scope.overrideScope overlay;
| ^
30|
(stack trace truncated; use '--show-trace' to show the full, detailed trace)
error: attribute 'ocaml-test' missing
at /nix/store/n4ch79chp544barfjwxmnyq1b9397sxy-source/src/opam.nix:759:16:
758| latestVersions = mapAttrs (_: last) (listRepo repo);
759| pkgdef = repo.passthru.pkgdefs.${name}.${latestVersions.${name}};
| ^
760|
Expected behavior A clear and concise description of what you expected to happen.
Expected to enter a devShell as stated in the article in the readme for getting started
Environment
- OS name + version: aarch64-linux
- Version of the code:
Additional context Add any other context about the problem here.
You also need to have an actual OCaml project in that directory as well, so that opam-nix has something to build. If you don't have any yet and want to initialize one, try:
nix-shell -p dune_3 --run "dune init proj ocaml_test ."
But be aware that for now (due to #115) you also have to disable subst:
echo "(subst disabled)" >> dune-project
It would be nice if there was a default where if a project doesn't yet exist you still get a devShell with the tools to create a project, similar to crane. Perhaps I should reference this in a new issue, though.
I think it would be better addressed in documentation. You don't need much tooling besides some version of dune, and it doesn't make sense (at least to me) for opam-nix to explicitly provide it, especially given how it doesn't even save much typing (nix-shell -p dune_3 vs nix develop). I'll keep this issue open until I can update the documentation to reflect this.
I think my only argument would be discover-ability, but documented is better than not 🙂
I'll add that on initial setup, you also need to:
-
Have
ocamlin the path (either with nix shell etc or installed system-wide) -
Run
dune buildat least once, otherwise you'll have an empty .opam file, andnix developetc will fail
Thanks @snrubthinks , I'll address this in the docs