Commit Graph

25 Commits

Author SHA1 Message Date
figsoda
08e0e1b667 nixos/nspawn-container: remove outdated comment and flush 2026-07-29 19:23:25 -04:00
figsoda
503d46170d nixos/nspawn-container: fix build 2026-07-25 15:41:51 -04:00
zowoq
814dbea27f nixos/nspawn-container: hash name, remove assertion
the code comment is copied from the commit that added the assertion

af0238c70e
2026-07-07 10:59:58 +10:00
Arian van Putten
b4a5a3d28f nixos/virtualisation/nspawn-container: add virtualisation.credentials support
Assisted-by: Claude <noreply@anthropic.com>
2026-06-25 13:44:20 +02:00
Arian van Putten
b9ce8900b0 nixos/getty: do not conditionalize on console. (#480686) 2026-06-22 11:31:00 +00:00
zowoq
f5c8639dd5 nixos/nspawn-container: use ty instead of mypy
the test driver package is also using ty
85d58871ae
2026-05-29 12:25:45 +10:00
zowoq
5eba89ff43 nixos/nspawn-container: add "usr/bin"
same change was done for nixos/nixos-containers in b9f2fa1c7d
2026-05-22 11:27:39 +10:00
nixpkgs-ci[bot]
d7f7172553 Merge master into staging-nixos 2026-05-14 18:39:31 +00:00
Jared Baur
68e2e2bde3 nixos/test-driver: fix eval with noUserModules
When "non-user" modules are not placed in baseModules or
extraModules (arguments of eval-config.nix), noUserModules.evalModules
breaks if the options defined in those modules are consumed. In order
to restore noUserModules functionality for NixOS VM (and now nspawn)
tests, the modules implementing test behavior are moved to baseModules.
2026-05-09 18:31:52 -07:00
Jacek Galowicz
948c5d0da2 nixos-test-driver: fix vlan/bridge cleanup 2026-05-03 17:45:52 +02:00
Arian van Putten
2b1adfc10d nixos/nspawn-container: don't enable console
Serial terminals should work regardless of vconsole settings now
2026-04-04 10:28:24 +02:00
Kierán Meinhardt
d1386a426b nixos/virtualisation: provide actionable advice on VLAN TAP failure 2026-03-04 08:40:12 +01:00
Kierán Meinhardt
c4c96a76e9 nixos/test-driver: wait for READY message from nspawn container 2026-03-03 16:32:01 +01:00
Kierán Meinhardt
3acd5cae61 nixos/virtualisation: disallow specialisation in nspawn-container 2026-03-03 16:32:01 +01:00
Kierán Meinhardt
af0238c70e nixos/virtualisation: assert nspawn container name length
If the names for systemd-nspawn containers are too long,
the generated bridge interface names will surpass the
kernel limit IFNAMSIZ (15 characters + '\0').
2026-03-03 16:32:01 +01:00
Kierán Meinhardt
0702405810 nixos/test-driver: implement container↔VM networking 2026-01-28 11:28:33 +01:00
Kierán Meinhardt
a88839a901 nixos/nspawn-container: add support for shared directory
Co-authored-by: Jeremy Fleischman <jeremyfleischman@gmail.com>
2026-01-27 16:58:48 +01:00
Kierán Meinhardt
be846f5e47 nixos/nspawn-container: assign getty TODO to @arianvp
Co-Authored-By: Arian van Putten <arian.vanputten@gmail.com>
2026-01-19 10:36:38 +01:00
Kierán Meinhardt
f4baee30bb nixos/virtualisation: factor out common networking options between qemu-vm and nspawn-container 2026-01-19 10:36:38 +01:00
Kierán Meinhardt
1e3c78f75d nixos/nspawn-container: run-nspawn as cli application 2026-01-19 10:36:38 +01:00
Kierán Meinhardt
7ba279d21e nixos/nspawn-container: rename initArgs to cmdline 2026-01-19 10:36:38 +01:00
Kierán Meinhardt
835e38cf1a nixos/nspawn-container: clarify format of virtualisation.systemd-nspawn option tree 2026-01-19 10:36:37 +01:00
Kierán Meinhardt
46303ebf09 nixos/nspawn-container: fix typo in virtualisation.allInterfaces 2026-01-19 10:36:37 +01:00
Kierán Meinhardt
40f2d0b242 nixos/nspawn-container: fix typo in comment 2026-01-19 10:36:37 +01:00
Jeremy Fleischman
4bd5482aa6 nixos/nspawn-container: init a new nspawn-container profile
This shares a lot in common with the
<nixos/modules/virtualisation/nixos-containers.nix> infrastructure, but
is designed to behave like our `qemu-vm.nix` profile (provides a lot of
the same `virtualisation.*` options, produces a simple script you can
run).

This lays the groundwork to be able to rework the nixos test
infrastructure to allow for containers as well as qemu nodes. That work
isn't quite done yet, but if you want more context, you can see the
followup work in <https://github.com/applicative-systems/nixpkgs/compare/nspawn-container-profile...applicative-systems:nixpkgs:nixos-test-containers>.

Credit due to the [Clan.lol](https://clan.lol/) team for first
implementing this. I'm just cleaning it up and making it play nicely
with upstream.

To try it out, create a `demo.nix`:

```nix
let
  pkgs = import ./. { };
  mkContainer =
    {
      nodeNumber,
      vlans,
    }:
    pkgs.nixos (
      {
        config,
        modulesPath,
        pkgs,
        lib,
        ...
      }:
      let
        interfaces = lib.attrValues config.virtualisation.allInterfaces;

        # Automatically assign IP addresses to requested interfaces.
        assignIPs = lib.filter (i: i.assignIP) interfaces;
        ipInterfaces = lib.forEach assignIPs (
          i:
          lib.nameValuePair i.name {
            ipv4.addresses = [
              {
                address = "192.168.${toString i.vlan}.${toString nodeNumber}";
                prefixLength = 24;
              }
            ];
          }
        );
      in
      {
        imports = [ "${modulesPath}/virtualisation/nspawn-container" ];
        users.users.root.password = "";

        networking.hostName = "c${toString nodeNumber}";
        virtualisation.vlans = vlans;
        networking.interfaces = lib.listToAttrs ipInterfaces;

        environment.systemPackages = [ pkgs.neovim ];
        system.stateVersion = lib.trivial.release;
      }
    );
in
{
  container1 = mkContainer {
    nodeNumber = 1;
    vlans = [ 1 ];
  };
  container2 = mkContainer {
    nodeNumber = 2;
    vlans = [ 2 ];
  };
  container12 = mkContainer {
    nodeNumber = 12;
    vlans = [
      1
      2
    ];
  };
}
```

Build and run the machines in separate terminals (unfortunately,
`systemd-nspawn` requires `sudo`):

```console
$ sudo $(nix-build ./demo.nix -A container1.config.system.build.nspawn)/bin/run-c1-nspawn
$ sudo $(nix-build ./demo.nix -A container2.config.system.build.nspawn)/bin/run-c2-nspawn
$ sudo $(nix-build ./demo.nix -A container12.config.system.build.nspawn)/bin/run-c12-nspawn
```

You can log into this machines as `root`, and verify they can ping each
other:

`c1` can ping `c12`:

```
[root@c1:~]# ping 192.168.1.12 -c 1
PING 192.168.1.12 (192.168.1.12) 56(84) bytes of data.
64 bytes from 192.168.1.12: icmp_seq=1 ttl=64 time=0.164 ms
...
```

So can `c2`:

```
[root@c2:~]# ping 192.168.2.12
PING 192.168.2.12 (192.168.2.12) 56(84) bytes of data.
64 bytes from 192.168.2.12: icmp_seq=1 ttl=64 time=0.127 ms
```
2026-01-19 10:36:37 +01:00