Skip to content

Conversation

gcurtis
Copy link
Collaborator

@gcurtis gcurtis commented Sep 8, 2022

Summary

Add a shell.init_hook field to devbox.json which can contain arbitrary commands to run at shell startup.

{
  "packages": ["go"],
  "shell": {
    "init_hook": "echo hello from a hook!"
  }
}

This change also merges the shell package into nix, making it clearer that it handles Nix shells specifically. The nix.Shell function is replaced by the nix.Shell struct, which does everything that the shell.Shell struct did.

The new API looks something like:

sh, err := nix.DetectShell()
sh.UserInitHook = cfg.Shell.InitHook
sh.Run(nixPath)

Finally, we now build the devbox shellrc with a template since it was getting a bit complex.

How was it tested?

Adding a hook and running a shell.

Add a `shell.init_hook` field to devbox.json which can contain arbitrary
commands to run at shell startup.

	{
	  "packages": ["go"],
	  "shell": {
	    "init_hook": "echo hello from a hook!"
	  }
	}

This change also merges the `shell` package into `nix`, making it
clearer that it handles Nix shells specifically. The `nix.Shell`
function is replaced by the `nix.Shell` struct, which does everything
that the `shell.Shell` struct did.

The new API looks something like:

	sh, err := nix.DetectShell()
	sh.UserInitHook = cfg.Shell.InitHook
	sh.Run(nixPath)

Finally, we now build the devbox shellrc with a template since it was
getting a bit complex.
@gcurtis
Copy link
Collaborator Author

gcurtis commented Sep 8, 2022

Obviously also open to suggestions on how the devbox.json should look.

Copy link
Contributor

@loreto loreto left a comment

Choose a reason for hiding this comment

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

LGTM, let's just agree on the right schema for devbox.json

Copy link
Collaborator

@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.

nice!

I think I could use this in the rust planner in #97: I need to call rustup default <version> after the shell starts....

@gcurtis gcurtis merged commit 6f434d3 into main Sep 9, 2022
@gcurtis gcurtis deleted the gcurtis/hooks branch September 9, 2022 15:29
@Lagoja Lagoja added this to the 0.0.5 milestone Sep 9, 2022
@venkytv
Copy link

venkytv commented Sep 9, 2022

Awesome! Thank you!

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.

Allow setting ENV and other custom scripts on shell start
6 participants