Video 76 reference
Also read:
https://wiki.nixos.org/wiki/Derivations
https://nix.dev/manual/nix/2.33/store/derivation/
Watch the video
Basic derivation
derivation {
name = "name";
builder = "/bin/sh";
args = ["-c" "echo 'hello world' > $out"];
system = "x86_64-linux";
} Build the package
$ nix-build ./path/to/derivation.nix Basic mkDerivation derivation
let
pkgs = import <nixpkgs> {};
in
pkgs.stdenv.mkDerivation {
name = "myPackage";
src = ./.;
buildPhase = ''
echo 'hello world' > $out
'';
} Build the package
$ nix-build ./path/to/derivation.nix Basic derivation
derivation {
name = "name";
builder = "/bin/sh";
args = ["-c" "echo 'hello world' > $out"];
system = "x86_64-linux";
} Build the package
$ nix-build ./path/to/derivation.nix CallPackage Derivation
{
stdenv,
}:
stdenv.mkDerivation {
name = "myPackage";
src = ./.;
buildPhase = ''
echo 'hello world' > $out
'';
} Build the package
$ nix-build -E 'with import <nixpkgs> {}; callPackage ./package.nix {}' nixpkgs will automatically provide all requested dependencies.
Flake Derivation
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
};
outputs = { self, nixpkgs }:
let
system = "x86_64-linux";
pkgs = import nixpkgs { inherit system; };
in {
packages.${system}.default =
pkgs.stdenv.mkDerivation {
pname = "myPackage";
version = "0.1.0";
src = ./.;
buildPhase = ''
echo 'hello world' > $out
'';
};
};
} Build the package
$ nix build /path/to/flake