Skip to content

brainrake/nixos-tutorial

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 

Repository files navigation

check out the cheat sheet

outline

  • setup (5m)
  • nix-env package management (10m)
  • nix-shell isolated environments (10m)
  • NixOS declarative operating system configuration
    • introduction (5m)
    • service (5m)
    • network (5m)
    • user (5m)
  • conclusion (5m)

setup

nix-env package management

  • each user has a nix profile, pointing to the current user environment, that is a set of installed packages, managed via nix-env
  • only trusted channels are used by default, so updating the package lists is the only operation requiring root.
update package list sudo nix-channel --update
search nix search hello also try search.nixos.org/packages
install nix-env -iA nixos.hello run it with hello
uninstall nix-env -e hello running hello fails
rollback nix-env --rollback hello is back

nix-shell isolated environments

  • start a shell in an environment with some packages available, and run some commands in it:
    • nix-shell -p toilet
      • toilet NixOS
      • Ctrl+D to exit nix-shell
      • toilet NixOS fails
  • start a shell with packages and run a command in it:
    • nix-shell -p toilet --run 'toilet --gay hello'
  • try a python example
  • nix-shell on its own will load default.nix or shell.nix from the current directory, where you can define an environment for a project.

NixOS declarative operating system configuration

  • edit /etc/nixos/configuration.nix
    • eg. add services.openssh.enable = true; before the last }
  • nixos-rebuild switch to the new configuration
  • nixos-option services.openssh.enable to see the option's current value and documentation
  • find the option on search.nixos.org/options, click the result, click the link after "Declared in:" and see The Source
  • nixos-rebuild switch --rollback to previous configuration

let's try a few configuration options:

service

system

user

network

  • networking.hostName = "darkstar";
  • networking.firewall.allowedTCPPorts = [ 22 80 8000 ];

conclusion

  • declarative - say what you want, not how to get there
  • safe (atomic, rollback, isolated, consistent, hash-checked)
  • reliable (deterministic, reproducible)
  • fast (lazy, hash-based store, binary cache)
  • great for repeatable builds and declarative operating system configuration