Skip to content
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

Add support for Nix build environment #338

Merged
merged 12 commits into from
Jan 25, 2024
Merged

Add support for Nix build environment #338

merged 12 commits into from
Jan 25, 2024

Conversation

m15a
Copy link
Contributor

@m15a m15a commented Jan 4, 2024

related: none

A small contribution for Nix users to indicate if nix develop shell is activated in their prompt.

How to test pre-release?

☠️ Feature can be unstable and break your prompt!

fisher install m15a/pure@feat/nixdevshell   # branch name
set --universal pure_symbol_nixdevshell_prefix ❄️
mkdir /tmp/some_nix_project
nix flake init             # nix flake is required
echo 'use flake' > .envrc  # direnv and nix-direnv is required
direnv allow

Then your prompt looks like

❄impure ❯

First contribution?

Check the 👍 Contribute section and the contributing guide.

Specs

New config in conf.d/pure.fish

_pure_set_default pure_enable_nixdevshell true
_pure_set_default pure_symbol_nixdevshell_prefix "❄️"
_pure_set_default pure_color_nixdevshell_prefix brblue
_pure_set_default pure_color_nixdevshell_status pure_color_mute

Documentation

Usage

set --universal pure_enable_nixdevshell true            # enable/disable this featureset --universal pure_symbol_nixdevshell_prefix ❄️       # set your favorite prefix iconset --universal pure_color_nixdevshell_prefix brblue  # set your favorite color for prefix symbolset --universal pure_color_nixdevshell_status pure_color_mute  # set your favorite color for nix dev shell status

Acceptance Checks

  • documentation is up-to-date:
  • feature flag is present in conf.d/pure.fish ;
  • symbol is present in conf.d/pure.fish ;
  • tests are passing (I can help you 🤗 ):
  • customization is available ;
  • feature is implemented.

Copy link
Member

@edouard-lopez edouard-lopez left a comment

Choose a reason for hiding this comment

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

Thanks for the submission!

As it's an OS-specific feature, I won't enable it by default as it could impact other OSes (see comments).

Check out tests/_pure.test.fist to see how to test your feature settings:

pure/tests/_pure.test.fish

Lines 318 to 328 in 586869b

@test "configure: pure_enable_k8s" (
set --erase pure_enable_k8s
source (status dirname)/../conf.d/pure.fish
echo $pure_enable_k8s
) = false
@test "configure: pure_symbol_k8s_prefix" (
set --erase pure_symbol_k8s_prefix
source (status dirname)/../conf.d/pure.fish
echo $pure_symbol_k8s_prefix
) = ""

Then you can have a look at tests/_pure_prompt_k8s.test.fish to see how you can test the feature itself
https://github.com/pure-fish/pure/blob/586869bdf0f336d8fdcc4efd4a169a9f53a10a36/tests/_pure_prompt_k8s.test.fish

When that's done, we will need to restrict executions of the feature's tests in CI to the Nix job only, i.e detecting the OS with uname -s

if test (uname -s) = Linux
@test "_pure_is_inside_container: detect with pid method" (

conf.d/pure.fish Outdated Show resolved Hide resolved
conf.d/pure.fish Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
functions/_pure_prompt_nixdevshell.fish Outdated Show resolved Hide resolved
@m15a
Copy link
Contributor Author

m15a commented Jan 5, 2024

When that's done, we will need to restrict executions of the feature's tests in CI to the Nix job only, i.e detecting the OS with uname -s

As I mentioned above, Nix is not only available on NixOS. So IMHO we don't need to restrict CI tests.

@m15a
Copy link
Contributor Author

m15a commented Jan 5, 2024

I've introduced another config variable so that one can customize colors of prefix symbol (by pure_color_nixdevshell_prefix) and nix dev shell status (by pure_color_nixdevshell_status).

@m15a
Copy link
Contributor Author

m15a commented Jan 5, 2024

Because on my system bash is at different path, I modified makefile:

diff --git a/makefile b/makefile
index a4368e5..6822660 100644
--- a/makefile
+++ b/makefile
@@ -1,7 +1,7 @@
 #!/usr/bin/make -sf

 # force use of Bash
-SHELL := /bin/bash
+SHELL := /usr/bin/env bash
 INTERACTIVE=true

and then ran tests using docker:

make build-pure-on FISH_VERSION=3.6.4
make test-pure-on FISH_VERSION=3.6.4

All tests passed.

@kothavade
Copy link

kothavade commented Jan 17, 2024

@m15a would you be willing to add a feature where only the icon is shown, but the status text (eg impure) is not? i like the visual feedback of the icon, but generally do not need the actual output of IN_NIX_SHELL.

i can also send a separate PR for that once this is merged if @edouard-lopez is okay with the added feature, but having it be in this PR would be easier.

@edouard-lopez
Copy link
Member

Could you add the makefile change, it's a more robust approach. I would prefer another PR to keep them small.

I would look at this one Thursday, thanks for your patience

@edouard-lopez edouard-lopez merged commit bf7265f into pure-fish:master Jan 25, 2024
6 checks passed
@edouard-lopez
Copy link
Member

@m15a Note that I renamed the color variable

-pure_color_nixdevshell_status
+pure_color_nixdevshell_symbol

c6e59a3

@m15a
Copy link
Contributor Author

m15a commented Jan 26, 2024

@edouard-lopez Thanks!!

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

Successfully merging this pull request may close these issues.

3 participants