> Proper way to build a remote system with flakes - discourse.nixos.org > Awesome Nix - github
> Nix4Noobs VM
Building to a remote server
# nixos-rebuild switch --flake .#myMachine --target-host user@system
examples:
# nixos-rebuild switch --flake .#system --target-host [email protected]
NixOS system in ./result
The build command to end up with a nixOS in ./result:
- Use this one if you don’t have nixOS but only nix available (e.g. on a CI action)
# nix build .#nixosConfigurations.staging.config.system.build.toplevel
# nixos-rebuild build --flake .#staging
Note that nixosConfigurations prefix is ommitted if nixos-rebuild is used. The error messages differ and are somewhat more usable via nixos-rebuild command, although it lacks a -o flag, so you can’t build multiple results next to each other without manually renaming them between builds.
…
This defines a system configuration called computer1
, this configuration can be built on a NixOS system with the next command.
$ sudo nixos-rebuild switch --flake /path/to/flake#computer1
-> ./flake.nix
{
description = "Simple nixOS flake";
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
outputs = {
self,
nixpkgs
}: {
nixosConfigurations = {
computer1 = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
specialArgs = {
# Inherit argument from let here, or define arguments.
#inherit argument;
hostname = "computer1";
};
modules = [
./hosts/computer1
# Add inputs here (like disko.nixosModules.disko)
];
# Example how to pass an arg to configuration.nix:
};
#computer2 = nixpkgs.lib.nixosSystem {
#system = "x86_64-linux";
# ...
};
};
};
}
-> ./hosts/computer1/default.nix
{
imports = [
configuration.nix
hardware-configuration.nix
];
}
-> ./hosts/computer1/configuration.nix:
{ config, pkgs, hostname, ... }: {
networking.hostName = hostname;
...
}