1
0
Fork 0
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:
Henrik 2023-06-02 17:17:10 +01:00 committed by GitHub
parent 4d59f3bb11
commit 29e1e273b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 11 deletions

View file

@ -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

View file

@ -1,9 +1,12 @@
with (import <nixpkgs> {});
derivation {
let
pkgs = import <nixpkgs> {};
in
pkgs.stdenv.mkDerivation {
name = "simple";
builder = "${bash}/bin/bash";
builder = "${pkgs.bash}/bin/bash";
args = [ ./simple_builder.sh ];
inherit gcc coreutils;
gcc = pkgs.gcc;
coreutils = pkgs.coreutils;
src = ./simple.c;
system = builtins.currentSystem;
}

View 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;
}