Skip to content

[remove nixpkgs] add toPath, and edit devbox.lock only on update command #1256

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

Merged
merged 6 commits into from
Jul 7, 2023

Conversation

savil
Copy link
Collaborator

@savil savil commented Jul 7, 2023

Summary

This PR rolls in a few fixes:

  1. Add toPath to builtins.fetchClosure
    • lets us remove --impure flag in nix print-dev-env
  2. Add ca_store_path to devbox.lock
    • Because this is system-dependent, and is calculated locally, a devbox update will only update the user's system's ca_store_path.
    • This is good for team-mates on the same system, and to avoid the slow nix store make-content-addressed <path> call on each devbox shell/run/shellenv.
  3. Only update devbox.lock during devbox update.
    • Previously, it would update system info on devbox shell/run/shellenv.
  4. Simplify devbox.lock schema's SystemInfo to have StorePath and CAStorePath. These are used as fromPath and toPath in builtins.fetchClosure.

Miscellaneous changes:

  1. I remove actionlint from the devbox.json. It is not core to our workflows, and I am working with very minimal space on devbox cloud VM. This reduces "out of space errors" marginally.

How was it tested?

In examples/development/go/hello-world:
devbox update and devbox shell

The devbox.lock diff is now

❯ git diff
diff --git a/examples/development/go/hello-world/devbox.lock b/examples/development/go/hello-world/
devbox.lock
index 34556d3f..168874db 100644
--- a/examples/development/go/hello-world/devbox.lock
+++ b/examples/development/go/hello-world/devbox.lock
@@ -2,9 +2,18 @@
   "lockfile_version": "1",
   "packages": {
     "[email protected]": {
-      "last_modified": "2023-05-01T16:53:22Z",
-      "resolved": "github:NixOS/nixpkgs/8670e496ffd093b60e74e7fa53526aa5920d09eb#go_1_19",
-      "version": "1.19.8"
+      "last_modified": "2023-05-03T02:55:54Z",
+      "resolved": "github:NixOS/nixpkgs/0d373d5af960504dd60c3d06c65e553b36ef29d8#go_1_19",

+      "version": "1.19.8",
+      "systems": {
+        "aarch64-darwin": {
+          "store_path": "/nix/store/7m99ip3616l3z670y83p34r3plwd4iq1-go-1.19.8"
+        },
+        "x86_64-linux": {
+          "store_path": "/nix/store/r0x0agq0vwn0p6z99vkkvn8l8a8idzsb-go-1.19.8",
+          "ca_store_path": "/nix/store/ns557l24yf1f16f9jvbmxv57qdkkn2mj-go-1.19.8"
+        }
+      }
     }
   }
-}
\ No newline at end of file
+}

// we'll need to progressively add it to a project's lockfile.
needsLocalStorePath = userSysInfo.LocalStorePath == ""
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line 119 to line 128 the logic is a bit hard to follow, since you have if !needsSysInfo, needsLocalStorePath, if needsSysInfo...

Can we flatten this a bit? Something like:

        var userSysInfo
        var localStorePath
	if featureflag.RemoveNixpkgs.Enabled() {
		userSysInfo = d.lockfile.Packages[pkg.Raw].Systems[userSystem]
		if userSysInfo != nil {
			localStorePath = userSysInfo.LocalStorePath
		}
	}

         if userSysInfo == nil { ... }
         if localStorePath == "" { ... }

@savil savil requested a review from mikeland73 July 7, 2023 01:08
@savil savil marked this pull request as ready for review July 7, 2023 01:09
Copy link
Collaborator

@gcurtis gcurtis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm finding some of the new terms a bit confusing. Could we make them match what Nix calls them?

  • BinaryStorePath - this can just be StorePath. There isn't any difference between a path in a remote binary cache and a local store.
  • LocalStorePath - it looks like this is just the content-addressed version of the store path. Could we call it CAStorePath (or ContentAddressedStorePath if CA sounds like certificate)?
  • BinaryStoreBinaryCache

// Example:
// > nix store make-content-addressed /nix/store/r2jd6ygnmirm2g803mksqqjm4y39yi6i-git-2.33.1
// rewrote '/nix/store/r2jd6ygnmirm2g803mksqqjm4y39yi6i-git-2.33.1' to '/nix/store/ldbhlwhh39wha58rm61bkiiwm6j7211j-git-2.33.1'
var contentAddressedRegex = regexp.MustCompile(`rewrote\s'[\/a-z0-9-\.]+'\sto\s'([a-z0-9-\/\.]+)'`)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does nix store make-content-addressed --json work?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yeah, good call. Will try that...

