nix-book/source/recipes/devshell/flake/main.adoc0
Amy de Buitléir 6b8580e53b temp
2025-09-06 16:42:22 +01:00

54 lines
1.3 KiB
Text

= Access a flake
////
$ mkdir tempwork
$ cd tempwork
$ cp ../flake.nix flake.nix
$ git add flake.nix
$ nix develop
$ git add flake.lock
$ git commit -a -m temp
////
In this example, we will use a flake defined in a remote git repo.
However, you can use any of the flake reference styles defined in <<#flakeref>>.
[source,nix,linenums,highlight='5,16']
.flake.nix
....
$# cat flake.nix
....
Let's take a closer look at the `buildInputs`.
....
$# grep buildInputs flake.nix | sed 's/ //g'
....
Why is the first part `hello-flake` and the last part `hello`?
The first part refers to the name we assigned in the input section of our flake,
and the last part is the name of the package or app we want.
You can find the outputs of a flake using the `nix flake show` command.
....
$# echo '$ nix flake show git+https://codeberg.org/mhwombat/hello-flake'
$# nix flake show git+https://codeberg.org/mhwombat/hello-flake --quiet | sed -e 's/\x1b\[[0-9;]*m//g'
....
Examining the output of this command,
we see that this flake provides both a package and an app called `hello`.
Here's a demonstration using the shell.
....
$ hello-flake
$# ../../../../../start-shell nix develop <<EOL
$ hello-flake
$# EOL
....
////
Good adoc0 scripts clean up after themselves.
$ cd .. ; rm -rf tempwork # clean up
////