mirror of
https://codeberg.org/mhwombat/nix-book.git
synced 2025-12-27 08:44:56 +08:00
initial commit
This commit is contained in:
parent
ad8b58fa44
commit
5b5698afb5
1 changed files with 54 additions and 0 deletions
54
source/recipes/devshell/flake/main.adoc0
Normal file
54
source/recipes/devshell/flake/main.adoc0
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
= 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
|
||||
////
|
||||
Loading…
Add table
Add a link
Reference in a new issue