$ nix run nixpkgs#cowsay "Moo!" + ______ +< Moo! > + ------ + \ ^__^ + \ (oo)\_______ + (__)\ )\/\ + ||----w | + || ||+
From 7de7ca85321035a1ac234ff830b52689b7a7d83a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Amy=20de=20Buitl=C3=A9ir?=
-
-
@@ -4097,13 +4130,286 @@ interpreter and any dependencies.flake.nixshell.nix.cabal file)
+.cabal file)
+
+
$ nix run nixpkgs#cowsay "Moo!" + ______ +< Moo! > + ------ + \ ^__^ + \ (oo)\_______ + (__)\ )\/\ + ||----w | + || ||+
$ nix run ~/codeberg/hello-flake +Hello from your flake!+
$ nix run git+https://codeberg.org/mhwombat/hello-flake +Hello from your 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+
$ nix run https://codeberg.org/mhwombat/hello-flake/archive/main.zip +Hello from your flake!+
$ nix run https://codeberg.org/mhwombat/hello-flake/archive/main.tar.gz +Hello from your flake!+
$ nix shell nixpkgs#cowsay +$ cowsay "moo" + _____ +< moo > + ----- + \ ^__^ + \ (oo)\_______ + (__)\ )\/\ + ||----w | + || ||+
$ nix shell git+https://codeberg.org/mhwombat/hello-flake +$ hello-flake +Hello from your flake!+
You can use all of the flake reference styles defined in Section 10.1.2, “Flakes”.
+1
+2
+3
+4
#! /usr/bin/env nix
+#! nix shell nixpkgs#hello nixpkgs#cowsay --command bash
+hello
+cowsay "Pretty cool, huh?"
+
+Hello, world! + ___________________ +< Pretty cool, huh? > + ------------------- + \ ^__^ + \ (oo)\_______ + (__)\ )\/\ + ||----w | + || ||+
1
+2
+3
#! /usr/bin/env nix
+#! nix shell git+https://codeberg.org/mhwombat/hello-flake --command bash
+hello-flake
+
+Hello from your flake!+
You can use all of the flake reference styles defined in Section 10.1.2, “Flakes”.
+ 1
+ 2
+ 3
+ 4
+ 5
+ 6
+ 7
+ 8
+ 9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+20
{
+ 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; };
+ in
+ {
+ devShells = rec {
+ default = pkgs.mkShell {
+ packages = [ pkgs.cowsay ];
+ };
+ };
+ }
+ );
+}
+
+Here’s a demonstration using the shell.
+$ cowsay "Moo!" +bash: line 35: cowsay: command not found +$ pwd +/home/amy/codeberg/nix-book/source/recipes/devshell/tempwork +$ realpath ../../../.. +/home/amy/codeberg/nix-book +$ nix develop +warning: Git tree '/home/amy/codeberg/nix-book' is dirty +warning: creating lock file '"/home/amy/codeberg/nix-book/source/recipes/devshell/tempwork/flake.lock"': +• Added input 'flake-utils': + 'github:numtide/flake-utils/11707dc2f618dd54ca8739b309ec4fc024de578b?narHash=sha256-l0KFg5HjrsfsO/JpG%2Br7fRrqm12kzFHyUHqHCVpMMbI%3D' (2024-11-13) +• Added input 'flake-utils/systems': + 'github:nix-systems/default/da67096a3b9bf56a91d16901293e51ba5b49a27e?narHash=sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768%3D' (2023-04-09) +• Added input 'nixpkgs': + 'github:NixOS/nixpkgs/6ce002c32a5e3470505a44fbcfb9e51cbaec71a6?narHash=sha256-uOBDwpkJZMb8gjkOA89fx%2Bcq9qT0abLETCINC/cb%2Bz0%3D' (2025-09-03) +warning: Git tree '/home/amy/codeberg/nix-book' is dirty +$ cowsay "Moo!" + ______ +< Moo! > + ------ + \ ^__^ + \ (oo)\_______ + (__)\ )\/\ + ||----w | + || ||+
FINISH
+FINISH
+FINISH
+FINISH
+FINISH
+You can use all of the flake reference styles defined in Section 10.1.2, “Flakes”.
+Ex: Access two packages from nixpkgs: hello and cowsay.
$ nix shell nixpkgs#hello nixpkgs#cowsay --command bash @@ -4122,7 +4428,7 @@ $ cowsay "moo"
$ nix-shell -p "[hello cowsay]" @@ -4141,7 +4447,7 @@ $ cowsay "moo"
flake.nixflake.nixSee the example in Section 8.2, “Introducing a dependency” where defined a development shell in flake.nix @@ -4150,7 +4456,7 @@ and tested the shell.
shell.nixshell.nixEx: Access a package (not a flake) called hello-nix,
which is defined in a remote git repo on codeberg.
@@ -4260,7 +4566,7 @@ To use a package from GitHub, GitLab, or any other public platform,
modify the URL.
shell.nixshell.nixEx: Access a flake called hello-flake,
which is defined in a remote git repo on codeberg.
@@ -4307,7 +4613,17 @@ To use a package from GitHub, GitLab, or any other public platform,
modify the URL.
shell.nix$ nix shell git+https://codeberg.org/mhwombat/hello-flake +$ hello-flake +Hello from your flake!+
shell.nix.cabal file).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.
@@ -4357,7 +4673,7 @@ but you don’t want to bother writing a cabal file.Example: Access the containers package from the haskellPackages set in the nixpkgs repo.
shell.nixshell.nixEx: Access three Haskell packages
(pandoc-linear-table, pandoc-logic-proof, and pandoc-columns)
that are on my hard drive.
shell.nixshell.nixEx: Access four Haskell packages
(pandoc-linear-table, pandoc-logic-proof, pandoc-columns and pandoc-maths-web)
@@ -4520,7 +4836,7 @@ that are on my hard drive.
The fourth package depends on the first three to build.
shell.nixshell.nixOccasionally 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.
@@ -4576,7 +4892,7 @@ but you don’t want to bother configuring a builder.Example: Access the html_sanitizer package from the python3nnPackages set in the nixpkgs repo.
Ex: Set the value of the environment variable FOO to “bar”
shell.nixshell.nix