nix-book/source/hello-flake.adoc0
Amy de Buitléir c800974e93 initial commit
2023-06-12 17:54:20 +01:00

53 lines
1.5 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.

== Hello, flake!
Before learning to write Nix flakes, lets learn how to use them. Ive
created a simple example of a flake in this git
https://codeberg.org/mhwombat/hello-flake[repository]. To run this
flake, you dont need to install anything; simply run the command below.
The first time you use a flake, Nix has to fetch and build it, which
may take time. Subsequent invocations should be instantaneous.
....
$ nix run "git+https://codeberg.org/mhwombat/hello-flake"
....
Thats a lot to type every time we want to use this package. Instead, we
can enter a shell with the package available to us, using the
`nix shell` command.
....
$ nix shell "git+https://codeberg.org/mhwombat/hello-flake"
....
In this shell, the command is on our `$PATH`, so we can execute the
command by name.
....
$ hello-flake
....
Nix didnt _install_ the package; it merely built and placed it in a
directory called the ``Nix store''. Thus we can have multiple versions
of a package without worrying about conflicts. We can find out the
location of the executable, if were curious.
....
$ which hello-flake
....
Once we exit that shell, the `hello-flake` command is no longer
directly available.
....
$# echo '$ exit'
$# echo '$ hello-flake'
sh: line 3: hello-flake: command not found
....
However, we can still run the command using the store path we found
earlier. Thats not particularly convenient, but it does demonstrate
that the package remains in the store for future use.
....
/nix/store/0xbn2hi6h1m5h4kc02vwffs2cydrbc0r-hello-flake/bin/hello-flake
....