mirror of
https://codeberg.org/mhwombat/nix-book.git
synced 2026-01-27 00:47:12 +08:00
initial commit
This commit is contained in:
parent
0311f3a7e5
commit
7761303cd4
9 changed files with 111 additions and 0 deletions
5
source/recipes/env-var/main.adoc
Normal file
5
source/recipes/env-var/main.adoc
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
= Set an environment variable
|
||||
|
||||
Ex: Set the value of the environment variable FOO to "`bar`"
|
||||
|
||||
include::shell/main-generated.adoc[leveloffset=+1]
|
||||
8
source/recipes/haskell-local-deps/main.adoc
Normal file
8
source/recipes/haskell-local-deps/main.adoc
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
= Access to a Haskell package on your local computer, with interdependencies
|
||||
|
||||
Ex: Access four Haskell packages
|
||||
(`pandoc-linear-table`, `pandoc-logic-proof`, `pandoc-columns` and `pandoc-maths-web`)
|
||||
that are on my hard drive.
|
||||
The fourth package depends on the first three to build.
|
||||
|
||||
include::shell/main-generated.adoc[leveloffset=+1]
|
||||
7
source/recipes/haskell-local/main.adoc
Normal file
7
source/recipes/haskell-local/main.adoc
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
= Access to a Haskell package on your local computer
|
||||
|
||||
Ex: Access three Haskell packages
|
||||
(`pandoc-linear-table`, `pandoc-logic-proof`, and `pandoc-columns`)
|
||||
that are on my hard drive.
|
||||
|
||||
include::shell/main-generated.adoc[leveloffset=+1]
|
||||
13
source/recipes/haskell-nixpkg/shebang/main.adoc0
Normal file
13
source/recipes/haskell-nixpkg/shebang/main.adoc0
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
= In a Haskell script
|
||||
|
||||
[source,haskell,linenums]
|
||||
.Script
|
||||
....
|
||||
include::my-script.sh[]
|
||||
....
|
||||
|
||||
.Output
|
||||
....
|
||||
$# ./my-script.sh
|
||||
....
|
||||
|
||||
41
source/recipes/main.adoc
Normal file
41
source/recipes/main.adoc
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
= Recipes
|
||||
|
||||
This chapter provides examples of how to use Nix in a variety of scanarios.
|
||||
Multiple types of recipes are provided are provided for some scenarios;
|
||||
comparing the different recipes will help you better understand Nix.
|
||||
|
||||
- An _"ad hoc" shell_
|
||||
is useful when you want to quickly create an environment
|
||||
for a one-off task.
|
||||
|
||||
- A _traditional nix shell_
|
||||
is useful when you want to define an environment that you will
|
||||
use more than once.
|
||||
|
||||
- _Nix flakes_
|
||||
are the recommended approach for development projects.
|
||||
|
||||
- You can use `nix-shell` to run scripts in arbitrary languages, providing
|
||||
the necessary dependencies. This is particularly convenient for
|
||||
standalone scripts because you don’t need to create a repo and write a
|
||||
separate `flake.nix`.
|
||||
The script should start with two _"shebang"_ (`#!`) commands. The first
|
||||
should invoke `nix-shell`. The second should declares the script
|
||||
interpreter and any dependencies.
|
||||
|
||||
|
||||
include::nixpkgs-pkg/main.adoc[leveloffset=+1]
|
||||
|
||||
include::remote-git/main.adoc[leveloffset=+1]
|
||||
|
||||
include::remote-git-flake/main.adoc[leveloffset=+1]
|
||||
|
||||
include::haskell-nixpkg/main.adoc[leveloffset=+1]
|
||||
|
||||
include::haskell-local/main.adoc[leveloffset=+1]
|
||||
|
||||
include::haskell-local-deps/main.adoc[leveloffset=+1]
|
||||
|
||||
include::python-nixpkg/main.adoc[leveloffset=+1]
|
||||
|
||||
include::env-var/main.adoc[leveloffset=+1]
|
||||
10
source/recipes/nixpkgs-pkg/main.adoc
Normal file
10
source/recipes/nixpkgs-pkg/main.adoc
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
= Access to a top-level package from the Nixpkgs/NixOS repo
|
||||
|
||||
Ex: Access two packages from nixpkgs:
|
||||
hello and cowsay.
|
||||
|
||||
include::cli/main-generated.adoc[leveloffset=+1]
|
||||
|
||||
include::shell/main-generated.adoc[leveloffset=+1]
|
||||
|
||||
include::shebang/main-generated.adoc[leveloffset=+1]
|
||||
11
source/recipes/python-nixpkg/main.adoc
Normal file
11
source/recipes/python-nixpkg/main.adoc
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
= Access to a Python library package in the nixpkgs repo (without using a Python builder)
|
||||
|
||||
Occasionally you might want to run a short Python program that depends on a Python library,
|
||||
but you don't want to bother configuring a builder.
|
||||
|
||||
Example: Access the `html_sanitizer` package from the `python3nnPackages` set in the nixpkgs repo.
|
||||
|
||||
// TODO include::shell/main-generated.adoc[leveloffset=+1]
|
||||
|
||||
include::shebang/main-generated.adoc[leveloffset=+1]
|
||||
|
||||
8
source/recipes/remote-git-flake/main.adoc
Normal file
8
source/recipes/remote-git-flake/main.adoc
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
= Access to a flake defined in a remote git repo
|
||||
|
||||
Ex: Access a flake called `hello-flake`,
|
||||
which is defined in a remote git repo on codeberg.
|
||||
To use a package from GitHub, GitLab, or any other public platform,
|
||||
modify the URL.
|
||||
|
||||
include::shell/main-generated.adoc[leveloffset=+1]
|
||||
8
source/recipes/remote-git/main.adoc
Normal file
8
source/recipes/remote-git/main.adoc
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
= Access to a package defined in a remote git repo
|
||||
|
||||
Ex: Access a package called `hello-nix`,
|
||||
which is defined in a remote git repo on codeberg.
|
||||
To use a package from GitHub, GitLab, or any other public platform,
|
||||
modify the URL.
|
||||
|
||||
include::shell/main-generated.adoc[leveloffset=+1]
|
||||
Loading…
Add table
Add a link
Reference in a new issue