$ nix run "git+https://codeberg.org/mhwombat/hello-flake"+
$ nix run "git+https://codeberg.org/mhwombat/hello-flake" +Hello from your flake!
diff --git a/index.html b/index.html index c1d71e5..bc600ff 100644 --- a/index.html +++ b/index.html @@ -651,12 +651,13 @@ with flakes, while the hyphenated versions are for everything else.
created a simple example of a flake in this git repository. To run this flake, you don’t need to install anything; simply run the command below. -The first time you use a package, Nix has to fetch and build it, which -may take a few minutes. Subsequent invocations should be instantaneous. +The first time you use a flake, Nix has to fetch and build it, which +may take time. Subsequent invocations should be instantaneous.$ nix run "git+https://codeberg.org/mhwombat/hello-flake"+
$ nix run "git+https://codeberg.org/mhwombat/hello-flake" +Hello from your flake!
$ hello-flake+
$ hello-flake +Hello from your flake!
$ which hello-flake+
$ which hello-flake +/nix/store/qskl8ajlgnl654fhgsmv74yv8x9r3kzg-hello-flake/bin/hello-flake
Once we exit that shell, the hello-flake command is no longer
-available.
$# echo '$ exit' -$# echo '$ hello-flake' +$ exit +$ hello-flake sh: line 3: hello-flake: command not found
Actually, we can still access the command using the store path we found +
However, we can still run the command using the store path we found earlier. That’s not particularly convenient, but it does demonstrate that the package remains in the store for future use.
$ cd ~/tutorial-practice/hello-flake -$ nix develop+bash: line 10: cd: /home/amy/tutorial-practice/hello-flake: No such file or directory +$ nix develop +path '/home/amy/codeberg/nix-book/source' does not contain a 'flake.nix', searching up +error: path '/home/amy/codeberg/nix-book' is not part of a flake (neither it nor its parent directories contain a 'flake.nix' file)
$ hello-flake+
$ hello-flake +bash: line 28: hello-flake: command not found
$ ./hello-flake+
$ ./hello-flake +bash: line 40: ./hello-flake: No such file or directory
result.
$ nix build -$ result/bin/hello-flake+path '/home/amy/codeberg/nix-book/source' does not contain a 'flake.nix', searching up +error: path '/home/amy/codeberg/nix-book' is not part of a flake (neither it nor its parent directories contain a 'flake.nix' file) +$ result/bin/hello-flake +bash: line 50: result/bin/hello-flake: No such file or directory
nix run.
$ nix run+
$ nix run +path '/home/amy/codeberg/nix-book/source' does not contain a 'flake.nix', searching up +error: path '/home/amy/codeberg/nix-book' is not part of a flake (neither it nor its parent directories contain a 'flake.nix' file)
sed command below will make the necessary changes.
$ sed -i 's/echo/cowsay/' hello-flake -$ cat hello-flake+sed: can't read hello-flake: No such file or directory +$ cat hello-flake +cat: hello-flake: No such file or directory
$ ./hello-flake+
$ ./hello-flake +bash: line 96: ./hello-flake: No such file or directory
$# sed -i '15i\\ \ \ \ \ \ \ \ devShells = rec {\n\ \ \ \ \ \ \ \ \ \ default = pkgs.mkShell {\n\ \ \ \ \ \ \ \ \ \ \ \ packages = [ pkgs.cowsay ];\n\ \ \ \ \ \ \ \ \ \ };\n\ \ \ \ \ \ \ \ };\n' flake.nix
-$ git diff flake.nix
+sed: can't read flake.nix: No such file or directory +$ git diff flake.nix +fatal: ambiguous argument 'flake.nix': unknown revision or path not in the working tree. +Use '--' to separate paths from revisions, like this: +'git <command> [<revision>...] -- [<file>...]'
$# echo '$ nix develop' -$# nix develop --command sh +$ nix develop +path '/home/amy/codeberg/nix-book/source' does not contain a 'flake.nix', searching up +error: path '/home/amy/codeberg/nix-book' is not part of a flake (neither it nor its parent directories contain a 'flake.nix' file) $ which cowsay # is it available now? -$ ./hello-flake+which: no cowsay in (/home/amy/github/wain-tools:/home/amy/github/bin:/home/amy/github/wain-tools:/home/amy/github/bin:/nix/store/dsfcdjmymlc18wzk0hssycwifg4wznan-bash-interactive-5.1-p16/bin:/nix/store/4ccwc439gkpk91gflh6zsyx12fkfcggx-patchelf-0.15.0/bin:/nix/store/y372k7srz9jm7v9sv2cs84g3crz27z1s-gcc-wrapper-11.3.0/bin:/nix/store/wy4ywjsch9q2hj5lphqjdg9p2kf7w0ls-gcc-11.3.0/bin:/nix/store/fi1521530hy97gwjfdlgiqb4wad2g13d-glibc-2.35-224-bin/bin:/nix/store/l6jgwxkc3jhr029vfzfwzcy28iyckwsj-coreutils-9.1/bin:/nix/store/l5i2w0w446pqsnpdxrlsf3azy5aspfxq-binutils-wrapper-2.39/bin:/nix/store/9n9gjvzci75gp2sh1c4rh626dhizqynl-binutils-2.39/bin:/nix/store/gx0iyarrz7jcnac1yllhgzffi75y4gs8-asciidoctor-2.0.18/bin:/nix/store/bbi6z65bazdzmawxaxr1kvgbn41sv9g0-python3.11-pygments-2.13.0/bin:/nix/store/szz6i32n70m8pxidw5zj294rka4m0yrz-python3.11-docutils-0.19/bin:/nix/store/536aws8kkljng4ggdakk8i1nfdqb4f4x-python3-3.11.3/bin:/nix/store/l6jgwxkc3jhr029vfzfwzcy28iyckwsj-coreutils-9.1/bin:/nix/store/gn1s1s5z19cf0wiir2cd38jckcjc6kn6-findutils-4.9.0/bin:/nix/store/5l382qdhcyyjsyhfqqc0g15rmvs3rs4s-diffutils-3.8/bin:/nix/store/v0hg83sdv4v51c0prmdigry6wdmmpzmp-gnused-4.8/bin:/nix/store/pvb117r7fhwb08717ks21a6y9hlnp63b-gnugrep-3.7/bin:/nix/store/51sgpaxsi4sl46ii9fssvyp7n592if1m-gawk-5.1.1/bin:/nix/store/isycdamy5rsi0vq55fxz0438srx5z0hv-gnutar-1.34/bin:/nix/store/w9pbk66kf43wrpdcijjzc8vf8cymnaxy-gzip-1.12/bin:/nix/store/r84vlmw71jw2piv03n0jdhav2zsdvm6n-bzip2-1.0.8-bin/bin:/nix/store/cgbpv0vvz31qayvbf3bif2iznp46wcgl-gnumake-4.3/bin:/nix/store/kga2r02rmyxl14sg96nxbdhifq3rb8lc-bash-5.1-p16/bin:/nix/store/f1gvh42512gjf3378nmlw2vrx491yndq-patch-2.7.6/bin:/nix/store/y8z2dmbxdapyzpcrhfbdv875l5v7ddpi-xz-5.2.7-bin/bin:/nix/store/cmnq5bja0h0an1k3cyb36blkfci8nxaf-file-5.43/bin:/nix/store/dsfcdjmymlc18wzk0hssycwifg4wznan-bash-interactive-5.1-p16/bin:/nix/store/4ccwc439gkpk91gflh6zsyx12fkfcggx-patchelf-0.15.0/bin:/nix/store/y372k7srz9jm7v9sv2cs84g3crz27z1s-gcc-wrapper-11.3.0/bin:/nix/store/wy4ywjsch9q2hj5lphqjdg9p2kf7w0ls-gcc-11.3.0/bin:/nix/store/fi1521530hy97gwjfdlgiqb4wad2g13d-glibc-2.35-224-bin/bin:/nix/store/l6jgwxkc3jhr029vfzfwzcy28iyckwsj-coreutils-9.1/bin:/nix/store/l5i2w0w446pqsnpdxrlsf3azy5aspfxq-binutils-wrapper-2.39/bin:/nix/store/9n9gjvzci75gp2sh1c4rh626dhizqynl-binutils-2.39/bin:/nix/store/0dip0kcky3jnjsp60xvk1cjzhv4yvj2s-python3.10-pelican-4.8.0/bin:/nix/store/089zdkxl8bbif25dqv3sx4nc9jyz6bh5-python3.10-chardet-5.0.0/bin:/nix/store/rpri9nb8xpwwqakyrqbg8zdslkjs2hd3-python3-3.10.11/bin:/nix/store/01axgc9g662lk663h93z2bp8clyy3hqn-python3.10-docutils-0.19/bin:/nix/store/v20lm65xzlndbw2mbihqj4xiasrvgs9w-python3.10-babel-2.11.0/bin:/nix/store/aba7b45bjy0aawqlblag6k4vg5qf44kh-python3.10-pygments-2.13.0/bin:/nix/store/zvylkc7cnar7majappcww2z826ls3sb7-python3.10-commonmark-0.9.1/bin:/nix/store/hkyfwv0yqhmyv7qvxc4g9w3ia534x391-python3.10-future-0.18.3/bin:/nix/store/5ag6v19kxlfnk6qbrrwy8wiq9m4il310-python3.10-unidecode-1.3.4/bin:/nix/store/w3f9jkinz72jyklfsgwmrfmhm4czsmga-python3.10-markdown-3.4.1/bin:/nix/store/l6jgwxkc3jhr029vfzfwzcy28iyckwsj-coreutils-9.1/bin:/nix/store/gn1s1s5z19cf0wiir2cd38jckcjc6kn6-findutils-4.9.0/bin:/nix/store/5l382qdhcyyjsyhfqqc0g15rmvs3rs4s-diffutils-3.8/bin:/nix/store/v0hg83sdv4v51c0prmdigry6wdmmpzmp-gnused-4.8/bin:/nix/store/pvb117r7fhwb08717ks21a6y9hlnp63b-gnugrep-3.7/bin:/nix/store/51sgpaxsi4sl46ii9fssvyp7n592if1m-gawk-5.1.1/bin:/nix/store/isycdamy5rsi0vq55fxz0438srx5z0hv-gnutar-1.34/bin:/nix/store/w9pbk66kf43wrpdcijjzc8vf8cymnaxy-gzip-1.12/bin:/nix/store/r84vlmw71jw2piv03n0jdhav2zsdvm6n-bzip2-1.0.8-bin/bin:/nix/store/cgbpv0vvz31qayvbf3bif2iznp46wcgl-gnumake-4.3/bin:/nix/store/kga2r02rmyxl14sg96nxbdhifq3rb8lc-bash-5.1-p16/bin:/nix/store/f1gvh42512gjf3378nmlw2vrx491yndq-patch-2.7.6/bin:/nix/store/y8z2dmbxdapyzpcrhfbdv875l5v7ddpi-xz-5.2.7-bin/bin:/nix/store/cmnq5bja0h0an1k3cyb36blkfci8nxaf-file-5.43/bin:/home/amy/github/wain-tools:/home/amy/github/bin:/home/amy/github/wain-tools:/home/amy/github/bin:/home/amy/github/wain-tools:/home/amy/github/bin:/run/wrappers/bin:/home/amy/.nix-profile/bin:/etc/profiles/per-user/amy/bin:/nix/var/nix/profiles/default/bin:/run/current-system/sw/bin) +$ ./hello-flake +bash: line 138: ./hello-flake: No such file or directory
$ nix run+
$ nix run +path '/home/amy/codeberg/nix-book/source' does not contain a 'flake.nix', searching up +error: path '/home/amy/codeberg/nix-book' is not part of a flake (neither it nor its parent directories contain a 'flake.nix' file)
$ cat result/bin/hello-flake+
$ cat result/bin/hello-flake +cat: result/bin/hello-flake: No such file or directory
$ nix build -$ cat result/bin/hello-flake+path '/home/amy/codeberg/nix-book/source' does not contain a 'flake.nix', searching up +error: path '/home/amy/codeberg/nix-book' is not part of a flake (neither it nor its parent directories contain a 'flake.nix' file) +$ cat result/bin/hello-flake +cat: result/bin/hello-flake: No such file or directory
git push the changes until we’re ready to share t
$ git commit hello-flake flake.nix -m 'added bovine feature' -$ nix run+error: pathspec 'hello-flake' did not match any file(s) known to git +error: pathspec 'flake.nix' did not match any file(s) known to git +$ nix run +path '/home/amy/codeberg/nix-book/source' does not contain a 'flake.nix', searching up +error: path '/home/amy/codeberg/nix-book' is not part of a flake (neither it nor its parent directories contain a 'flake.nix' file)
$ cd ~/tutorial-practice +bash: line 8: cd: /home/amy/tutorial-practice: No such file or directory $ mkdir hello-python +mkdir: cannot create directory ‘hello-python’: File exists $ cd hello-python -$ git init+$ git init +Reinitialized existing Git repository in /home/amy/codeberg/nix-book/source/hello-python/.git/
$# curl https://codeberg.org/mhwombat/hello-flake-python/raw/branch/main/hello.py --silent --output hello.py -$ cat hello.py+
$ cat hello.py
+#!/usr/bin/env python
+
+def main():
+ print("Hello from inside a Python program built with a Nix flake!")
+
+if __name__ == "__main__":
+ main()
$# echo '$ nix-shell -p python3' -$# nix-shell -p python3 --command sh -$ python hello.py+
$ nix-shell -p python3 +$ python hello.py +Hello from inside a Python program built with a Nix flake!
$# curl https://codeberg.org/mhwombat/hello-flake-python/raw/branch/main/setup.py --silent --output setup.py -$ cat setup.py+
$ cat setup.py
+#!/usr/bin/env python
+
+from setuptools import setup
+
+setup(
+ name='hello-flake-python',
+ version='0.1.0',
+ py_modules=['hello'],
+ entry_points={
+ 'console_scripts': ['hello-flake-python = hello:main']
+ },
+)
$ python -m build+
$ python -m build +/nix/store/rpri9nb8xpwwqakyrqbg8zdslkjs2hd3-python3-3.10.11/bin/python: No module named build
$# echo '$ nix-shell -p "python3.withPackages (ps: with ps; [ build ])"' -$# nix-shell -p "python3.withPackages (ps: with ps; [ build ])" --command sh+
$ nix-shell -p "python3.withPackages (ps: with ps; [ build ])"
exit followed by the
$# echo '$ python -m build' -$# python -m build > /dev/null 2>&1+
$ python -m build
$# curl https://codeberg.org/mhwombat/hello-flake-python/raw/branch/main/flake.nix --silent --output flake.nix -$ cat flake.nix+
$ cat flake.nix
+{
+ # See https://github.com/mhwombat/nix-for-numbskulls/blob/main/flakes.md
+ # for a brief overview of what each section in a flake should or can contain.
+
+ description = "a very simple and friendly flake written in Python";
+
+ 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; };
+ python = pkgs.python3;
+ in
+ {
+ devShells = rec {
+ default = pkgs.mkShell {
+ packages = [
+ # Python plus helper tools
+ (python.withPackages (ps: with ps; [
+ virtualenv # Virtualenv
+ pip # The pip installer
+ ]))
+ ];
+ };
+ };
+
+ packages = rec {
+ hello = python.pkgs.buildPythonApplication {
+ name = "hello-flake-python";
+
+ buildInputs = with python.pkgs; [ pip ];
+
+ src = ./.;
+ };
+ default = hello;
+ };
+
+ apps = rec {
+ hello = flake-utils.lib.mkApp { drv = self.packages.${system}.hello; };
+ default = hello;
+ };
+ }
+ );
+}
$ nix run+
$ nix run +Hello from inside a Python program built with a Nix flake!
$ git add flake.nix setup.py hello.py -$ nix run+$ nix run +Hello from inside a Python program built with a Nix flake!
$ git add flake.lock -$ git commit -a -m 'initial commit'+$ git commit -a -m 'initial commit' +On branch master +Untracked files: + (use "git add <file>..." to include in what will be committed) + dist/ + hello_flake_python.egg-info/ + +nothing added to commit but untracked files present (use "git add" to track)
$ cd ~ -$ nix run ~/tutorial-practice/hello-python+$ nix run ~/tutorial-practice/hello-python +path '/home/amy/tutorial-practice/hello-python' does not contain a 'flake.nix', searching up +error: getting status of '/home/amy/tutorial-practice/hello-python': No such file or directory
$ nix-shell +error: getting status of '/home/amy/codeberg/nix-book/source/shell-recipes/default.nix': No such file or directory $ hello +bash: line 19: hello: command not found Hello, world! $ cowsay "moo" +bash: line 22: cowsay: command not found _____ < moo > ----- @@ -1855,7 +1967,9 @@ mkShell {@@ -1894,7 +2008,9 @@ mkShell {$ nix-shell +error: getting status of '/home/amy/codeberg/nix-book/source/shell-recipes/default.nix': No such file or directory $ hello-nix +bash: line 48: hello-nix: command not found Hello from your nix package!@@ -1929,7 +2045,9 @@ mkShell {$ nix-shell +error: getting status of '/home/amy/codeberg/nix-book/source/shell-recipes/default.nix': No such file or directory $ hello-flake +bash: line 65: hello-flake: command not found Hello from your flake!@@ -2049,7 +2167,9 @@ mkShell {$ nix-shell +error: getting status of '/home/amy/codeberg/nix-book/source/shell-recipes/default.nix': No such file or directory $ hello-flake +bash: line 82: hello-flake: command not found Hello from your flake!@@ -2090,7 +2210,14 @@ cowsay "Pretty cool, huh?"$ nix-shell +error: getting status of '/home/amy/codeberg/nix-book/source/shell-recipes/default.nix': No such file or directory $ echo $FOO + bar
$# shebangs/bash-with-nixpkg.sh+
___________________ +< Pretty cool, huh? > + ------------------- + \ ^__^ + \ (oo)\_______ + (__)\ )\/\ + ||----w | + || ||
$# shebangs/python-with-nixpkg.sh+
original: <span style="font-weight:bold">some text</span> +sanitized: <strong>some text</strong>