mirror of
https://codeberg.org/mhwombat/nix-book.git
synced 2025-12-27 00:34:58 +08:00
49 lines
1.2 KiB
Text
49 lines
1.2 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,8,16']
|
|
.flake.nix
|
|
....
|
|
$# cat flake.nix
|
|
....
|
|
|
|
Line 5 adds `hello-flake` as an input to this flake.
|
|
Line 8 allows the output function to reference `hello-flake`.
|
|
Line 16 adds `hello-flake` as a build input for this flake.
|
|
|
|
Let's take a closer look at the `buildInputs` expression from line 16.
|
|
|
|
....
|
|
$# grep buildInputs flake.nix | sed 's/ //g; s/.*\[//; s/\].*//'
|
|
....
|
|
|
|
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.
|
|
(See <<_flake_outputs>> for how to identify flake outputs.)
|
|
|
|
Here's a demonstration using the shell.
|
|
|
|
....
|
|
$ hello-flake # Fails; dependency not available
|
|
$# start-shell nix develop <<EOL
|
|
$ hello-flake # Works in development environment
|
|
$# EOL
|
|
....
|
|
|
|
////
|
|
Good adoc0 scripts clean up after themselves.
|
|
$ cd .. ; rm -rf tempwork # clean up
|
|
////
|