update nix.md
This commit is contained in:
parent
a44fc08a84
commit
25055b1fcc
1 changed files with 22 additions and 13 deletions
35
nix.md
35
nix.md
|
@ -156,10 +156,13 @@ derivation {
|
|||
system = builtins.currentSystem;
|
||||
}
|
||||
```
|
||||
<div class="eval">= derivation «/nix/store/ha5hof1nput-foobar.drv»</div>
|
||||
<div class="eval">= derivation «/nix/store/119h84n7a58069l5zi0rgs7q06rhrlh3-foobar.drv»</div>
|
||||
|
||||
To build this, use `:b (copy-pasted code)` in the repl. It should print
|
||||
a path to the build outputs.
|
||||
This code outputs a hash-based path to a derivation, nix's version of a
|
||||
build script. Derivations *derive* build outputs from build inputs. To
|
||||
build the derivation, use `:b (copy-pasted code)` in the repl. It should
|
||||
print a path to the build outputs. If you `cat` the output, you should
|
||||
get back "Hello, derivation!".
|
||||
|
||||
[NixOS/nixpkgs](https://github.com/NixOS/nixpkgs) is a combination package
|
||||
repository and standard library, containing thousands of derivations and
|
||||
|
@ -178,24 +181,24 @@ will *always* produce the same outputs. If it works on one nix user's
|
|||
machine, it will work every nix user's machine. If a build fails, it
|
||||
fails for everyone.
|
||||
|
||||
Flakes work by taking in an explicit set of inputs along with the build
|
||||
steps. Anything that isn't explicitly defined as an input, whether
|
||||
it's binaries, paths, or environment variables, is not given to the
|
||||
derivation's builder.
|
||||
|
||||
Here's an example flake:
|
||||
Nix flakes are a new tool that makes the inputs explicit as well, instead
|
||||
of only the build steps. Anything that isn't explicitly defined as an
|
||||
input, whether it's binaries, paths, or environment variables, is not
|
||||
given to the derivation's builder. Here's an example flake:
|
||||
|
||||
```nix
|
||||
{
|
||||
description = "any useful description here";
|
||||
|
||||
inputs = {
|
||||
# this is a flake identifier
|
||||
# Inputs take in flake references
|
||||
# https://nix.dev/manual/nix/2.18/command-ref/new-cli/nix3-flake#flake-references
|
||||
nixpkgs.url = "github:NixOS/nixpkgs";
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs }: {
|
||||
packages.x86_64-linux.default = inputs.nixpkgs.legacyPackages.x86_64-linux.hello;
|
||||
# reuse an existing derivation for simplicity
|
||||
packages.x86_64-linux.default = nixpkgs.legacyPackages.x86_64-linux.hello;
|
||||
};
|
||||
}
|
||||
```
|
||||
|
@ -222,8 +225,14 @@ another flake:
|
|||
packages.x86_64-linux.default = pkgs.stdenv.mkDerivation {
|
||||
name = "hello";
|
||||
src = self;
|
||||
buildPhase = "echo '#!/bin/sh\necho hello world' > bin; chmod +x bin";
|
||||
installPhase = "mkdir -p $out/bin; mv bin $out/bin/hello";
|
||||
buildPhase = ''
|
||||
echo '#!/bin/sh\necho hello world' > bin
|
||||
chmod +x bin
|
||||
'';
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
mv bin $out/bin/hello
|
||||
'';
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue