-
Notifications
You must be signed in to change notification settings - Fork 264
[shell] add packages within shell, leveraging nix-profile #188
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. |
8b711f3
to
513c9b4
Compare
boxcli/rm.go
Outdated
fmt.Print(successMsg) | ||
|
||
// Sadface. This doesn't seem to work within devbox shell for now. | ||
fmt.Println(" You may need to restart `devbox shell` for this to take effect.") |
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 that's reasonable.
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.
Fixed this via doing nix-env --install development.nix
again!
devbox.go
Outdated
@@ -49,13 +49,26 @@ func Open(dir string) (*Devbox, error) { | |||
return nil, errors.WithStack(err) | |||
} | |||
|
|||
// if dir is current directory, then get the full path | |||
if dir == "." { |
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.
Why?
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.
solved via #200. Removed this code.
nix/shell.go
Outdated
@@ -250,11 +258,13 @@ func (s *Shell) writeDevboxShellrc() (path string, err error) { | |||
OriginalInitPath string | |||
UserHook string | |||
PlanInitHook string | |||
NixProfileDir string |
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: ProfileBinDir
nix/shellrc.tmpl
Outdated
@@ -57,7 +61,7 @@ PATH="$( | |||
*) non_nix_path="${non_nix_path:+$non_nix_path:}${path_dir}" ;; | |||
esac | |||
done | |||
echo "${nix_path:+$nix_path:}${non_nix_path}" | |||
echo "{{ .NixProfileDir }}:${non_nix_path}" |
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.
nice!
devbox.go
Outdated
@@ -49,13 +49,26 @@ func Open(dir string) (*Devbox, error) { | |||
return nil, errors.WithStack(err) | |||
} | |||
|
|||
// if dir is current directory, then get the full path |
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.
Instead of only resolving .
, why not call filpath.Abs
on any directory, to ensure everything is an absolute path?
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.
solved via #200
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.
deleted this code
boxcli/add.go
Outdated
@@ -27,6 +30,31 @@ func addCmdFunc() runFunc { | |||
if err != nil { | |||
return errors.WithStack(err) | |||
} | |||
return box.Add(args...) | |||
|
|||
if err = box.Add(args...); err != 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.
I think you have too much logic in here for add
, rm
and shell
.
The goal of the devbox
library is that it can be used as an SDK that is equivalent to using the CLI. In other words, box.Add("package")
should be roughly the same as calling devbox add package
; similarly box.Remove("package")
should be roughly the same as calling devbox rm package
. But since you've added all this logic inside of the CLI, instead of inside of the library, that is no longer true.
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.
oh gotcha - sure I can move more logic inside the devbox
library.
Do we want user-messaging to happen inside the library as well i.e. the print statements? Should we consider passing in an io.Writer
in the constructor for box
in devbox.Open
?
nix/shell.go
Outdated
@@ -107,7 +110,7 @@ func rcfilePath(basename string) string { | |||
return filepath.Join(home, basename) | |||
} | |||
|
|||
func (s *Shell) Run(nixPath string) error { | |||
func (s *Shell) Run(nixShellFilePath string, srcDir string) 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 find this new interface for Run
slightly confusing. Can you elaborate on why we now need both of these to be passed in?
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 use it to construct the directory-for-profile-binaries i.e. srcDir + .devbox/profile/bin
It seems that the intention is for nix
package to simulate a go-sdk. In that case, this is maybe not the best API.
devbox.go
Outdated
box := &Devbox{ | ||
cfg: cfg, | ||
srcDir: dir, | ||
} | ||
return box, nil | ||
} | ||
|
||
func (d *Devbox) SourceDir() string { |
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'm not sure this needs to be public – I think you have to make it public right now because you implemented a lot of the logic outside of the Devbox SDK – if you move that logic to be internal, then you don't need to expose this.
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.
removed this function
3fa3da9
to
7e8a62e
Compare
a4901dc
to
8b8e7ab
Compare
beffd38
to
ac4992b
Compare
ac4992b
to
8dfb76f
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.
👍
if mode == uninstall { | ||
installingVerb = "Uninstalling" | ||
} | ||
fmt.Fprintf(d.writer, "%s nix packages. This may take a while...", installingVerb) |
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.
Can we just say, "updating nix packages"?
installedVerb = "removed" | ||
} | ||
|
||
successMsg := fmt.Sprintf("%s is now %s.", pkgs[0], installedVerb) |
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.
Just say "packages updated?"
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 considered that, but "updated package" has another meaning i.e. has been updated from version 1.0.1 to 1.0.2 so felt it better to be super explicit
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.
oh right, haven't thought about that hehe
devbox.go
Outdated
|
||
cmdStr := fmt.Sprintf( | ||
"--profile %s --install -f %s/.devbox/gen/development.nix", | ||
d.srcDir+"/"+profileDir, |
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.
filepath.join
?
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.
oh yes of course :)
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 audit other places in this PR too!
8dfb76f
to
40a2e33
Compare
…stall development.nix' again
40a2e33
to
8305051
Compare
Summary
Motivation:
We can define a custom nix-profile, and install packages scoped to this profile.
The goal is to make it easier to add packages when within devbox shell. Currently,
users need to exit the shell and restart it for the nix package to be installed - clearly
not ideal. With a nix-profile, if we install the package using that profile, then the
package's binary should be downloaded and visible within the shell.
Within
devbox shell
:PATH
.PATH
and skip manually adding each package.Limitations:
devbox add
within adevbox shell
, the user needs to manually executehash -r
to ensure the latest binaries are visible.ForFixed via reapplyingdevbox rm
within adevbox shell
, the user still needs to restart the shell. I'm not quite sure why thenix-env --profile <profile dir> --uninstall <pkg>
isn't working as intended.nix-env --profile <profile> -if development.nix
devbox add
andrm
when in a shell started from a parent directory will not work.DEVBOX_CONFIG_DIR
env-var when inside a shell, and use that value indevbox add
andrm
.How was it tested?
testdata/rust/rust-stable
:devbox shell
which openssl
and getting/usr/bin/openssl
devbox add openssl
which openssl
still reflects the non nix-store location. It has NOT yet been updated.hash -r
and thenwhich openssl
and see it point to a nix-store locationdevbox rm openssl
which openssl
still reflects the nix-store location. It has NOT yet been updated.devbox shell
and dowhich openssl
to verify it has been removed