-
It's the basis for everything and a pretty simple functional language
"JSON with
functionsfootguns" - It does have some easy to overlook subtleties:inherit (x) y;vs.inherit x y;vs.let ... invs.with ...;f: g: ret;vs.{ f, g }: ret{ f, g ? default, ...} @ attrs: ret -
Manuals: NixOS, nixpkgs, nix.conf, builtins, trivial builders, input references )
-
Code: nixpkgs, nix built-status
- Comparison: docker vs. nix
- showcase of nix
- vimjoyer tutorials
- Good enough
- nixcon
- Overlays
- nix-hour #19: module system
- nixcon: debugging closure size
- Home-Manager
- Nixvim
- Disko
- Chaotic Nyx
- NUR
- Deployment Tools (nixos-anywhere, colmena, deploy-rs, etc.)
let
commit = "345c263f2f53a3710abe117f28a5cb86d0ba4059";
pkgs = import (builtins.fetchTarball {
url = "https://github.com/NixOS/nixpkgs/archive/${commit}.tar.gz";
}) { config = {}; overlays = []; };
in
pkgs.mkShell {
name = "nix intro";
packages = [
pkgs.clolcat
pkgs.curl
];
shellHook = ''
echo Hallo von der nix shell
'';
}# File: configuration.nix
# Build with:
# NIXOS_CONFIG="$PWD/configuration.nix" nixos-rebuild build-vm
# # ...you might need `nix-shell -p nixos-rebuild` as it's only installed on NixOS by default
# Run with:
# ./result/bin/run-*-vm &
{ pkgs, lib, config, ... }:
{
# imports = [ ./some-file.nix ];
users.mutableUsers = false;
users.users.root.hashedPassword = "";
services.getty.autologinUser = "root";
system.stateVersion = config.system.nixos.release;
programs.git.enable = true;
programs.neovim = { enable = true; defaultEditor = true; viAlias = true; vimAlias = true; };
environment.systemPackages = with pkgs; [ ripgrep ];
virtualisation.vmVariant = {
virtualisation = {
qemu.options = [ "-nographic" ]; # qemu.options = [ "-vga virtio" ];
qemu.consoles = [ "ttyS0" ];
diskImage = null; # "./nixos.qcow2";
sharedDirectories.share = { source = toString ./.; target = "/etc/nixos"; };
mountHostNixStore = true;
writableStoreUseTmpfs = false;
};
boot.loader.grub.device = "nodev";
fileSystems."/" = {};
};
}# File: dockerlolcatalpine
FROM alpine:3.20.3
RUN : \
apk update && \
apk add --no-cache --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing/ lolcat
RUN cat > /entrypoint <<EOF
#!/bin/sh
echo -en "Nix build docker image\n" \
"Much nice, such wow!\n" \
"Can't contain happy.\n" | lolcat -f
EOF
RUN chmod +x /entrypoint
CMD [ "/entrypoint" ]
# Build with: docker build --tag dockerlolcatalpine --file dockerlolcatalpine . && docker run --rm dockerlolcatalpine#File: dockerlolcat.nix
{ pkgs ? (import <nixpkgs> { config = { }; overlays = [ ]; }).pkgsMusl, lib ? pkgs.lib, ... }:
pkgs.dockerTools.streamLayeredImage {
name = "dockerlolcatnix";
tag = "latest";
config.Cmd =
let
msg = pkgs.writeTextFile {
name = "msg.txt";
text = ''
Nix build docker image
Much nice, such wow!
Can't contain happy.
'';
};
in
[ "${lib.getExe pkgs.clolcat}" "-f" "${msg}" ];
}
# $(nix-build dockerlolcat.nix --no-out-link) | docker load && docker run --rm dockerlolcatnix$ docker images | grep lolcat
NAME TAG IMAGE AGE SIZE
dockerlolcatalpine latest ba0f95047ef9 6 days ago 7.85MB
dockerlolcatnix latest 55fb40eb145e 54 years ago 3.84MBecho Nix is Great | figlet
which clolcat # not there
echo Nix is Great | figlet | nix run "nixpkgs#clolcat"
echo Nix is Great | figlet | nix run "github:NixOS/nixpkgs/nixos-unstable#clolcat"
clolcat # still not there
nix-shell -p clolcat
which clolcat # somewhere in /nix/store/ now
nix-shell shell.nix # see snippets
which clolcat
echo ... | clolcat
cd ~/devel/python/stechuhr # advanced example
Depencency tree...
nix-visualize $(realpath $(which clolcat)) -c .viz.cfg -s nix -o clol.png
nix-tree --derivation 'nixpkgs#nix'
chromium --new-window https://mercurytechnologies.github.io/looking-glass-viewer/ >/dev/null 2>&1 &
./nix-closure-graph/nix-closure-graph --lg 'nixpkgs#jupyter' | xclip -i -selection clipboard
nix-build shell.nix # see snippets
ls -hl result
ls -hl /nix/var/nix/gcroots/auto/ | grep -F "$(pwd)"
cat result
firefox --new-window https://github.com/nixos/nixpkgs
vi /etc/nixpkgs/pkgs/tools/misc/clolcat/default.nix
firefox --new-window https://search.nixos.org/options
vi configuraiton.nix
NIXOS_CONFIG="$PWD/configuration.nix" nixos-rebuild build-vm --max-jobs auto --builders ''
ll result/system/
./result/bin/run-nixos-vm -nographic; reset
firefox --new-window https://github.com/nix-community/nixos-generators?tab=readme-ov-file#supported-formats
firefox https://github.com/nix-community/NixOS-WSL
nix build nixpkgs#pkgsCross.riscv64.clolcat
file result/bin/clolcat
# File: options.nix
{ lib, config, ... }:
let
inherit (lib) types mkOption;
toyType = types.submodule (
{ name, ... }: # name, lib, options, config, specialArgs
{
options = {
name = mkOption {
type = types.str;
default = name;
readOnly = true;
};
manual = mkOption {
type = with types; nullOr str;
description = "Where the toys manual is";
default = "default";
};
};
}
);
in
{
options = {
description = mkOption { type = types.str; default = "My toybox"; };
toys = mkOption {
type = with types; attrsOf toyType;
};
};
config = {
# This toy is in every toybox
toys.teddyBear = { manual = "https://mr-snuggles.com"; };
};
}# File: default.nix
let
pkgs = import <nixpkgs> { config = {}; overlays = []; };
result = pkgs.lib.evalModules {
modules = [
./options.nix # <-- this is where we use our module
{
toys = {
barbie = { manual = "https://martell.com"; };
marbles = { manual = null; };
};
}
];
};
in
result.config
# nix eval --file default.nix | nix run 'nixpkgs#alejandra' -- --quiet -
Uh oh!
There was an error while loading. Please reload this page.