nix-book/source/shell-recipes/_include.adoc0
Amy de Buitléir fb453b751f initial commit
2023-06-12 16:37:53 +01:00

112 lines
2 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

== Nix shell recipes
=== Shell with access to a package from the Nixpkgs/NixOS repo
This shell provides access to two packages from nixpkgs: hello and
cowsay.
[source,nix,linenums]
....
include::0100-shell-with-nixpkgs.nix[]
....
Heres a demonstration using the shell.
....
$ nix-shell
$ hello
Hello, world!
$ cowsay "moo"
_____
< moo >
-----
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
....
The command-line equivalent would be `nix-shell -p hello cowsay`
=== Shell with access to a package defined in a remote git repo
[source,nix,linenums]
....
include::0150-shell-with-git-nix-pkg.nix[]
....
Heres a demonstration using the shell.
....
$ nix-shell
$ hello-nix
Hello from your nix package!
....
=== Shell with access to a flake
[source,nix,linenums]
....
include::0200-shell-with-flake.nix[]
....
Heres a demonstration using the shell.
....
$ nix-shell
$ hello-flake
Hello from your flake!
....
=== Shell with access to a specific revision of a flake
[source,nix,linenums]
....
include::0250-shell-with-flake-rev.nix[]
....
Heres a demonstration using the shell.
....
$ nix-shell
$ hello-flake
Hello from your flake!
....
=== Shell with access to a Haskell package on your local computer
This shell provides access to three Haskell packages that are on my hard
drive.
[source,nix,linenums]
....
include::0300-shell-haskell-local.nix[]
....
=== Shell with access to a Haskell package on your local computer, with interdependencies
This shell provides access to four Haskell packages that are on my hard
drive. The fourth package depends on the first three to build.
[source,nix,linenums]
....
include::0350-shell-haskell-local-deps.nix[]
....
=== Shell with an environment variable set
This shell has the environment variable FOO set to ``bar''
[source,nix,linenums]
....
include::0400-shell-with-env-var.nix[]
....
Heres a demonstration using the shell.
....
$ nix-shell
$ echo $FOO
bar
....