Daniel Schaefer
August 10, 2018
On installation:
/nix/{store,var}
nix-daemon.service
During runtime:
/nix/{store,var}
$PATH
/nix/store/xxxxxx
in current directory named result
{ stdenv, fetchurl }:
stdenv.mkDerivation rec {
name = "hello-2.10";
src = fetchurl {
url = "mirror://gnu/hello/${name}.tar.gz";
sha256 = "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89n";
};
}
stdenv.mkDerivation
calls ./configure
and make
and make install
src = fetchurl {
url = "mirror://gnu/hello/${name}.tar.gz";
sha256 = "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89n";
};
https://github.com/nixos/nixpkgs has ~150k commits and 1700+ contributors
name = "hello-${version}";
version = "2.10";
src = fetchurl {
url = "mirror://gnu/hello/${name}.tar.gz";
sha256 = "0ssi1wpaf7plaswqqjwigppsg5fyh99vdlb9kzl7c9lng89n";
};
nix-collect-garbage
if running low on space$ nix-env -i chromium
$ chromium
Image you didn’t want PHP installed but had to demonstrate it’s flaws:
$ nix-shell -p php
$ php -a
Interactive shell
php > var_dump(1 == "1el0");
bool(true)
php > var_dump(1 == "1e10");
bool(false)
php > exit
$ man php
$ exit
$ php
php: command not found
Python is better than PHP but you need packages for many things
nix-shell -p python36Packages.matplotlib python36Packages.ipython --command ipython
(e.g. make gcc dependencies)
$ git clone https://github.com/qemu/qemu
$ cd qemu
$ nix-shell '<nixpkgs>' -A qemu
$ ./configure
$ make
$ ./x86_64-softmmu/qemu-system-x86_64
iso.nix
{config, pkgs, ...}:
{
imports = [
<nixpkgs/nixos/modules/installer/cd-dvd/installation-cd-minimal.nix>
];
}
nix-build '<nixpkgs/nixos>' -A config.system.build.isoImage -I nixos-config=iso.nix
{config, pkgs, ...}:
{
imports = [
<nixpkgs/nixos/modules/installer/cd-dvd/installation-cd-minimal.nix>
];
environment.systemPackages = [
cowsay vim tmux git wget
];
}
But! This is about Nix not NixOS
nix-build '<nixpkgs>' -A hello --option build-use-substitutes false
nix-build '<nixpkgs>' --arg crossSystem '(import <nixpkgs> {}).lib.systems.examples.aarch64-multiplatform' -A hello
$ cat default.nix
with import <nixpkgs> {};
stdenv.mkDerivation {
name = "why-nix-presentation";
src = ./.;
buildInputs = with pkgs; [ pandoc ];
}
$ nix-build
$ firefox result
nix-shell --command make
Add single line to $package.nix
:
patches = [ ./covfefe.diff ];
For developing use current directory:
src = ./.;
Use own fork:
src = fetchFromGitHub {
owner = "me";
repo = "fork";
rev = "v${version}";
sha256 = "1gd0bq5x49sjm83r2wivjf03dxvhdli6cvwb9b853wwcvy4";
};
configurePhase = ''
./weird-configure
'';
Just look at the package in $nixpkgs
$ nix-shell -p cowsay --command "cowsay Nix works!"
____________
< Nix works! >
------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
let
fetchNixpkgs = { rev, sha256 } : builtins.fetchTarball {
url = "https://github.com/NixOS/nixpkgs/archive/${rev}.tar.gz";
inherit sha256;
};
in
import (fetchNixpkgs {
rev = "5141f28405e5d31f21c10869dfc86ff340053787";
sha256 = "0q91kfxg950g1nr71ifxhb4gfn3vfs4szh2yn7z8s2xri4l36p5m";
}) { config = {}; }
$ nix-shell -p openssl_1_0_2 --command "openssl version"
OpenSSL 1.0.2o 27 Mar 2018
$ nix-shell -p openssl_1_1_0 --command "openssl version"
OpenSSL 1.1.0h 27 Mar 2018
Nothing can screw with installed packages
Package is dependent on:
Configure entire system declaratively
networking.interfaces.eth0.ipv4. = [{
address = "192.168.192.1";
prefixLength = 24;
}];
time.timeZone = "Europe/London";
services.openssh.enable = true;
boot.kernelPackages = pkgs.linuxPackages_4_17;
users.extraUsers.elprofesor.isNormalUser = true;
boot.loader = {
systemd-boot.enable = true;
efi.canTouchEfiVariables = false;
};
boot.kernelModules = [ "kvm-intel" ];