-
Notifications
You must be signed in to change notification settings - Fork 248
[remove nixpkgs] part 2: generate flake.nix using builtins.fetchClosure #1209
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
Conversation
Current dependencies on/for this PR:
This comment was auto-generated by Graphite. |
eed5ad6
to
6f26857
Compare
ecbc74f
to
163ddb4
Compare
Sorry for the delay - I just remembered that I never reviewed this. I'll take a look tomorrow morning. |
163ddb4
to
3df3c5c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had some comments, but approving to keep the train moving.
internal/shellgen/flake_input.go
Outdated
allInputs = lo.Filter(allInputs, func(item *nix.Package, _ int) bool { | ||
// This is temporary, so that we can support the existing flake.nix.tmpl | ||
// as well as the new flake_remove_nixpkgs.nix.tmpl. | ||
return !featureflag.RemoveNixpkgs.Enabled() || item.SystemInfo() == nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't this just remove everything when the feature is enabled? In which case allInputs
could just be nil.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will continue to include packages (like local or remote flakes) that don't have system info
internal/shellgen/flake_package.go
Outdated
Name: attributePath, | ||
FromStore: nixosCacheURL, | ||
FromPath: filepath.Join("/nix/store", storeDir), | ||
// TODO add ToPath: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you looked at the builtins.storePath
function? If we're running in impure mode, then it might make things a little easier. It doesn't require a content-addressed hash and it will automatically use the Nix-configured binary caches (aka substituters). That'll make this work automatically with nixed in Devbox Cloud.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't yet. Thanks for the pointer. Will look into it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not blocking, but I would really want to avoid adding a new Package
struct. I also think system info should be part of resolve. Ideally system info can be abstracted away so that the whatever generates the flake can just get the data if it's present.
btw, you should assume that we will not be able to avoid nixpkgs for certain packages for the short and medium term, so we need to structure this in a clean way where both types can coexist.
3df3c5c
to
755eff3
Compare
@gcurtis addressed comments and made updates @mikeland73 Folded |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great! I really like how this ended up.
internal/nix/input.go
Outdated
pkg := &Package{ | ||
URL: *pkgURL, | ||
lockfile: locker, | ||
Raw: raw, | ||
normalizedPackageAttributePathCache: "", | ||
} | ||
|
||
return pkg |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, you can revert this if you want. You can also omit normalizedPackageAttributePathCache
if you used name fields.
internal/nix/input.go
Outdated
func (p *Package) IsInBinaryStore() bool { | ||
return p.isVersioned() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a better way to determine this? For example only true if lock file data has system info?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 yeah, we could add that check too. In my previous iteraiton of this PR, I was checking both p.isVersioned()
and "has system info".
I can add that here. It feels weird to possibly make network-calls in an if-statement but I understand the architecture better now so lets roll with it.
var err error | ||
shellPlan.FlakeInputs, err = flakeInputs(ctx, devbox) | ||
userPackages := devbox.PackagesAsInputs() | ||
pluginPackages, err := devbox.PluginManager().PluginInputs(userPackages) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll rename PluginInputs
and PackagesAsInputs
in a follow up.
Also, I'm thinking of changing plugins to encapsulate it more. Having plugins show up in shellgen package is not idael
Summary
See #1208 for motivation.
That previous PR handled the "writing the system info to the lockfile". In this PR:
flake.nix
fromflake_remove_nixpkgs.nix.tmpl
template.builtins.fetchClosure
to download the package's binary directly from the binary-cache-store (likecache.nixos.org
). This lets us bypassnixpkgs
for nix packages in the binary store.shellgen.flakePlan
.flakePlan
, we:a. filter
flakeInputs
to be those not in the binary store (like remote or local flakes)b. add a new field
Packages []*nix.Package
.In
nix.Package
, we have a few new methods specific to the BinaryStore, likeIsInBinaryStore
andPathInBinaryStore
.Testing note:
I was stymied in extensively testing this by:
cc @mikeland73
How was it tested?
Tested with
examples/development/go/hello-world
.For a more complex example, with a flake, the
examples/flakes/remote
produces thisflake.nix
: