mirror of
https://github.com/ryan4yin/nixos-and-flakes-book.git
synced 2025-07-25 15:34:50 +02:00
994 B
994 B
Updating the System
With Flakes, updating the system is straightforward. Simply execute the following commands
in /etc/nixos
or any other location where you keep the configuration:
Note
: The
/etc/nixos
directory is owned by and only writable toroot
. Therefore, if your flake is located in this directory, you'll need to usesudo
to update any configuration files.
# Update flake.lock
nix flake update
# Or update only the specific input, such as home-manager:
nix flake update home-manager
# Apply the updates
sudo nixos-rebuild switch
# Or if your flake is not located at /etc/nixos
sudo nixos-rebuild switch --flake /path/to/flake
# Or to update flake.lock & apply with one command (i.e. same as running "nix flake update" before)
sudo nixos-rebuild switch --recreate-lock-file
Occasionally, you may encounter a "sha256 mismatch" error when running
nixos-rebuild switch
. This error can be resolved by updating flake.lock
using
nix flake update
.