mirror of
https://codeberg.org/mhwombat/nix-book.git
synced 2026-05-14 08:21:13 +08:00
expanded
This commit is contained in:
parent
ec7fd17c07
commit
7e29b45472
15 changed files with 18 additions and 163 deletions
|
|
@ -1,6 +1,6 @@
|
|||
= Ad hoc environments with access to...
|
||||
= Ad hoc environments
|
||||
|
||||
== A top level package from the Nixpkgs/NixOS repo
|
||||
== Access a top level package from the Nixpkgs/NixOS repo
|
||||
|
||||
....
|
||||
$# ../../../start-shell nix shell nixpkgs#cowsay <<EOL
|
||||
|
|
@ -8,7 +8,7 @@ $ cowsay "moo"
|
|||
$# EOL
|
||||
....
|
||||
|
||||
== A flake
|
||||
== Access a flake
|
||||
|
||||
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>>.
|
||||
|
|
|
|||
|
|
@ -1,60 +0,0 @@
|
|||
{
|
||||
"nodes": {
|
||||
"flake-utils": {
|
||||
"inputs": {
|
||||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1731533236,
|
||||
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1757096966,
|
||||
"narHash": "sha256-nJpPWCFbc5/u0VIoSHT350FEwPS5pwiRfyZBbZA3Kgg=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "6eb784fb955ab56952e6eeb01f3e64a79933e2b5",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils",
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
"locked": {
|
||||
"lastModified": 1681028828,
|
||||
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "nix-systems",
|
||||
"repo": "default",
|
||||
"type": "github"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
{
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs";
|
||||
flake-utils.url = "github:numtide/flake-utils";
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, flake-utils }:
|
||||
flake-utils.lib.eachDefaultSystem (system:
|
||||
let
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
customGhc = pkgs.haskellPackages.ghcWithPackages (p: with p; [ containers ]);
|
||||
in
|
||||
{
|
||||
devShells = rec {
|
||||
default = pkgs.mkShell {
|
||||
buildInputs = [ customGhc ];
|
||||
};
|
||||
};
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
= Development shells with access to...
|
||||
= Development shells
|
||||
|
||||
include::nixpkg/main-generated.adoc[leveloffset=+1]
|
||||
|
||||
|
|
|
|||
|
|
@ -22,14 +22,8 @@ include::devshell/main.adoc[leveloffset=+1]
|
|||
|
||||
include::nix-shell/main-generated.adoc[leveloffset=+1]
|
||||
|
||||
include::remote-git/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]
|
||||
|
|
|
|||
|
|
@ -1,12 +0,0 @@
|
|||
= In a Python script
|
||||
|
||||
[source,python,linenums]
|
||||
.Script
|
||||
....
|
||||
include::my-script.sh[]
|
||||
....
|
||||
|
||||
.Output
|
||||
....
|
||||
$# ./my-script.sh
|
||||
....
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
from html_sanitizer import Sanitizer
|
||||
sanitizer = Sanitizer() # default configuration
|
||||
|
||||
original='<span style="font-weight:bold">some text</span>'
|
||||
print('original: ', original)
|
||||
|
||||
sanitized=sanitizer.sanitize(original)
|
||||
print('sanitized: ', sanitized)
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
= In `shell.nix`
|
||||
|
||||
[source,nix,linenums]
|
||||
.shell.nix
|
||||
....
|
||||
include::shell.nix[]
|
||||
....
|
||||
|
||||
Here's a short Python program that uses it.
|
||||
|
||||
[source,python,linenums]
|
||||
.Main.hs
|
||||
....
|
||||
include::Main.py[]
|
||||
....
|
||||
|
||||
Here's a demonstration using the program.
|
||||
|
||||
....
|
||||
$# echo '$ nix-shell'
|
||||
$# nix-shell --run bash <<EOL
|
||||
$ python Main.py
|
||||
$# EOL
|
||||
....
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
with (import <nixpkgs> {});
|
||||
let
|
||||
customPython = python3.withPackages (ps: with ps; [ html_sanitizer ]);
|
||||
in
|
||||
mkShell {
|
||||
buildInputs = [
|
||||
customPython
|
||||
];
|
||||
}
|
||||
|
|
@ -1,16 +1,10 @@
|
|||
= Access to a Haskell library package in the nixpkgs repo (without a `.cabal` file)
|
||||
= Access a Haskell library package in the nixpkgs repo (without a `.cabal` file)
|
||||
|
||||
Occasionally you might want to run a short Haskell program that depends on a Haskell library,
|
||||
but you don't want to bother writing a cabal file.
|
||||
|
||||
Example: Access the `containers` package from the `haskellPackages` set in the nixpkgs repo.
|
||||
|
||||
include::shell/main-generated.adoc[leveloffset=+1]
|
||||
|
||||
include::shebang/main-generated.adoc[leveloffset=+1]
|
||||
|
||||
= In a Haskell script
|
||||
|
||||
[source,haskell,linenums]
|
||||
.Script
|
||||
....
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
= Scripts with access to...
|
||||
= Scripts
|
||||
|
||||
You can use `nix shell` to run scripts in arbitrary languages, providing
|
||||
the necessary dependencies.
|
||||
|
|
@ -14,3 +14,5 @@ include::nixpkg/main-generated.adoc[leveloffset=+1]
|
|||
include::flake/main-generated.adoc[leveloffset=+1]
|
||||
|
||||
include::haskell-nixpkg/main-generated.adoc[leveloffset=+1]
|
||||
|
||||
include::python-nixpkg/main-generated.adoc[leveloffset=+1]
|
||||
|
|
|
|||
|
|
@ -1,11 +1,17 @@
|
|||
= Access to a Python library package in the nixpkgs repo (without using a Python builder)
|
||||
= Access 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]
|
||||
[source,python,linenums]
|
||||
.Script
|
||||
....
|
||||
include::my-script.sh[]
|
||||
....
|
||||
|
||||
.Output
|
||||
....
|
||||
$# ./my-script.sh
|
||||
....
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
#! /usr/bin/env nix-shell
|
||||
#! nix-shell -i bash -p "[hello cowsay]"
|
||||
hello
|
||||
cowsay "Pretty cool, huh?"
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
#! /usr/bin/env nix
|
||||
#! nix shell git+https://codeberg.org/mhwombat/hello-flake --command bash
|
||||
hello-flake
|
||||
Loading…
Add table
Add a link
Reference in a new issue