rizo / onix-examples

4 stars 0 forks source link

error: file 'nixpkgs' was not found in the Nix search path #1

Closed yawaramin closed 1 year ago

yawaramin commented 1 year ago

Getting this error:

% cd hello-ocaml-5
% make
nix build -f default.nix -j auto -v
error: file 'nixpkgs' was not found in the Nix search path (add it using $NIX_PATH or -I)

       at /Users/yawarquadiramin/Downloads/onix-examples-master/hello-ocaml-5/default.nix:1:17:

            1| { pkgs ? import <nixpkgs> { } }:
             |                 ^
            2|
(use '--show-trace' to show detailed location information)
make: *** [build] Error 1

Nix version:

% nix --version
nix (Nix) 2.12.0
rizo commented 1 year ago

Thanks for opening the issue, @yawaramin!

It seems like your nix installation isn't correctly configured. Looks like NIX_PATH isn't set by your environment.

Could you provide some additional details?

$ uname -a
$ printenv NIX_PATH
$ nix-channel --list

Also how did you install nix? Is your shell sourcing the nix environment?

I would suggest confirming that you have completed all steps in https://nixos.org/manual/nixos/stable/index.html#sec-installing-from-other-distro See my comment below.

rizo commented 1 year ago

In particular, if you don't have any channels (last command from my previous post), you can run:

$ nix-channel --add https://nixos.org/channels/nixpkgs-unstable nixpkgs
yawaramin commented 1 year ago

Hi, I installed Nix using this installer: https://zero-to-nix.com/concepts/nix-installer

Outputs of the requested commands:

% uname -a
Darwin Yawars-MacBook-Air.local 21.6.0 Darwin Kernel Version 21.6.0: Mon Aug 22 20:20:05 PDT 2022; root:xnu-8020.140.49~2/RELEASE_ARM64_T8101 arm64
% printenv NIX_PATH
% nix-channel --list
nixpkgs https://nixos.org/channels/nixpkgs-unstable
rizo commented 1 year ago

Strange, it does seem like you have the correct channel.

Just to be 100% sure, could you try building the following minimal example?

Create hello.nix:

{ pkgs ? import <nixpkgs> { } }: pkgs.hello

Build:

$ nix build -f hello.nix
$ ./result/bin/hello
rizo commented 1 year ago

Or even something as simple as:

$ nix-instantiate --eval -E '(import <nixpkgs> {}).lib.version'

Which I found in https://nixos.org/manual/nix/stable/command-ref/nix-channel.html#examples

leojrfs commented 1 year ago

Hi, I installed Nix using this installer: https://zero-to-nix.com/concepts/nix-installer

Outputs of the requested commands:

% uname -a
Darwin Yawars-MacBook-Air.local 21.6.0 Darwin Kernel Version 21.6.0: Mon Aug 22 20:20:05 PDT 2022; root:xnu-8020.140.49~2/RELEASE_ARM64_T8101 arm64
% printenv NIX_PATH
% nix-channel --list
nixpkgs https://nixos.org/channels/nixpkgs-unstable

I'd recommend to install using the official script. For that, uninstall the one you installed by:

/nix/nix-installer uninstall

and then follow the official instructions for multi-user installation for MacOS here.

If you want to keep the unofficial setup, you should raise this issue at https://github.com/DeterminateSystems/nix-installer

Depending on the unofficial nix-installer version you used, It might not have MacOS support. Which might be the case since you shown that your resulting nix version is 2.12.0.

rizo commented 1 year ago

Might be related to https://github.com/DeterminateSystems/nix-installer/issues/234

yawaramin commented 1 year ago

Good find! After running nix-channel --update, I got to the next error :-)

...
building '/nix/store/5jsl2igq5mhac0bbkq5yflbkjdvhk1mm-topkg-1.0.7.tbz.drv'...
building '/nix/store/k2zwmhign48354n80zbvrf9p5z3rkcqh-trunk.tar.gz.drv'...
copying path '/nix/store/8j2xkb2as1b9cknyr7376kd7qgnhb01l-clang-11.1.0' from 'https://cache.nixos.org'...
copying path '/nix/store/yqki0jmyjmyzykfj8h8wqn942ca2fm60-cctools-binutils-darwin-973.0.1' from 'https://cache.nixos.org'...
copying path '/nix/store/nwa5r8nkw1b1y70v4b1ndqszmfdnakhy-cctools-binutils-darwin-wrapper-973.0.1' from 'https://cache.nixos.org'...
copying path '/nix/store/cqag9fv2gia03nzcsaygan8fw1ggdf4g-clang-wrapper-11.1.0' from 'https://cache.nixos.org'...
copying path '/nix/store/6f2hwi7fni5b1v67ic3m7zdq0vg8gkn5-ocaml-4.14.0' from 'https://cache.nixos.org'...
copying path '/nix/store/qrz2mnb2gsnzmw2pqax693daxh5hsgap-stdenv-darwin' from 'https://cache.nixos.org'...
error: hash mismatch in fixed-output derivation '/nix/store/k2zwmhign48354n80zbvrf9p5z3rkcqh-trunk.tar.gz.drv':
         specified: sha256-GHAi//lVga8OGgjiVjZsvQMmZGLcnr2crTtjUa6V96k=
            got:    sha256-UINpKl9ZT/qSW2DyAfX+fZldliA2HmPgTJbN6n0aVbM=
error: 1 dependencies of derivation '/nix/store/7sl2kqz6g99gys9jqfjqpadlw1p0fdzp-ocaml-variants-5.1.0+trunk.drv' failed to build
error: 1 dependencies of derivation '/nix/store/hz5kfwpqkc1cd5f5kgx2h48x78375hm4-ocaml-5.1.0.drv' failed to build
error: 1 dependencies of derivation '/nix/store/j83c8dsqz66b6l7b53813j8r06fwrxyl-example-dev.drv' failed to build
error: 1 dependencies of derivation '/nix/store/vxawahhiydz58axfcf85y42qpnshrhjr-onix-links.drv' failed to build
make: *** [build] Error 1
rizo commented 1 year ago

Fixed in https://github.com/odis-labs/onix-examples/commit/0955f9e59b2fa28967983f31c9e28110d84144a6

I accidentally used ocaml-trunk, which is meant to be a mutable endpoint of course.

Try pulling and running make again. At the end of the compilation run ./result/example-dev/bin/example.

Thanks for testing this.

yawaramin commented 1 year ago

Works with the latest update, thank you. I also had to delete the other example directories otherwise when I tried to go into the make shell and run dune build it complains:

(nix:nix-shell) [onix]$ dune build
Entering directory '/Users/yawarquadiramin/Downloads'
Error: Too many opam files for package "example":
- "onix-examples-master 2/hello-nix-compiler/example.opam"
- "onix-examples-master 2/hello-nix-compiler-flakes/example.opam"

Also one small nitpick,

(nix:nix-shell) [onix]$ dune build
Entering directory '/Users/yawarquadiramin/Downloads'
File "onix-examples-master 2/hello-ocaml-5/example.ml", line 1, characters 0-12:
1 | open Eio.Std
    ^^^^^^^^^^^^
Error (warning 33 [unused-open]): unused open Eio.Std.

But this is an easy fix for anyone.

In general this is a very promising approach. A few specialists can provide Nix-enabled templates for OCaml and many people can benefit from a super-simple first-time setup process. It can significantly lower the barrier to entry even if we don't know Nix all that well. The value proposition of having all the dependencies automatically set up, is very significant. Thank you.

yawaramin commented 1 year ago

Although I must note that the initial discussion was about trying out an Eio port of Dream and I can't find any examples of that here :-)