NixBSD
3 min read
Unofficial NixOS fork using a FreeBSD kernel. Brings reproducible, declarative configuration to BSD by replacing NixOS's Linux-specific modules with FreeBSD equivalents. Configuration mirrors NixOS syntax closely.
Quick Start
Try a VM without a local checkout:
sh
nix run 'github:nixos-bsd/nixbsd#extra.vm'
# Login: root:toor or bestie:toor
Repository Structure
NixBSD spans three repositories:
| Repo | Purpose |
|---|---|
nix | Nix fork with FreeBSD build support and platform fixes |
nixpkgs | nixpkgs fork adding x86_64-freebsd platform and stdenv changes |
nixbsd | System modules (analogous to the nixos/ directory in nixpkgs) |
FreeBSD source changes are minimal — patches are applied in nixpkgs rather than maintaining a separate kernel fork.
Building a VM
sh
# Pin the closure to prevent garbage collection (recommended — full build is 30+ GiB)
nix build .#base.vmClosureInfo --out-link .gcroots/vm
# Build the VM image
nix build .#base.vm
# Run it
result/bin/run-nixbsd-base-vm
Build Outputs
| Output | Description |
|---|---|
toplevel | Full system derivation; linked at /run/current-system |
vm | Runnable UEFI VM script (CoW, writable) |
closureInfo | Closure metadata to prevent GC |
vmClosureInfo | VM-specific closure info; keep this to avoid rebuilds |
Build Tips
• First full build can take 8+ hours on fast hardware; save vmClosureInfo.
• Use --max-jobs 4 or lower if package checks fail intermittently under load.
Configuration
NixBSD configurations follow NixOS module syntax. Place your config in configuration.nix inside a flake:
nix
# flake.nix
{
inputs = {
nixbsd.url = "github:nixos-bsd/nixbsd";
};
outputs = { self, nixbsd, ... }: {
nixbsdConfigurations.myhost = nixbsd.lib.nixbsdSystem {
system = "x86_64-freebsd";
modules = [ ./configuration.nix ];
};
};
}
nix
# configuration.nix
{ config, pkgs, lib, ... }: {
# Hostname
networking.hostName = "myhost";
# System packages
environment.systemPackages = with pkgs; [
git curl vim tmux
];
# Enable SSH
services.openssh = {
enable = true;
settings.PermitRootLogin = "no";
};
# ZFS (FreeBSD has native ZFS support)
boot.supportedFilesystems = [ "zfs" ];
# Users
users.users.admin = {
isNormalUser = true;
extraGroups = [ "wheel" ];
openssh.authorizedKeys.keys = [ "ssh-ed25519 AAAA..." ];
};
system.stateVersion = "24.05";
}
Init System
NixBSD uses rc.d (FreeBSD's init system) instead of systemd. NixOS module options that map to systemd services are translated to rc.d equivalents where possible.
Define a custom rc.d service:
nix
rc.services.myapp = {
description = "My application";
command = "${pkgs.myapp}/bin/myapp";
commandArgs = "--config /etc/myapp/config.toml";
after = [ "network" ];
enable = true;
};
Key Differences from NixOS
| Aspect | NixOS (Linux) | NixBSD (FreeBSD) |
|---|---|---|
| Init system | systemd | rc.d |
| Kernel | Linux | FreeBSD |
| ZFS | via OpenZFS module | Native in-kernel |
| Jails | Not available | Native FreeBSD jails |
| Ports / pkg | Not applicable | Available alongside nix |
| GEOM | Not available | Native disk framework |
| Capsicum | Not available | Native sandboxing |
Status
NixBSD is experimental. Not all NixOS modules have BSD equivalents. Areas with good support:
• Base system, shell, CLI packages
• SSH, basic networking
• ZFS filesystem
• User management
Areas still in progress or unsupported:
• Full desktop/GUI stack
• Many systemd-dependent NixOS services
• Some nixpkgs packages that assume Linux
OpenBSD
The repository also includes preliminary support for OpenBSD configurations. See the openbsd/ modules directory in the repo.