Unverified Commit f43a0881 authored by jade's avatar jade Committed by GitHub
Browse files

nixos-containers: Added flake option (#413463)

parents 2defa371 b5b04bb1
Loading
Loading
Loading
Loading
+33 −5
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
@@ -844,6 +849,16 @@ in
                '';
              };

              flake = lib.mkOption {
                type = lib.types.nullOr lib.types.str;
                default = null;
                example = "github:NixOS/nixpkgs/master";
                description = ''
                  The Flake URI of the NixOS configuration to use for the container.
                  Replaces the option {option}`containers.<name>.path`.
                '';
              };

              # Removed option. See `checkAssertion` below for the accompanying error message.
              pkgs = mkOption { visible = false; };
            } // networkOptions;
@@ -867,13 +882,18 @@ in
                      - containers.${name}.config.nixpkgs.pkgs
                        This only sets the `pkgs` argument used inside the container modules.
                    ''
                  else if options.config.isDefined && (options.flake.value != null) then
                    throw ''
                      The options 'containers.${name}.path' and 'containers.${name}.flake' cannot both be set.
                    ''
                  else
                    null;
              in
              {
                path =
                  builtins.seq checkAssertion mkIf options.config.isDefined
                    config.config.system.build.toplevel;
                path = builtins.seq checkAssertion mkMerge [
                  (mkIf options.config.isDefined config.config.system.build.toplevel)
                  (mkIf (config.flake != null) "/nix/var/nix/profiles/per-container/${name}")
                ];
              };
          }
        )
@@ -929,7 +949,10 @@ in

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

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

          environment = {
            root = "${stateDirectory}/%i";
@@ -1044,7 +1067,12 @@ in
            name: cfg:
            nameValuePair "${configurationDirectoryName}/${name}.conf" {
              text = ''
                ${optionalString (cfg.flake == null) ''
                  SYSTEM_PATH=${cfg.path}
                ''}
                ${optionalString (cfg.flake != null) ''
                  FLAKE=${cfg.flake}
                ''}
                ${optionalString cfg.privateNetwork ''
                  PRIVATE_NETWORK=1
                  ${optionalString (cfg.hostBridge != null) ''