jetify-com / devbox

Instant, easy, and predictable development environments
https://www.jetify.com/devbox/
Apache License 2.0
8.61k stars 197 forks source link

[Bug]: installing devbox with Determinate Nix on macOS yields "error: attribute 'nixpkgs' in selection path 'nixpkgs.devbox' not found" #1348

Open bklebe opened 1 year ago

bklebe commented 1 year ago

Current Behavior (bug) Following the installation guide for Devbox at https://www.jetpack.io/devbox/docs/installing_devbox/, I first installed Nix via the Determinate Nix Installer:

curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- install

After it completed and I verified that the nix command was installed, I ran nix-env -iA nixpkgs.devbox to install Devbox on my Mac:

$ nix-env -iA nixpkgs.devbox
error: attribute 'nixpkgs' in selection path 'nixpkgs.devbox' not found

After some googling it seems this is related to channels. Any idea what's wrong with my setup? I would appreciate any help that's available.

Expected Behavior (fix) Nix installs Devbox.

Additional context I'm running Nix 2.15.0 on macOS Ventura 13.5.

bklebe commented 1 year ago

It looks like I can get Devbox as a Flake by running nix profile install nixpkgs#devbox. Is this the appropriate way to install Devbox with the Determinate Nix Installer? Happy to PR the docs if so.

savil commented 1 year ago

@bklebe sorry for the delayed response. I'll need to look into why the Determinate Systems installer isn't working. I have nix 2.13 installed via the official nix installer on macOS 13.4, and it seemed to work:

savil@Savil-Srivastavas-MacBook-Pro ~> nix-env -iA nixpkgs.devbox
installing 'devbox-0.4.2'
this path will be fetched (5.05 MiB download, 16.73 MiB unpacked):
  /nix/store/bfq38khmfpsrhipvignfzj167ly2av2s-devbox-0.4.2
copying path '/nix/store/bfq38khmfpsrhipvignfzj167ly2av2s-devbox-0.4.2' from 'https://cache.nixos.org'...
building '/nix/store/g2rl3xg2k77r4rpgfm08rdnb7ayz9hfw-user-environment.drv'...

One thing to note is that the nixpkgs.devbox is severely out of date. Version 0.4.2 is super old. We need to update the nixpkgs repository.

I'd strongly recommend installing it via the curl -fsSL https://get.jetpack.io/devbox | bash on Mac OS.

While it does have the downside of not being "managed by nix", our installer will help manage devbox versions for you and give you a head's up when a new update is pending. Might that work for you?

bklebe commented 1 year ago

No worries about the delayed response. I file issues mostly so I can keep track of things to come back to later for myself. Helpful people responding is a nice bonus :)

I'd strongly recommend installing it via the curl -fsSL https://get.jetpack.io/devbox | bash on Mac OS.

While it does have the downside of not being "managed by nix", our installer will help manage devbox versions for you and give you a head's up when a new update is pending. Might that work for you?

I really appreciate the help, but I would say that doesn't fit my needs at the moment. What I wanted with Devbox is a tool for declaratively managing the application runtime environment from development to production deployment. In particular, I need to be able to generate more complex containers from images other than debian-slim. Ideally I would like to be able to use a development image as the base for a production image. It seems like Devbox is not ready to supplant Nix for this use case.

I installed Devbox via Nix for two reasons: one, I wanted to learn more about Nix, and two, I assumed that since Devbox is built on Nix and presumably developed by Nix users that Nix would be the best way to install it. I don't have a particular aversion to curl | sh from a security perspective, but I've never liked letting applications of all kinds spray files around willy nilly, polluting the system with state and configuration that can be a real pain to track down later if you want to reproduce an application's behavior somewhere else or even just remove it entirely. Nix seems to me like a way to avoid that, and it seemed like Devbox would be a good package to experiment with.

Devbox so far has been a really great entrypoint into Nix for me, which I've tried and failed to learn several times. All the work you've done to make Nix more accessible is incredibly valuable and I appreciate it a lot.

savil commented 1 year ago

Thanks for sharing the container use-case. Very helpful to know.

Yes, today, we don't make it easy to generate a dev versus prod image. The debian-slim one that's generated is more a "starter Dockerfile" to get one going.

We could leverage nix's dockerTools by generating a .nix file (analogous to the flake.nix we generate for a project's shell environment). But: (1) we don't currently have dev versus prod modes (to separate packages, envs, etc. for dev versus prod), and (2) from experience, cross-compiling can be painful. Making this work better is on our radar, in general. Part of Devbox's goals are to make it much easier to leverage the nix tooling.

In general, Devbox works well complementary to nix:

I've never liked letting applications of all kinds spray files around willy nilly, polluting the system with state and configuration that can be a real pain to track down later if you want to reproduce an application's behavior somewhere else or even just remove it entirely.

This makes sense. FWIW, we install a bash script we call the "installer" in /usr/local/bin, which is what users execute when they run "devbox". This delegates to the actual golang binary for all commands. The installer helps track when new updates are available, and aides in the self-update procedure.

Other than that, we follow the XDG Base Directory specification, and locate files and artifacts in the relevant XDG_{FOLDER_KIND}/devbox directory. So, cleanup is relatively easy. Aside fom the "installer" part, this would be the same even if you install devbox via nix.

bklebe commented 1 year ago

Interesting, good to know that the installation is fairly minimal. I probably should have audited the script myself 😅 I just didn’t realize the version in nixpkgs was out of date.

icorbett commented 6 months ago

I just ran into this same problem with a fresh install of nix 2.20.5 with the Determinate Installer v0.17.1.

Unlike the original report I see that the latest version of nixpkgs.devbox appears to be available.

% nix search nixpkgs devbox
* legacyPackages.x86_64-darwin.devbox (0.10.4)
  Instant, easy, predictable shells and containers.

The install error remains the same.

% nix-env -iA nixpkgs.devbox
error: attribute 'nixpkgs' in selection path 'nixpkgs.devbox' not found

This is a little disappointing considering the instructions seem to claim this is supported. I hoped that this toolchain would allow me to bypass a policy disallowing curl | bash.

If there is anything I can do to contribute to overcoming this error I am happy to do so. I have had a great experience with devbox and would love to share it more broadly!

Update:

I kept digging and discovered that this may be caused by the fact that the Determinate Installer does not set up any nixpkgs channel seen in the empty response below.

% nix-channel --list
%

Experimentally adding the nixpkgs-unstable channel followed by an update provides a different outcome:

% nix-channel --add https://nixos.org/channels/nixpkgs-unstable
% nix-channel --list
nixpkgs https://nixos.org/channels/nixpkgs-unstable
% nix-channel --update
unpacking channels...
% nix-env -iA nixpkgs.devbox --dry-run
(dry run; not doing anything)
installing 'devbox-0.10.4'

Would it be appropriate to update the NixOS/Nixpkgs docs to recommend using the flake install for any system without a channel installed? Ref: https://www.jetify.com/devbox/docs/installing_devbox/