Building nixos system with nix build and a channel specifier

With nixpkgs added via nix-channel I can build the nixos config with

nix build -f '<nixpkgs/nixos>' system

Is there a similar way to build the nixos config with nix build from a channel specifier, e.g. channel:nixos-19.09?

You can use the pkgs.nixos function for this.
e.g. https://github.com/arianvp/nixos-stuff/blob/f34eb42447956e62b5a8c0b0419d0102826a6c15/deployments.nix#L64-L68

Also; with nix-flakes, this will be supported by default: https://github.com/NixOS/nixpkgs/pull/68897

1 Like

nix build -I nixpkgs=channel:nixos-19.09 -f '<nixpkgs/nixos>' system

Oh that was obvious XD I basically do that already when building the git repo…