Comment on lines +15 to +16
"/nix/store/r2jd6ygnmirm2g803mksqqjm4y39yi6i-git-2.33.1",
"/nix/store/ldbhlwhh39wha58rm61bkiiwm6j7211j-git-2.33.1",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does Nix automatically download these if they're not in the store yet?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep

"testing"
)

func TestContentAddressedPath(t *testing.T) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

@savil
Copy link
Collaborator Author

savil commented Jul 7, 2023

I'm finding some of the new terms a bit confusing. Could we make them match what Nix calls them?

  • BinaryStorePath - this can just be StorePath. There isn't any difference between a path in a remote binary cache and a local store.
  • LocalStorePath - it looks like this is just the content-addressed version of the store path. Could we call it CAStorePath (or ContentAddressedStorePath if CA sounds like certificate)?
  • BinaryStoreBinaryCache

Sounds good to me. Don't feel strongly about the current names (except I didn't want it to be "fromPath" and "toPath", since those don't make sense outside the context of fetchClosure)

Copy link
Collaborator Author

@savil savil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All CICD has passed. Going to make a small "rename" I missed out and then land...

StorePath string `json:"store_path,omitempty"`
// CAStorePath is the content-addressed path for the nix package in /nix/store
// It is of the form <hash>-<name>-<version>
CAStorePath string `json:"local_store_path,omitempty"`
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, forgot to rename the key to ca_store_path

// Check if the system info is missing for the user's system.
sysInfo := d.lockfile.Packages[pkg.Raw].Systems[userSystem]
if sysInfo == nil {
d.lockfile.Packages[pkg.Raw] = newEntry
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, could this override an existing (different) system that already has a CA path?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right! Much obliged 🙏🏾

sending fix: #1259

}

// Check if the package's system info is missing, or not complete.
if featureflag.RemoveNixpkgs.Enabled() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of the logic in this block could be encapsulated in lock file. Maybe:

if existing.CanBeUpdated(newEntry) {
  d.lockfile.Update(existing, newEntry)
}

or something like that. It could deal with version changes and also missing system stuff.

That way we could make Package.Systems semi-private. (It still needs to be exported because it is part of the JSON)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, is this logic block missing profile install/uninstall? e.g. if a package previously required nixpkgs and we replace it with one that does not require it, do we want to update the profile?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I agree this could likely be moved into the lock package. In general, I think quite a bit of the update code (beyond this block) could be better encapsulated. I may not have time to get to it though...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, is this logic block missing profile install/uninstall? e.g. if a package previously required nixpkgs and we replace it with one that does not require it, do we want to update the profile?

🤔 yeah, this one I am unsure about. In theory, the package's binary should be the exact same.

Its also why I think it was okay and/or put a question mark after using InputAddressedPath in the Package.Installable here.

@gcurtis would you have an opinion?

savil added a commit that referenced this pull request Jul 7, 2023
… and ContentAddressedPath, and s/BinaryStore/BinaryCache (#1257)

## Summary

This PR is a follow up to this request from @gcurtis:

#1256 (review)

BUT having `NixStorePath` and `ContentAddressedPath` seemed odd since
content-addressed paths
are also nix store paths. So, in this PR, I'm explicit about
`NixStorePath` being
`InputAddressedPath`.


Also - changed `BinaryStore` to `BinaryCache`.

**RFC**:
I didn't change the `lock.SystemInfo` struct, I've left it as:
```
type SystemInfo struct {
	// StorePath is the input-addressed path for the nix package in /nix/store
	// It is the cache key in the Binary Cache Store (cache.nixos.org)
	// It is of the form <hash>-<name>-<version>
	// <name> may be different from the canonicalName so we store the full store path.
	StorePath string `json:"store_path,omitempty"`
	// CAStorePath is the content-addressed path for the nix package in /nix/store
	// It is of the form <hash>-<name>-<version>
	CAStorePath string `json:"ca_store_path,omitempty"`
}
```

I think this could be okay, because the default `store_path` for nix is
input-addressed, for now at least.

If you'd like I can change `StorePath` to be explicitly:
```
InputAddrStorePath string `json:"input_addr_path, omitempty"
ContentAddrStorePath string `json:"content_addr_path, omitempty"
```

Let me know!

## How was it tested?

compiles
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants