Skip to content

Instantly share code, notes, and snippets.

@dacr
Created January 12, 2025 23:19
Show Gist options
  • Save dacr/b6dddb42b346c724361d01d45a8c7f4a to your computer and use it in GitHub Desktop.
Save dacr/b6dddb42b346c724361d01d45a8c7f4a to your computer and use it in GitHub Desktop.
nixos cheat sheet / published by https://github.com/dacr/code-examples-manager #9e9f9a93-ca32-46a9-bad3-6f6d2977ca8f/6e3a40989446c92a1fd394cd8906dc1d62259468

nixos cheat sheet

Notes

Installing NIXOS

make ISO image

lsblk
sudo dd of=/dev/sdh if=~/Downloads/nixos-gnome-21.11.337514.4c560cc7ee5-x86_64-linux.iso
sudo dd of=/dev/sdc1 if=nixos-gnome-22.05.2676.b9fd420fa53-x86_64-linux.iso

Operating NIXOS

  • sudo vi /etc/nixos/configuration.nix
  • sudo nixos-rebuild switch
  • encoding users password in configuration.nix
    1. mkpasswd -m sha-512
    2. And in configuration.nix : hashedPassword="..."
    3. OF course this is not a best practice ;)

Search for packages

  • by regex :
    nix-env -qa 'i3.*'
    nix-env -qa '.*idea.*'
    
  • by package name : nix search xfce (experimental)
  • by command name : command-not-found make
  • which package : nix-locate /bin/sh

Updates

sudo nix-channel --update
sudo nixos-rebuild switch

Upgrades

sudo nix-channel --list
sudo nix-channel --add https://nixos.org/channels/nixos-22.05 nixos
sudo nix-channel --add https://nixos.org/channels/nixos-22.11 nixos
sudo nix-channel --add https://nixos.org/channels/nixos-23.11 nixos

Cleanup

nix-collect-garbage
nix-collect-garbage -d

Cleanup boot

For example when build fail because no more space in /boot/ file system

nix-env --list-generations --profile /nix/var/nix/profiles/system

nix-env --delete-generations --profile /nix/var/nix/profiles/system --delete-generations +5
nix-env --delete-generations --profile /nix/var/nix/profiles/system 199 198 197

Unstable channel

sudo nix-channel --add https://nixos.org/channels/nixos-unstable nixpkgs-unstable

And to make it available in /etc/nixos/configuration.nix as for example unstable.jetbrains.idea-ultimate :

{ config, pkgs, ... }:

let
  unstable = import <nixpkgs-unstable> {
    config.allowUnfree = true;
  };
in
{{ config, pkgs, ... }:

let
  unstable = import <nixpkgs-unstable> {
    config.allowUnfree = true;
  };
in
{
...
}

Temporary install :)

  • ephemeral install : nix-shell -p nmap
    • just for the started shell session life time !!!!! :)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment