Commit b5b04bb1 authored by Gwendolyn Kornak's avatar Gwendolyn Kornak Committed by Jade Lovelace
Browse files

nixos/nixos-containers: add flake to container start script

Integrated the flake container setup into the spawn script for systemd-nspawn.
The trickiest part of this was ensuring the underlying per-container is built.
With the .conf file created, running `nixos-container update` creates all the necessary per-container structure.
We call this command at start to ensure the structure is created only if the per-container system isnt there.
Note: This also means the flake gets updated to branch HEAD when the container is started for the first time.
parent 9a3173da
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -113,6 +113,11 @@ let

    cp --remove-destination /etc/resolv.conf "$root/etc/resolv.conf"

    if [ -n "$FLAKE" ] && [ ! -e "/nix/var/nix/profiles/per-container/$INSTANCE/system" ]; then
      # we create the etc/nixos-container config file, then if we utilize the update function, we can then build all the necessary system files for the container
      ${lib.getExe nixos-container} update "$INSTANCE"
    fi

    declare -a extraFlags

    if [ "$PRIVATE_NETWORK" = 1 ]; then
@@ -944,7 +949,10 @@ in

          unitConfig.RequiresMountsFor = "${stateDirectory}/%i";

          path = [ pkgs.iproute2 ];
          path = [
            pkgs.iproute2
            config.nix.package
          ];

          environment = {
            root = "${stateDirectory}/%i";