Slide 1 / 20
Nix Learning Curriculum
Dari Dasar hingga Mahir
Back
Next
Overview
Tujuan Pembelajaran
Goals
Memahami konsep dasar Nix
Mampu menggunakan Nix sebagai package manager
Membuat Nix expressions dan derivations
Menggunakan NixOS untuk system configuration
Membangun environment reproducible dengan Nix flakes
Back
Next
Minggu 1
Dasar-Dasar Nix
Jadwal Minggu 1
Hari
Topik
Praktik
1
Pengenalan Nix
Apa itu Nix? Sejarah, ekosistem
2
Instalasi
Install Nix di Linux/macOS/WSL
3
Package Management Dasar
nix-env -i, nix-search, nix-channel
4
Run Commands
nix run, nix-shell
5
Nix Store
Memahami /nix/store
Back
Next
Minggu 1 - Hari 1
Kenapa Nix?
Definisi: Nix adalah package manager dan OS configuration tool yang powerful
Keunggulan Nix
Reproducible - Environment sama di mana saja
Atomic - Upgrade/rollback aman
Declarative - State yang diinginkan, bukan cara mendapatkannya
Pure - Input sama - Output sama
Ekosistem Nix
nix - Package manager
nix-darwin - macOS configuration
NixOS - Linux distribution
Back
Next
Minggu 1 - Hari 2
Instalasi Nix
Install Nix (Single-User Mode)
# Install Nix
sh <(curl -L https://nixos.org/nix/install) --no-daemon
# Aktifkan flakes (edit ~/.config/nix/nix.conf)
experimental-features = nix-command flakes
# Verify
nix --version
Catatan: Untuk multi-user installation, gunakan tanpa flag --no-daemon
Konfigurasi Awal
# Buat config directory
mkdir -p ~/.config/nix
# Edit nix.conf
echo "experimental-features = nix-command flakes" > ~/.config/nix/nix.conf
Back
Next
Minggu 1 - Hari 3-4
Package Management Dasar
Cari - Install Package
# Cari package
nix search nixpkgs vim
# Install package (ke user profile)
nix-env -iA nixpkgs.vim
# List installed packages
nix-env -q
# Uninstall
nix-env -e vim
# Upgrade semua
nix-env -u
Run Tanpa Install
# Run tanpa install
nix run nixpkgs#vim
# Shell sementara dengan dependencies
nix-shell -p vim git
Tips: Gunakan nix run untuk mencoba aplikasi tanpa menginstall
Back
Next
Minggu 1 - Hari 5
Nix Store
Apa itu Nix Store? Direktori khusus tempat Nix menyimpan semua package (/nix/store)
Struktur Nix Store
/nix/store/
├── 1a2b3c...-vim-9.0/ # Each package has hash
├── 4d5e6f...-gcc-13.2.0/
└── ...hash...-glibc-2.38/
Karakteristik
Content-addressable - Hash menentukan content
Garbage Collection - Bersihkan package yang tidak terpakai
Generations - Timeline perubahan sistem
Commands Penting
# Garbage collection
nix-collect-garbage -d
# List generations
nix-env --list-generations
Back
Next
Minggu 2
Nix Expressions - Derivations
Jadwal Minggu 2
Hari
Topik
Praktik
1
Nix Language Basics
Syntax, types, functions
2
Nix Expressions
Memahami .nix files
3
Build dari awal Derivations>
4
Build Pipeline
Builder scripts, phases
5
Kuis - Latihan
Build package sederhana
Back
Next
Minggu 2 - Hari 1
Nix Language Basics
Tipe Data
123 # integer
"hello" # string
[1 2 3] # list
{ a = 1; b = 2; } # attribute set
true / false # boolean
Let Expression
let
x = 1;
y = 2;
in x + y # = 3
Function
add = x: y: x + y
add 1 2 # = 3
# With statement
with builtins; min 1 2 # = 1
# If
if true then "yes" else "no"
# String interpolation
name = "world";
"hello ${name}" # = "hello world"
Back
Next
Minggu 2 - Hari 2
Nix Expressions
Nix Expression adalah cara declarative untuk mendeskripsikan package dan environment
Contoh hello.nix
{ pkgs ? import {} }:
pkgs.mkShell {
name = "hello-env";
buildInputs = [ pkgs.hello pkgs.git ];
}
Cara Menggunakan
# Build dan masuk shell
nix-shell hello.nix
# Atau build
nix-build hello.nix
./result/bin/hello
Back
Next
Minggu 2 - Hari 3-4
Derivations
Derivation adalah deskripsi build process dalam Nix - bagaimana membuat sebuah package
Contoh my-derivation.nix
{ stdenv, fetchurl }:
stdenv.mkDerivation rec {
pname = "hello";
version = "2.12.1";
src = fetchurl {
url = "https://ftp.gnu.org/hello/hello-${version}.tar.gz";
sha256 = "sha256-...=";
};
configureFlags = [ "--prefix=${placeholder "out"}" ];
meta = with stdenv.lib; {
description = "A GNU Hello world program";
homepage = "https://www.gnu.org/software/hello/";
license = licenses.gpl3;
};
}
Build
nix-build my-derivation.nix
Back
Next
Minggu 3
NixOS - Configuration
Jadwal Minggu 3
Hari
Topik
Praktik
1
NixOS Concepts
Declarative system configuration
2
Configuration.nix
Setup dasar (users, packages, services)
3
Modules
Membuat module sendiri
4
Option Types
Types di NixOS options
5
Modules Reusable
Import/export modules
Back
Next
Minggu 3 - Hari 1-2
NixOS Configuration
/etc/nixos/configuration.nix
{ config, pkgs, ... }:
{
# Boot
boot.loader.grub.enable = true;
boot.loader.grub.device = "/dev/sda";
# Networking
networking.hostName = "myhost";
networking.firewall.allowedTCPPorts = [ 80 443 ];
# Users
users.users.alice = {
isNormalUser = true;
extraGroups = [ "wheel" ];
};
# Packages
environment.systemPackages = with pkgs; [
vim
git
curl
];
# Services
services.openssh.enable = true;
services.nginx.enable = true;
# Timezone
time.timeZone = "Asia/Jakarta";
}
Apply - Rollback
# Apply configuration
sudo nixos-rebuild switch
# Rollback
sudo nixos-rebuild switch --rollback
# Upgrade
sudo nixos-rebuild switch --upgrade
Back
Next
Minggu 4
Flakes - Advanced
Jadwal Minggu 4
Hari
Topik
Praktik
1
Flakes Intro
Apa itu flakes? flake.nix, flake.lock
2
NixOS Modules with Flakes
Modern NixOS setup
3
Home Manager
User config dengan Nix
4
DevShells
Development environments
5
Project Summary
Deploy project nyata
Back
Next
Minggu 4 - Hari 1
Flakes
Flakes adalah fitur experimental yang menyediakan cara baru untuk mengelola Nix projects dengan dependency tracking yang lebih baik
flake.nix
{
description = "My NixOS Configuration";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
home-manager.url = "github:nix-community/home-manager";
home-manager.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = { self, nixpkgs, home-manager, ... }:
let
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
in
{
nixosConfigurations.myhost = nixpkgs.lib.nixosSystem {
system = system;
modules = [ ./configuration.nix ];
};
};
}
Flakes Commands
nix flake show # Show flake outputs
nix flake update # Update inputs
Back
Next
Minggu 4 - Hari 4
DevShells
DevShells adalah development environment yang reproducible menggunakan Nix flakes
Contoh DevShell di flake.nix
devShells.${system}.default = pkgs.mkShell {
packages = [
pkgs.nodejs_20
pkgs.yarn
pkgs.python3
pkgs.postgresql
];
# Environment variables
GREETING = "Hello from Nix!";
# Shell hook
shellHook = ''
echo "Dev shell activated!"
'';
};
Cara Menggunakan
# Enter dev shell
nix develop
# Or with custom name
nix develop .#myapp
Back
Next
Minggu 4 - Hari 3
Home Manager
Home Manager adalah tool untuk mengelola user configuration (dotfiles, packages, settings) menggunakan Nix
Contoh home.nix
{ config, pkgs, ... }:
{
home.username = "alice";
home.homeDirectory = "/home/alice";
# Packages
home.packages = with pkgs; [
vim
fish
starship
];
# Programs
programs.fish.enable = true;
programs.starship.enable = true;
programs.git.enable = true;
# Dotfiles
home.file.".vimrc".source = ./vimrc;
home.stateVersion = "24.05";
}
Back
Next
Reference
Cheat Sheet
Package Management
nix search nixpkgs <package> # Cari package
nix-env -iA nixpkgs.<package> # Install
nix-env -e <package> # Uninstall
nix-env -q # List installed
Shell - Run
nix-shell -p <packages> # Shell dengan packages
nix run nixpkgs#<package> # Run tanpa install
Build
nix-build <file.nix> # Build derivation
nix develop # Enter dev shell
NixOS
nixos-rebuild switch # Apply config
nixos-rebuild switch --rollback # Rollback
Garbage Collection
nix-collect-garbage -d # Clean up
Back
Next
Reference
Referensi
Official
Learning Resources
Tools
Back
Next
Final
Next Steps
Setelah Mahir
Deploy ke VPS - NixOS di cloud
Build custom ISO - NixOS dengan config sendiri
NixOps - NixOS deployment
Cachix - Binary cache untuk CI/CD
Contribute ke nixpkgs - Open source!
Selamat! Anda telah menyelesaikan Nix Learning Curriculum. Practice makes perfect!
Back
Restart