1
1
mirror of https://github.com/divnix/digga.git synced 2024-11-23 20:22:04 +03:00
digga/doc/concepts/hosts.md
Pacman99 aa825b87a6 auto import hosts in flake.nix
this allows host-specific settings to be overriden with mkMerge
2021-04-27 10:26:45 -07:00

2.0 KiB

Hosts

Nix flakes contain an output called nixosConfigurations declaring an 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.

As an example, a file hosts/system.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.

For each host, the configuration automatically sets the networking.hostName attribute to the name of the file minus the .nix extension. This is for convenience, since nixos-rebuild automatically searches for a configuration 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 repository.

It is recommended that the host modules only contain configuration information specific to a particular piece of hardware. Anything reusable across machines is best saved for profile modules.

This is a good place to import sets of profiles, called suites, that you intend to use on your machine.

Example

flake.nix:

{
  nixos.hosts = mkMerge [
    (devos.lib.importHosts ./hosts)
    {
      librem = {
        channelName = "latest";
        modules = [ hardware.purism-librem-13v3 ];
      };
    }
  ];
}

hosts/librem.nix:

{ suites, ... }:
{
  imports = suites.laptop;

  boot.loader.systemd-boot.enable = true;
  boot.loader.efi.canTouchEfiVariables = true;

  fileSystems."/" = { device = "/dev/disk/by-label/nixos"; };
}