diff --git a/source/recipes/env-var/main.adoc b/source/recipes/env-var/main.adoc new file mode 100644 index 0000000..ee94597 --- /dev/null +++ b/source/recipes/env-var/main.adoc @@ -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] diff --git a/source/recipes/haskell-local-deps/main.adoc b/source/recipes/haskell-local-deps/main.adoc new file mode 100644 index 0000000..c8e1ed5 --- /dev/null +++ b/source/recipes/haskell-local-deps/main.adoc @@ -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] diff --git a/source/recipes/haskell-local/main.adoc b/source/recipes/haskell-local/main.adoc new file mode 100644 index 0000000..b4913e5 --- /dev/null +++ b/source/recipes/haskell-local/main.adoc @@ -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] diff --git a/source/recipes/haskell-nixpkg/shebang/main.adoc0 b/source/recipes/haskell-nixpkg/shebang/main.adoc0 new file mode 100644 index 0000000..5bbab81 --- /dev/null +++ b/source/recipes/haskell-nixpkg/shebang/main.adoc0 @@ -0,0 +1,13 @@ += In a Haskell script + +[source,haskell,linenums] +.Script +.... +include::my-script.sh[] +.... + +.Output +.... +$# ./my-script.sh +.... + diff --git a/source/recipes/main.adoc b/source/recipes/main.adoc new file mode 100644 index 0000000..21b082d --- /dev/null +++ b/source/recipes/main.adoc @@ -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] diff --git a/source/recipes/nixpkgs-pkg/main.adoc b/source/recipes/nixpkgs-pkg/main.adoc new file mode 100644 index 0000000..5f6c7cc --- /dev/null +++ b/source/recipes/nixpkgs-pkg/main.adoc @@ -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] diff --git a/source/recipes/python-nixpkg/main.adoc b/source/recipes/python-nixpkg/main.adoc new file mode 100644 index 0000000..3a820f5 --- /dev/null +++ b/source/recipes/python-nixpkg/main.adoc @@ -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] + diff --git a/source/recipes/remote-git-flake/main.adoc b/source/recipes/remote-git-flake/main.adoc new file mode 100644 index 0000000..c9acf8d --- /dev/null +++ b/source/recipes/remote-git-flake/main.adoc @@ -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] diff --git a/source/recipes/remote-git/main.adoc b/source/recipes/remote-git/main.adoc new file mode 100644 index 0000000..5e1c677 --- /dev/null +++ b/source/recipes/remote-git/main.adoc @@ -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]