-
Notifications
You must be signed in to change notification settings - Fork 265
[flakes] add and remove packages, individually #597
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. |
dc76cc9
to
bb0f540
Compare
bb0f540
to
d8bbd2c
Compare
## Summary These functions are no longer going to be used. Superseded by #597 ## How was it tested? compiles
1681324
to
2da5340
Compare
d8bbd2c
to
edf3a68
Compare
edf3a68
to
9cf1a8a
Compare
## Summary In #597, I wanted to introduce a file called `packages.go` (currently, called install.go but that's a poor substitute IMO). This file `pkgs.go` would be confusing to have at the same time. Since it is unused, lets remove it. It can be brought back whenever needed. ## How was it tested? compiles
e03c0f6
to
ef5c19b
Compare
ef5c19b
to
86cbc13
Compare
internal/impl/packages.go
Outdated
} | ||
|
||
// nixProfileListItems returns a list of the installed packages | ||
func (d *Devbox) nixProfileListItems() ([]*nixProfileListItem, error) { |
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 think this and below code is better moved to nix/profile.go
so it'll be nix.ProfileListItems()
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 think package name collisions are the only must-fix thing. Is there a performance difference in invoking Nix for each package vs. doing them all at once?
internal/nix/profile.go
Outdated
// Using an example: | ||
// 0 github:NixOS/nixpkgs/52e3e80afff4b16ccb7c52e9f0f5220552f03d04#legacyPackages.x86_64-darwin.go_1_19 github:NixOS/nixpkgs/52e3e80afff4b16ccb7c52e9f0f5220552f03d04#legacyPackages.x86_64-darwin.go_1_19 /nix/store/w0lyimyyxxfl3gw40n46rpn1yjrl3q85-go-1.19.3 | ||
// 1 github:NixOS/nixpkgs/52e3e80afff4b16ccb7c52e9f0f5220552f03d04#legacyPackages.x86_64-darwin.vim github:NixOS/nixpkgs/52e3e80afff4b16ccb7c52e9f0f5220552f03d04#legacyPackages.x86_64-darwin.vim /nix/store/gapbqxx1d49077jk8ay38z11wgr12p23-vim-9.0.0609 | ||
lines := strings.Split(strings.TrimSpace(string(out)), "\n") |
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.
A potential way to simplify the parsing is to use a bufio.Scanner
. For example:
out, err := cmd.StdoutPipe()
scanner := bufio.NewScanner(out)
scanner.Split(bufio.ScanWords)
for scanner.Scan() {
index, err := strconv.Atoi(scanner.Text())
if !scanner.Scan() {
return errors.New("incomplete nix profile list line")
}
unlockedReference := scanner.Text()
if !scanner.Scan() {
return errors.New("incomplete nix profile list line")
}
lockedReference := scanner.Text()
if !scanner.Scan() {
return errors.New("incomplete nix profile list line")
}
nixStorePath := scanner.Text()
items = append(items, ...)
}
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.
Much nicer now, thanks for the tip to use scanner (and helpful code).
internal/nix/profile.go
Outdated
) | ||
} | ||
|
||
packageName := parts[len(parts)-1] |
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 won't necessarily be unique. For example, python310Packages.numpy
and python311Packages.numpy
will both become numpy
. I think that'll affect the maps that use the package name as a key.
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.
Good point.
I could parse it the other direction assuming the prefix will always be legacyPackages.<platform>
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.
Added a test case and updated code to fix this.
14886d2
to
5e1f3b0
Compare
Summary
This PR adds the following top-level functions:
devbox.addPackagesToProfile
: used duringdevbox add
anddevbox shell
.devbox.removePackagesFromProfile
: used duringdevbox rm
.This PR's size comes from inspecting the results of
nix profile list
, which we parse intonix.ProfileListItem
structs. We use this information in two ways:devbox.addPackagesToProfile
, we inspect list ofnix.ProfileListItem
to determine which of thedevbox.json
packages are pending installation.devbox.removePackagesFromProfile
, we need the "attribute path" of the package, which we derive from itsnix.ProfileListItem
UX:
The UX can be improved, but I didn't invest in it since the PR size is already large. That can be a discussion and a follow up PR.
TODOs for future PRs:
github:NixOS/nixpkgs/<commit>
URL can leveragenixed
cache servicedevbox add
we always listnixpkgs
as being installed, which is kinda odd. Can we check that it has been pre-fetched already?bin
,lib
,share
, but with flakes profiles we just link tobin
andshare
How was it tested?
Installing looks like below. I did not use the
stepper
component so that we show the output of each individual install.