-
Notifications
You must be signed in to change notification settings - Fork 93
feat(entrypoint): fixes/improvements to support nix run (devshell-as-flake-app)
#243
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
08309ca
fix: pass fully-rendered entrypoint to mkFlakeApp
tomeon c9e6468
fix: mkSetupHook no longer ignores its argument
tomeon 5d256c2
feat(env.bash): always export PRJ_ROOT
tomeon e8b8a80
feat(entrypoint): better "am I sourced?" logic
tomeon 33fee2a
fix(entrypoint): expand HOME, PRJ_ROOT only if set
tomeon cdac2c3
refactor(entrypoint): condense to single "exec"
tomeon 76aef52
refactor(entrypoint): extensible options handling
tomeon 78e7c94
feat(entrypoint): add --prj-root option
tomeon 45a6cc2
feat(entrypoint): add --env-bin option
tomeon fb76d5b
tests: add tests for devshell entrypoint script
tomeon 3cf289d
feat(flake): expose devshell entrypoint as app
tomeon d0601cb
feat: make 'env' submodules stringify as Bash code
tomeon 8e6041c
feat(devshell): support default "$PRJ_ROOT" value
tomeon edca0bb
docs: show how to use devshells as Nix apps
tomeon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| # Using a devshell as a Nix application | ||
|
|
||
| Devshells provide the attribute `flakeApp`, which contains an attribute set | ||
| suitable for use as an entry in the `apps` flake output structure. Export this | ||
| attribute under `apps.<system>.<myapp>`, and then you can run commands within | ||
| your devshell as follows: | ||
|
|
||
| ```sh | ||
| nix run '.#<myapp>' -- <devshell-command> <and-args> | ||
| ``` | ||
|
|
||
| For example, given the following `flake.nix`: | ||
|
|
||
| ```nix | ||
| { | ||
| inputs.devshell.url = "github:numtide/devshell"; | ||
| inputs.flake-utils.url = "github:numtide/flake-utils"; | ||
|
|
||
| outputs = { self, flake-utils, devshell, nixpkgs }: | ||
| flake-utils.lib.eachDefaultSystem (system: { | ||
| apps.devshell = self.outputs.devShells.${system}.default.flakeApp; | ||
|
|
||
| devShells.default = | ||
| let | ||
| pkgs = import nixpkgs { | ||
| inherit system; | ||
|
|
||
| overlays = [ devshell.overlays.default ]; | ||
| }; | ||
| in | ||
| pkgs.devshell.mkShell ({ config, ... }: { | ||
| commands = [ | ||
| { | ||
| name = "greet"; | ||
| command = '' | ||
| printf -- 'Hello, %s!\n' "''${1:-world}" | ||
| ''; | ||
| } | ||
| ]; | ||
| }); | ||
| }); | ||
| } | ||
| ``` | ||
|
|
||
| You can execute your devshell's `greet` command like this: | ||
|
|
||
| ```console | ||
| $ nix run '.#devshell' -- greet myself | ||
| Hello, myself! | ||
| ``` | ||
|
|
||
| ## Setting `PRJ_ROOT` | ||
|
|
||
| By default, the `PRJ_ROOT` environment variable is set to the value of the | ||
| `PWD` environment variable. You can override this by defining `PRJ_ROOT` in | ||
| `nix run`'s environment: | ||
|
|
||
| ```sh | ||
| PRJ_ROOT=/some/where/else nix run '.#<myapp>' -- <devshell-command> <and-args> | ||
| ``` | ||
|
|
||
| You can also use the `--prj-root` option: | ||
|
|
||
| ```sh | ||
| nix run '.#<myapp>' -- --prj-root /yet/another/path -- <devshell-command> <and-args> | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.