Skip to content

Commit

Permalink
stdlib: add use_flake function (#847)
Browse files Browse the repository at this point in the history
I noticed some projects in the wild calling `use_flake` without sourcing
the `use_flake` function. It's time to add this to the stdlib.
  • Loading branch information
zimbatm committed Nov 28, 2021
1 parent 78fa3c0 commit 02b6d38
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
13 changes: 13 additions & 0 deletions man/direnv-stdlib.1
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,19 @@ If you have a \fB\fCdefault.nix\fR or \fB\fCshell.nix\fR these will be used by d
.PP
See http://nixos.org/nix/manual/#sec-nix-shell

.SS \fB\fCuse flake [<installable>]\fR
.PP
Load the build environment of a derivation similar to \fB\fCnix develop\fR\&.

.PP
By default it will load the current folder flake.nix devShell attribute. Or
pass an "installable" like "nixpkgs#hello" to load all the build dependencies
of the hello package from the latest nixpkgs.

.PP
Note that the flakes feature is hidden behind an experimental flag, which you
will have to enable on your own. Flakes is not considered stable yet.

.SS \fB\fCuse guix [...]\fR
.PP
Load environment variables from \fB\fCguix environment\fR\&.
Expand Down
11 changes: 11 additions & 0 deletions man/direnv-stdlib.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,17 @@ If you have a `default.nix` or `shell.nix` these will be used by default, but yo

See http://nixos.org/nix/manual/#sec-nix-shell

### `use flake [<installable>]`

Load the build environment of a derivation similar to `nix develop`.

By default it will load the current folder flake.nix devShell attribute. Or
pass an "installable" like "nixpkgs#hello" to load all the build dependencies
of the hello package from the latest nixpkgs.

Note that the flakes feature is hidden behind an experimental flag, which you
will have to enable on your own. Flakes is not considered stable yet.

### `use guix [...]`

Load environment variables from `guix environment`.
Expand Down
16 changes: 16 additions & 0 deletions stdlib.go
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,22 @@ const StdLib = "#!/usr/bin/env bash\n" +
" fi\n" +
"}\n" +
"\n" +
"# Usage: use_flake [<installable>]\n" +
"#\n" +
"# Load the build environment of a derivation similar to `nix develop`.\n" +
"#\n" +
"# By default it will load the current folder flake.nix devShell attribute. Or\n" +
"# pass an \"installable\" like \"nixpkgs#hello\" to load all the build\n" +
"# dependencies of the hello package from the latest nixpkgs.\n" +
"#\n" +
"# Note that the flakes feature is hidden behind an experimental flag, which\n" +
"# you will have to enable on your own. Flakes is not considered stable yet.\n" +
"use_flake() {\n" +
" watch_file flake.nix\n" +
" watch_file flake.lock\n" +
" eval \"$(nix print-dev-env --profile \"$(direnv_layout_dir)/flake-profile\" \"$@\")\"\n" +
"}\n" +
"\n" +
"# Usage: use_guix [...]\n" +
"#\n" +
"# Load environment variables from `guix environment`.\n" +
Expand Down
16 changes: 16 additions & 0 deletions stdlib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,22 @@ use_nix() {
fi
}

# Usage: use_flake [<installable>]
#
# Load the build environment of a derivation similar to `nix develop`.
#
# By default it will load the current folder flake.nix devShell attribute. Or
# pass an "installable" like "nixpkgs#hello" to load all the build
# dependencies of the hello package from the latest nixpkgs.
#
# Note that the flakes feature is hidden behind an experimental flag, which
# you will have to enable on your own. Flakes is not considered stable yet.
use_flake() {
watch_file flake.nix
watch_file flake.lock
eval "$(nix print-dev-env --profile "$(direnv_layout_dir)/flake-profile" "$@")"
}

# Usage: use_guix [...]
#
# Load environment variables from `guix environment`.
Expand Down

0 comments on commit 02b6d38

Please sign in to comment.