mirror of
https://codeberg.org/mhwombat/nix-book.git
synced 2025-12-26 16:24:56 +08:00
initial commit
This commit is contained in:
parent
24e71423e4
commit
5e2da971de
4 changed files with 122 additions and 0 deletions
21
source/recipes/devshell/flake/flake.nix
Normal file
21
source/recipes/devshell/flake/flake.nix
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
{
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs";
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
hello-flake.url = "git+https://codeberg.org/mhwombat/hello-flake";
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, flake-utils, hello-flake }:
|
||||
flake-utils.lib.eachDefaultSystem (system:
|
||||
let
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
in
|
||||
{
|
||||
devShells = rec {
|
||||
default = pkgs.mkShell {
|
||||
buildInputs = [ hello-flake.packages.${system}.hello ];
|
||||
};
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
||||
31
source/recipes/devshell/nixpkg/main.adoc0
Normal file
31
source/recipes/devshell/nixpkg/main.adoc0
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
= A top level package from the Nixpkgs/NixOS repo
|
||||
|
||||
////
|
||||
$ mkdir tempwork
|
||||
$ cd tempwork
|
||||
$ cp ../flake.nix flake.nix
|
||||
$ git add flake.nix
|
||||
$ nix develop
|
||||
$ git add flake.lock
|
||||
$ git commit -a -m temp
|
||||
////
|
||||
|
||||
[source,nix,linenums,highlight=15]
|
||||
.flake.nix
|
||||
....
|
||||
$# cat flake.nix
|
||||
....
|
||||
|
||||
Here's a demonstration using the shell.
|
||||
|
||||
....
|
||||
$ cowsay "Moo!"
|
||||
$# ../../../../../start-shell nix develop <<EOL
|
||||
$ cowsay "Moo!"
|
||||
$# EOL
|
||||
....
|
||||
|
||||
////
|
||||
Good adoc0 scripts clean up after themselves.
|
||||
$ cd .. ; rm -rf tempwork # clean up
|
||||
////
|
||||
20
source/recipes/nix-shell/main.adoc0
Normal file
20
source/recipes/nix-shell/main.adoc0
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
= An (old-style) Nix shell with access to a flake
|
||||
|
||||
If you are maintaining legacy code,
|
||||
you may need to provide access to a flake in a `nix-shell`.
|
||||
Here's how.
|
||||
|
||||
[source,nix,linenums]
|
||||
.shell.nix
|
||||
....
|
||||
include::shell.nix[]
|
||||
....
|
||||
|
||||
Here's a demonstration using the shell.
|
||||
|
||||
....
|
||||
$# echo '$ nix-shell'
|
||||
$# nix-shell --run bash <<EOL
|
||||
$ hello-flake
|
||||
$# EOL
|
||||
....
|
||||
50
source/recipes/run/main.adoc0
Normal file
50
source/recipes/run/main.adoc0
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
= Running programs directly (without installing them)
|
||||
|
||||
== A top level package from the Nixpkgs/NixOS repo
|
||||
|
||||
....
|
||||
$ nix run nixpkgs#cowsay "Moo!"
|
||||
....
|
||||
|
||||
[#flakeref]
|
||||
== Flakes
|
||||
|
||||
=== A flake defined in a local file
|
||||
|
||||
....
|
||||
$ nix run ~/codeberg/hello-flake
|
||||
....
|
||||
|
||||
=== A flake defined in a remote git repo
|
||||
|
||||
....
|
||||
$ nix run git+https://codeberg.org/mhwombat/hello-flake
|
||||
....
|
||||
|
||||
To run a specific branch, use the command below.
|
||||
|
||||
....
|
||||
nix run git+https://codeberg.org/mhwombat/hello-flake?ref=main
|
||||
....
|
||||
|
||||
To run a specific branch and revision, use the command below.
|
||||
|
||||
....
|
||||
nix run git+https://codeberg.org/mhwombat/hello-flake?ref=main&rev=d44728bce88a6f9d1d37dbf4720ece455e997606
|
||||
....
|
||||
|
||||
=== A flake defined in a zip archive
|
||||
|
||||
....
|
||||
$ nix run https://codeberg.org/mhwombat/hello-flake/archive/main.zip
|
||||
....
|
||||
|
||||
=== A flake defined in a compressed tar archive
|
||||
|
||||
....
|
||||
$ nix run https://codeberg.org/mhwombat/hello-flake/archive/main.tar.gz
|
||||
....
|
||||
|
||||
=== Other types of flake references
|
||||
|
||||
See https://nix.dev/manual/nix/stable/command-ref/new-cli/nix3-flake#flake-reference-attributes.
|
||||
Loading…
Add table
Add a link
Reference in a new issue