Skip to content

NixOS Support

Nilla provides support for NixOS using the nixos module and its accompanying CLI plugin. To get started, we will add the module to our project and install the CLI plugin so that we can work with the NixOS systems we create.

CLI Plugin

To interact with NixOS systems in Nilla projects, we will use the Nilla NixOS CLI plugin.

Terminal window
# We can install the package imperatively.
nix profile install github:nilla-nix/nixos
# Or we can run the Nilla NixOS CLI directly on-demand.
nix run github:nilla-nix/nixos -- --help

Nilla Module

For creating NixOS system configurations in Nilla projects, we will need to include the Nilla NixOS module. First, we will need to fetch Nilla NixOS for use in the project. We can do this using a tool like npins.

Terminal window
npins add --name nilla-nixos github nilla-nix nixos

With the dependency available, we can now include the module in our Nilla project.

nilla.nix
let
pins = import ./npins;
nilla = import pins.nilla;
in
nilla.create {
includes = [
"${pins.nilla-nixos}/modules/nixos.nix"
];
}

Create a NixOS system

NixOS systems are created with the configuration options under systems.nixos.*. Each NixOS system has its own configuration in this attribute set. The following sample creates a system named example for the x86_64-linux platform.

nilla.nix
let
pins = import ./npins;
nilla = import pins.nilla;
in
nilla.create ({ config }: {
includes = [
"${pins.nilla-nixos}/modules/nixos.nix"
];
config = {
inputs.nixpkgs.src = pins.nixos-unstable;
systems.nixos.example = {
pkgs = config.inputs.nixpkgs.result.x86_64-linux;
modules = [
# Here you can include your NixOS configuration files or inline modules.
./configuration.nix
];
};
};
})

Using NixOS systems

Now that we have a NixOS system defined, we can use the Nilla CLI to interact with it. With the NixOS CLI plugin installed, we can use the nilla nixos command to build, switch, and otherwise operate on our NixOS systems.

Terminal window
# Build the system.
nilla nixos build example
# Or build and switch to the new configuration.
nilla nixos switch example