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.
# 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
# We'll install the Nilla NixOS CLI package for your system architecture.system=$(nix-instantiate --eval --expr 'builtins.currentSystem' | tr -d '"')
# Install the package imperatively.nix-env -iA packages.default.result.${system} https://github.com/nilla-nix/nixos/archive/main.tar.gz
{ description = "My Flake that contains my NixOS system configuration.";
inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
# Add the Nilla NixOS CLI as an input in your flake. nilla-nixos.url = "github:nilla-nix/nixos"; };
outputs = { nixpkgs, nilla-nixos, ... }: { nixosConfigurations.myhost = nixpkgs.lib.nixosSystem { system = "x86_64-linux";
modules = [ ./configuration.nix ./hardware-configuration.nix
# Add an additional module to your system configuration. ({ pkgs, ... }: { environment.systemPackages = [ # Add the Nilla CLI to your system packages. nilla-nixos.packages.${pkgs.system}.default ]; }) ]; }; };}
{ pkgs, ... }:let # Fetch and import the Nilla NixOS CLI. nilla-nixos = import (pkgs.fetchFromGitHub { owner = "nilla-nix"; repo = "nixos"; rev = "v0.0.0-alpha.8"; # Try building with this empty hash first. Nix will let you # know what the correct hash to use is. sha256 = "0000000000000000000000000000000000000000000000000000"; });in{ # In your system configuration, add Nilla CLI to your system packages. environment.systemPackages = [ nilla-nixos.packages.default.result.${pkgs.system} ];}
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.
npins add --name nilla-nixos github nilla-nix nixos
With the dependency available, we can now include the module in our Nilla project.
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.
let pins = import ./npins;
nilla = import pins.nilla;innilla.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.
# Build the system.nilla nixos build example
# Or build and switch to the new configuration.nilla nixos switch example