Skip to content

Commit

Permalink
with removed from first line (#213)
Browse files Browse the repository at this point in the history
* with removed from first line

example no longer starts with with (import <nixpkgs> {});

* added inherit example and comments.

Co-authored-by: Valentin Gagarin <[email protected]>
  • Loading branch information
henrik-ch and fricklerhandwerk committed Jun 2, 2023
1 parent 4d59f3b commit 29e1e27
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
9 changes: 7 additions & 2 deletions pills/07-working-derivation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,15 @@
<varname>coreutils</varname>.
</para>
<para>
Then we meet the
Below is a revised version of the <filename>simple.nix</filename> file, using the <code>inherit</code> keyword:

<programlisting><xi:include href="./07/simple_inherit.txt" parse="text" /></programlisting>

Here we also take the opportunity to introduce the
<link xlink:href="https://nixos.org/manual/nix/stable/expressions/language-constructs.html#inheriting-attributes"><code>inherit</code> keyword</link>.
<code>inherit foo;</code> is equivalent to <code>foo = foo;</code>.
Similarly, <code>inherit foo bar;</code> is equivalent to <code>foo = foo; bar = bar;</code>.
Similarly, <code>inherit gcc coreutils;</code> is equivalent to <code> gcc = gcc; coreutils = coreutils;</code>.
Lastly, <code>inherit (pkgs) gcc coreutils;</code> is equivalent to <code> gcc = pkgs.gcc; coreutils = pkgs.coreutils;</code>.
</para>
<para>
This syntax only makes sense inside sets. There's no magic involved, it's
Expand Down
21 changes: 12 additions & 9 deletions pills/07/simple.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
with (import <nixpkgs> {});
derivation {
name = "simple";
builder = "${bash}/bin/bash";
args = [ ./simple_builder.sh ];
inherit gcc coreutils;
src = ./simple.c;
system = builtins.currentSystem;
}
let
pkgs = import <nixpkgs> {};
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;
}
11 changes: 11 additions & 0 deletions pills/07/simple_inherit.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
let
pkgs = import <nixpkgs> {};
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;
}

0 comments on commit 29e1e27

Please sign in to comment.