Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failing to add packages due to Go unmarshalling error #1767

Closed
emanguy opened this issue Jan 31, 2024 · 1 comment · Fixed by #1770
Closed

Failing to add packages due to Go unmarshalling error #1767

emanguy opened this issue Jan 31, 2024 · 1 comment · Fixed by #1770
Assignees
Labels
bug Something isn't working

Comments

@emanguy
Copy link

emanguy commented Jan 31, 2024

What happened?

After running devbox init, I attempt to add any package to it via devbox add but it fails with an unmarshalling error. Presumably it's trying to deserialize some JSON but Nix updated the format or something? I had Nix installed on my machine already, so maybe it's an incompatible version or something.

Steps to reproduce

  1. Install Nix on MacOS using their official installer: https://nixos.org/download#nix-install-macos
  2. Install devbox via the official script: https://www.jetpack.io/devbox/docs/quickstart/
  3. Run devbox init to start a devbox.json
  4. Run devbox add go to add the go package to devbox.json

Command

add

devbox.json

{
  "packages": [],
  "shell": {
    "init_hook": [
      "echo 'Welcome to devbox!' > /dev/null"
    ],
    "scripts": {
      "test": [
        "echo \"Error: no test specified\" && exit 1"
      ]
    }
  }
}

Devbox version

0.8.7

Nix version

2.20.1

What system does this bug occur on?

macOS (Intel)

Debug logs

I've edited the output to mask some file names, but semantically it's the same.

2024/01/31 15:59:37 findProjectDir: path is
2024/01/31 15:59:37 finding devbox config in dir: /Users/erittenhouse/Desktop/PROJECT/FOLDER/GIT_REPO
2024/01/31 15:59:37 findProjectDir: path is
2024/01/31 15:59:37 finding devbox config in dir: /Users/erittenhouse/Desktop/PROJECT/FOLDER/GIT_REPO
2024/01/31 15:59:38 findProjectDir: path is
2024/01/31 15:59:38 finding devbox config in dir: /Users/erittenhouse/Desktop/PROJECT/FOLDER/GIT_REPO
Info: Adding package "go@latest" to devbox.json

Error: There was an error installing nix packages
source: json: cannot unmarshal object into Go struct field ProfileListOutput.elements of type []nixprofile.ProfileListElement

2024/01/31 15:59:38
ExecutionID:1e390847f87b4708b43062a4736f5eed

2024/01/31 15:59:38 findProjectDir: path is
2024/01/31 15:59:38 finding devbox config in dir: /Users/erittenhouse/Desktop/PROJECT/FOLDER/GIT_REPO

@emanguy emanguy added bug Something isn't working triage Issue needs triage labels Jan 31, 2024
@savil
Copy link
Collaborator

savil commented Jan 31, 2024

Thanks for filing this. Looks like the latest nix version changed how the nix profile output is represented:

From the release notes:

nix profile now allows referring to elements by human-readable names #8678

nix profile now uses names to refer to installed packages when running list, remove or upgrade as opposed to indices. Profile element names are generated when a package is installed and remain the same until the package is removed.

Warning: The manifest.nix file used to record the contents of profiles has changed. Nix will automatically upgrade profiles to the new version when you modify the profile. After that, the profile can no longer be used by older versions of Nix.

We'll need to update Devbox and ship a release...

@gcurtis gcurtis removed the triage Issue needs triage label Feb 1, 2024
savil added a commit that referenced this issue Feb 1, 2024
## Summary

The latest nix version (2.20) changed how the nix profile output is
represented:

From the [release
notes](https://nixos.org/manual/nix/stable/release-notes/rl-2.20):

> nix profile now allows referring to elements by human-readable names
NixOS/nix#8678

> [nix
profile](https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-profile)
now uses names to refer to installed packages when running
[list](https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-profile-list),
[remove](https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-profile-remove)
or
[upgrade](https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-profile-upgrade)
as opposed to indices. Profile element names are generated when a
package is installed and remain the same until the package is removed.

> Warning: The manifest.nix file used to record the contents of profiles
has changed. Nix will automatically upgrade profiles to the new version
when you modify the profile. After that, the profile can no longer be
used by older versions of Nix.

and for `nix search`:
> Disallow empty search regex in nix search
[#9481](NixOS/nix#9481)

> [nix
search](https://nixos.org/manual/nix/stable/command-ref/new-cli/nix3-search)
now requires a search regex to be passed. To show all packages, use ^.


TODOs:
- [x] update `nix.readManifest` to handle the new format
- [x] `nix search` requires a regex to be passed
- [x] manually test on nix < 2.20 on devbox.sh to verify the older nix
still works

Fixes #1767 

## How was it tested?

CICD should pass

Installed nix 2.20.1 locally and am using Devbox with it to add, remove
packages and run scripts and shell.

verified flake updating works:
1. `examples/flakes/remote`. Did `devbox shell`, dropped the `v0.43.1`
from process-compose flake, did `devbox update`, and verified that
`process-compose` now had the latest version (IIRC `0.80+`)
2. `examples/flakes/php`. Did `devbox shell`, edited the flake to drop
`ds` and did `devbox update`. Verified no `ds` in `php -m | grep ds`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging a pull request may close this issue.

3 participants