From 29e1e273b827db169359256f11bf801499c89e4a Mon Sep 17 00:00:00 2001 From: Henrik Date: Fri, 2 Jun 2023 17:17:10 +0100 Subject: [PATCH] with removed from first line (#213) * with removed from first line example no longer starts with with (import {}); * added inherit example and comments. Co-authored-by: Valentin Gagarin --- pills/07-working-derivation.xml | 9 +++++++-- pills/07/simple.txt | 21 ++++++++++++--------- pills/07/simple_inherit.txt | 11 +++++++++++ 3 files changed, 30 insertions(+), 11 deletions(-) create mode 100644 pills/07/simple_inherit.txt diff --git a/pills/07-working-derivation.xml b/pills/07-working-derivation.xml index d1f44e2..9be1faf 100644 --- a/pills/07-working-derivation.xml +++ b/pills/07-working-derivation.xml @@ -307,10 +307,15 @@ coreutils. - Then we meet the + Below is a revised version of the simple.nix file, using the inherit keyword: + + + + Here we also take the opportunity to introduce the inherit keyword. inherit foo; is equivalent to foo = foo;. - Similarly, inherit foo bar; is equivalent to foo = foo; bar = bar;. + Similarly, inherit gcc coreutils; is equivalent to gcc = gcc; coreutils = coreutils;. + Lastly, inherit (pkgs) gcc coreutils; is equivalent to gcc = pkgs.gcc; coreutils = pkgs.coreutils;. This syntax only makes sense inside sets. There's no magic involved, it's diff --git a/pills/07/simple.txt b/pills/07/simple.txt index b975e95..aff3d15 100644 --- a/pills/07/simple.txt +++ b/pills/07/simple.txt @@ -1,9 +1,12 @@ -with (import {}); -derivation { - name = "simple"; - builder = "${bash}/bin/bash"; - args = [ ./simple_builder.sh ]; - inherit gcc coreutils; - src = ./simple.c; - system = builtins.currentSystem; -} +let + pkgs = import {}; +in + pkgs.stdenv.mkDerivation { + name = "simple"; + builder = "${pkgs.bash}/bin/bash"; + args = [ ./simple_builder.sh ]; + gcc = pkgs.gcc; + coreutils = pkgs.coreutils; + src = ./simple.c; + system = builtins.currentSystem; +} \ No newline at end of file diff --git a/pills/07/simple_inherit.txt b/pills/07/simple_inherit.txt new file mode 100644 index 0000000..7abbf03 --- /dev/null +++ b/pills/07/simple_inherit.txt @@ -0,0 +1,11 @@ +let + pkgs = import {}; +in + pkgs.stdenv.mkDerivation { + name = "simple"; + builder = "${pkgs.bash}/bin/bash"; + args = [ ./simple_builder.sh ]; + inherit (pkgs) gcc coreutils; + src = ./simple.c; + system = builtins.currentSystem; +} \ No newline at end of file