2021-02-13 19:38:20 -07:00
|
|
|
# Hosts
|
|
|
|
|
|
|
|
Nix flakes contain an output called `nixosConfigurations` declaring an
|
2021-04-27 10:26:45 -07:00
|
|
|
attribute set of valid NixOS systems. To simplify the management and creation
|
|
|
|
of these hosts, devos automatically imports every _.nix_ file inside this
|
|
|
|
directory to the mentioned attribute set, applying the projects defaults to
|
|
|
|
each. The only hard requirement is that the file contain a valid NixOS module.
|
2021-02-13 19:38:20 -07:00
|
|
|
|
2021-06-03 12:25:06 -07:00
|
|
|
As an example, a file `hosts/system.nix` or `hosts/system/default.nix` will
|
|
|
|
be available via the flake output `nixosConfigurations.system`. You can have
|
|
|
|
as many hosts as you want and all of them will be automatically imported based
|
|
|
|
on their name.
|
2021-02-13 19:38:20 -07:00
|
|
|
|
|
|
|
For each host, the configuration automatically sets the `networking.hostName`
|
2021-06-03 12:25:06 -07:00
|
|
|
attribute to the folder name or name of the file minus the _.nix_ extension. This
|
|
|
|
is for convenience, since `nixos-rebuild` automatically searches for a configuration
|
2021-04-27 10:26:45 -07:00
|
|
|
matching the current systems hostname if one is not specified explicitly.
|
|
|
|
|
|
|
|
You can set channels, systems, and add extra modules to each host by editing the
|
|
|
|
`nixos.hosts` argument in flake.nix. This is the perfect place to import
|
|
|
|
host specific modules from external sources, such as the
|
|
|
|
[nixos-hardware][nixos-hardware] repository.
|
2021-02-13 19:38:20 -07:00
|
|
|
|
|
|
|
It is recommended that the host modules only contain configuration information
|
|
|
|
specific to a particular piece of hardware. Anything reusable across machines
|
2021-04-18 20:26:27 -06:00
|
|
|
is best saved for [profile modules](./profiles.md).
|
2021-02-13 19:38:20 -07:00
|
|
|
|
2021-04-18 20:26:27 -06:00
|
|
|
This is a good place to import sets of profiles, called [suites](./suites.md),
|
2021-02-13 19:38:20 -07:00
|
|
|
that you intend to use on your machine.
|
|
|
|
|
|
|
|
## Example
|
|
|
|
|
2021-04-27 10:26:45 -07:00
|
|
|
flake.nix:
|
2022-11-20 23:28:23 +01:00
|
|
|
|
2021-04-27 10:26:45 -07:00
|
|
|
```nix
|
|
|
|
{
|
2021-05-18 10:23:43 -07:00
|
|
|
nixos = {
|
|
|
|
imports = [ (devos.lib.importHosts ./hosts) ];
|
|
|
|
hosts = {
|
2021-04-27 10:26:45 -07:00
|
|
|
librem = {
|
|
|
|
channelName = "latest";
|
2021-05-18 18:11:29 +02:00
|
|
|
modules = [ nixos-hardware.nixosModules.purism-librem-13v3 ];
|
2021-04-27 10:26:45 -07:00
|
|
|
};
|
2021-05-18 10:23:43 -07:00
|
|
|
};
|
|
|
|
};
|
2021-04-27 10:26:45 -07:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2021-02-14 17:41:15 -07:00
|
|
|
hosts/librem.nix:
|
2022-11-20 23:28:23 +01:00
|
|
|
|
2021-02-13 19:38:20 -07:00
|
|
|
```nix
|
2021-04-27 10:26:45 -07:00
|
|
|
{ suites, ... }:
|
2021-02-13 19:38:20 -07:00
|
|
|
{
|
2021-04-27 10:26:45 -07:00
|
|
|
imports = suites.laptop;
|
2021-02-13 19:38:20 -07:00
|
|
|
|
|
|
|
boot.loader.systemd-boot.enable = true;
|
|
|
|
boot.loader.efi.canTouchEfiVariables = true;
|
|
|
|
|
|
|
|
fileSystems."/" = { device = "/dev/disk/by-label/nixos"; };
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
[nixos-hardware]: https://github.com/NixOS/nixos-hardware
|