Keep modules. Add an entry point.
On an existing NixOS machine, place flake.nix alongside configuration.nix. Keep all hardware, boot, filesystem, user, and stateVersion settings from that installation.
The output name workstation is chosen by you. It is the selector after # in the rebuild command; it does not have to be the same as networking.hostName. This example follows nixos-unstable; choose an appropriate maintained release branch if you want the stable release workflow.
{
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
outputs = { nixpkgs, ... }: {
nixosConfigurations.workstation = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [ ./configuration.nix ];
};
};
}
An explicit configuration to rebuild.
From that configuration directory, ensure newly referenced files are tracked if you use Git. Create and review the lock, then build before activating.
The switch command applies changes to the machine running it. Use the correct machine configuration, and commit both Nix files and the lock file after checking the result.
nix flake lock
sudo nixos-rebuild build --flake .#workstation
# After reviewing the build:
sudo nixos-rebuild switch --flake .#workstation
nixosConfigurations.<name> connects a locked input graph to an existing set of system modules.