mirror of
https://github.com/NixOS/nix-pills
synced 2024-09-19 04:00:13 -04:00
with removed from first line (#213)
* with removed from first line example no longer starts with with (import <nixpkgs> {}); * added inherit example and comments. Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io>
This commit is contained in:
parent
4d59f3bb11
commit
29e1e273b8
|
@ -307,10 +307,15 @@
|
||||||
<varname>coreutils</varname>.
|
<varname>coreutils</varname>.
|
||||||
</para>
|
</para>
|
||||||
<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>.
|
<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>.
|
<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>
|
||||||
<para>
|
<para>
|
||||||
This syntax only makes sense inside sets. There's no magic involved, it's
|
This syntax only makes sense inside sets. There's no magic involved, it's
|
||||||
|
|
|
@ -1,9 +1,12 @@
|
||||||
with (import <nixpkgs> {});
|
let
|
||||||
derivation {
|
pkgs = import <nixpkgs> {};
|
||||||
name = "simple";
|
in
|
||||||
builder = "${bash}/bin/bash";
|
pkgs.stdenv.mkDerivation {
|
||||||
args = [ ./simple_builder.sh ];
|
name = "simple";
|
||||||
inherit gcc coreutils;
|
builder = "${pkgs.bash}/bin/bash";
|
||||||
src = ./simple.c;
|
args = [ ./simple_builder.sh ];
|
||||||
system = builtins.currentSystem;
|
gcc = pkgs.gcc;
|
||||||
|
coreutils = pkgs.coreutils;
|
||||||
|
src = ./simple.c;
|
||||||
|
system = builtins.currentSystem;
|
||||||
}
|
}
|
11
pills/07/simple_inherit.txt
Normal file
11
pills/07/simple_inherit.txt
Normal file
|
@ -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;
|
||||||
|
}
|
Loading…
Reference in a new issue