Skip to content

Commit

Permalink
added inherit example and comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
henrik-ch committed Jun 2, 2023
1 parent d73521d commit db29497
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 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 inherit 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
12 changes: 12 additions & 0 deletions pills/07/simple_inherit.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
let
pkgs = import <nixpkgs> {};
inherit (pkgs) gcc coreutils;
in
pkgs.stdenv.mkDerivation {
name = "simple";
builder = "${pkgs.bash}/bin/bash";
args = [ ./simple_builder.sh ];
inherit gcc coreutils;
src = ./simple.c;
system = builtins.currentSystem;
}

0 comments on commit db29497

Please sign in to comment.