erikarvstedt / extra-container

Run declarative NixOS containers without full system rebuilds
MIT License
218 stars 16 forks source link

missing system.stateVersion config #28

Closed SCOTT-HAMILTON closed 2 years ago

SCOTT-HAMILTON commented 2 years ago

When running the demo command from the README with extra-container 0.9 installed with https://github.com/erikarvstedt/extra-container#nixos-stable-without-flake-support

$ sudo extra-container create --start <<'EOF'
{
  containers.demo = {
    privateNetwork = true;
    hostAddress = "10.250.0.1";
    localAddress = "10.250.0.2";

    config = { pkgs, ... }: {
      systemd.services.hello = {
        wantedBy = [ "multi-user.target" ];
        script = ''
          while true; do
            echo hello | ${pkgs.netcat}/bin/nc -lN 50
          done
        '';
      };
      networking.firewall.allowedTCPPorts = [ 50 ];
    };
  };
}
EOF

I get this error:

Building containers...
error: attribute 'stateVersion' missing

       at /nix/var/nix/profiles/per-user/root/channels/nixos/nixos/modules/virtualisation/nixos-containers.nix:7:56:

            6|
            7|   configurationPrefix = optionalString (versionAtLeast config.system.stateVersion "22.05") "nixos-";
             |                                                        ^
            8|   configurationDirectoryName = "${configurationPrefix}containers";
(use '--show-trace' to show detailed location information)
$ nix-info -m --sandbox --host-os
bjornfor commented 2 years ago

I thought it was just a matter of adding system.stateVersion = "22.05" to the nixos container config, but apparently it's something else:

$ sudo extra-container create --start <<'EOF'
{
  containers.demo = {
    privateNetwork = true;
    hostAddress = "10.250.0.1";
    localAddress = "10.250.0.2";

    config = { pkgs, ... }: {
      systemd.services.hello = {
        wantedBy = [ "multi-user.target" ];
        script = ''
          while true; do
            echo hello | ${pkgs.netcat}/bin/nc -lN 50
          done
        '';
      };
      networking.firewall.allowedTCPPorts = [ 50 ];
      system.stateVersion = "22.05";    # ADDED THIS LINE
    };
  };
}
EOF
Building containers...
error: attribute 'stateVersion' missing

       at /etc/current-nixpkgs/nixos/modules/virtualisation/nixos-containers.nix:7:56:

            6|
            7|   configurationPrefix = optionalString (versionAtLeast config.system.stateVersion "22.05") "nixos-";
             |                                                        ^
            8|   configurationDirectoryName = "${configurationPrefix}containers";
(use '--show-trace' to show detailed location information)
bjornfor commented 2 years ago

Looks like something broke between nixos-21.11 and nixos-22.05. Bisecting...

erikarvstedt commented 2 years ago

This is a known bug, I'll fix this soon!

bjornfor commented 2 years ago

This is a known bug, I'll fix this soon!

Thanks!

(For some reason I got false results from git bisect, but manually bisected to https://github.com/nixos/nixpkgs/commit/f535d6f45ef9556d392de76c2dd1c26b436c4ea8.)

erikarvstedt commented 2 years ago

Fixed in https://github.com/erikarvstedt/extra-container/commit/738e506894d64303ec354089044716cbe0a9bf97.

bjornfor commented 2 years ago

Thanks!