Skip to content

WSL and system-manager

A fleet can mix machines that run NixOS, machines that run NixOS inside WSL on Windows, and machines of another Linux distribution that system-manager configures. Each is a kind with its own sink, and each sink builds its own flake output. An aspect at several kinds shares one piece of configuration between them.

The kinds, their sinks and the batteries that build them:

modules/fleet.nix
# Three kinds of machine: a NixOS host, a NixOS host that runs in WSL, and a machine of another Linux distribution
# that system-manager configures. Each kind has its own sink and builds its own flake output.
{
yen,
lib,
inputs,
...
}:
let
inherit (yen.lib.batteries) configurations nixos;
in
{
yen.kinds.fleet = {
spawns = {
host = _: yen.host;
wsl = _: yen.wsl;
machine = _: yen.machine;
};
sinks.out.reduce = yen.lib.reduce.merge;
};
yen.fleet.main = { };
yen.kinds.host.sinks.nixos.out = nixos.system {
# (1)
from = yen.kinds.host.sinks.nixos;
inherit (inputs) nixpkgs;
};
# WSL is NixOS with the NixOS-WSL module: the same battery, one more module
yen.kinds.wsl.sinks.nixos.out = nixos.system {
# (2)
from = yen.kinds.wsl.sinks.nixos;
inherit (inputs) nixpkgs;
};
yen.aspects.wsl = {
at = yen.kinds.wsl;
nixos = {
imports = [ inputs.nixos-wsl.nixosModules.default ]; # (3)
wsl.enable = true;
};
};
# system-manager: `systemConfigs.<name>` from the modules of the machine's sink
yen.kinds.machine.sinks.system.out = configurations {
# (4)
from = yen.kinds.machine.sinks.system;
output = "systemConfigs";
build = _: modules: inputs.system-manager.lib.makeSystemConfig { inherit modules; };
};
yen.flake = { out, ... }: out;
}
  • (1) builds nixosConfigurations.<name> for a NixOS host.
  • (2) is the same battery for a machine on WSL. WSL needs no battery of its own: it is NixOS with one more module.
  • (3) is that module, NixOS-WSL. The aspect wsl adds it, and wsl.enable, at the kind wsl.
  • (4) builds systemConfigs.<name> for another Linux, with system-manager.lib.makeSystemConfig.

The machines, and the aspect tools, which gives the same packages to all three through the key of each kind:

modules/machines.nix
# The machines, and one aspect that every one of them gets: it gives the same packages to NixOS, WSL and
# system-manager, each through the key of its own kind.
{ yen, ... }:
let
tools = pkgs: [
pkgs.git
pkgs.htop
];
in
{
yen.host.desk = { };
yen.wsl.laptop = { };
yen.machine.vps = { };
yen.aspects.base = {
at = [
yen.kinds.host
yen.kinds.wsl
];
nixos =
{ scope, ... }:
{
networking.hostName = scope.name;
nixpkgs.hostPlatform = "x86_64-linux";
system.stateVersion = "25.05";
fileSystems."/".device = "/dev/disk/by-label/nixos";
boot.loader.grub.devices = [ "nodev" ];
};
};
yen.aspects.tools = {
at = [
yen.kinds.host
yen.kinds.wsl
yen.kinds.machine
];
nixos = # (1)
{ pkgs, ... }:
{
environment.systemPackages = tools pkgs;
};
system = # (2)
{ pkgs, ... }:
{
nixpkgs.hostPlatform = "x86_64-linux";
environment.systemPackages = tools pkgs;
};
};
}

At (1), the packages go to NixOS and WSL through the nixos key. At (2), they go to the other Linux through the system key. The flake outputs, with the Lean check every flake gets:

result
{
checks = [
"aarch64-darwin"
"aarch64-linux"
"x86_64-linux"
];
nixosConfigurations = [
"desk"
"laptop"
];
systemConfigs = [
"vps"
];
}
Machine Kind Sink Battery Output
NixOS host nixos nixos.system nixosConfigurations.<name>
NixOS on WSL wsl nixos nixos.system, plus the NixOS-WSL module nixosConfigurations.<name>
Other Linux machine system configurations with system-manager.lib.makeSystemConfig systemConfigs.<name>

nix-darwin works the same way: a kind with a darwin sink and the battery darwin.system (see Platform batteries). An aspect at host, wsl, machine and the darwin kind shares its configuration with all four.

ContributeCommunitySponsor