Unverified Commit 5c3e59b6 authored by Robert Hensing's avatar Robert Hensing Committed by GitHub
Browse files

Merge pull request #230523 from hercules-ci/fast-nixos-test-eval

Fast nixos test eval
parents 4159685a 16e36473
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -57,6 +57,19 @@

      nixosModules = {
        notDetected = ./nixos/modules/installer/scan/not-detected.nix;

        /*
          Make the `nixpkgs.*` configuration read-only. Guarantees that `pkgs`
          is the way you initialize it.

          Example:

              {
                imports = [ nixpkgs.nixosModules.readOnlyPkgs ];
                nixpkgs.pkgs = nixpkgs.legacyPackages.x86_64-linux;
              }
        */
        readOnlyPkgs = ./nixos/modules/misc/nixpkgs/read-only.nix;
      };
    };
}
+8 −0
Original line number Diff line number Diff line
@@ -476,6 +476,14 @@ rec {
      check = x: isDerivation x && hasAttr "shellPath" x;
    };

    pkgs = addCheck
      (unique { message = "A Nixpkgs pkgs set can not be merged with another pkgs set."; } attrs // {
        name = "pkgs";
        descriptionClass = "noun";
        description = "Nixpkgs package set";
      })
      (x: (x._type or null) == "pkgs");

    path = mkOptionType {
      name = "path";
      descriptionClass = "noun";
+4 −0
Original line number Diff line number Diff line
@@ -99,6 +99,10 @@ merging is handled.
    problems.
    :::

`types.pkgs`

:   A type for the top level Nixpkgs package set.

### Numeric types {#sec-option-types-numeric}

`types.int`
+15 −9
Original line number Diff line number Diff line
@@ -38,6 +38,8 @@ let pkgs_ = pkgs;
in

let
  inherit (lib) optional;

  evalModulesMinimal = (import ./default.nix {
    inherit lib;
    # Implicit use of feature is noted in implementation.
@@ -47,15 +49,19 @@ let
  pkgsModule = rec {
    _file = ./eval-config.nix;
    key = _file;
    config = {
    config = lib.mkMerge (
      (optional (system != null) {
        # Explicit `nixpkgs.system` or `nixpkgs.localSystem` should override
        # this.  Since the latter defaults to the former, the former should
        # default to the argument. That way this new default could propagate all
        # they way through, but has the last priority behind everything else.
      nixpkgs.system = lib.mkIf (system != null) (lib.mkDefault system);

      _module.args.pkgs = lib.mkIf (pkgs_ != null) (lib.mkForce pkgs_);
    };
        nixpkgs.system = lib.mkDefault system;
      })
      ++
      (optional (pkgs_ != null) {
        _module.args.pkgs = lib.mkForce pkgs_;
      })
    );
  };

  withWarnings = x:
+51 −6
Original line number Diff line number Diff line
testModuleArgs@{ config, lib, hostPkgs, nodes, ... }:

let
  inherit (lib) mkOption mkForce optional types mapAttrs mkDefault mdDoc;

  system = hostPkgs.stdenv.hostPlatform.system;
  inherit (lib)
    literalExpression
    literalMD
    mapAttrs
    mdDoc
    mkDefault
    mkIf
    mkOption mkForce
    optional
    optionalAttrs
    types
    ;

  baseOS =
    import ../eval-config.nix {
      inherit system;
      system = null; # use modularly defined system
      inherit (config.node) specialArgs;
      modules = [ config.defaults ];
      baseModules = (import ../../modules/module-list.nix) ++
@@ -17,10 +26,16 @@ let
          ({ config, ... }:
            {
              virtualisation.qemu.package = testModuleArgs.config.qemu.package;

            })
          (optionalAttrs (!config.node.pkgsReadOnly) {
            key = "nodes.nix-pkgs";
            config = {
              # Ensure we do not use aliases. Ideally this is only set
              # when the test framework is used by Nixpkgs NixOS tests.
              nixpkgs.config.allowAliases = false;
              # TODO: switch to nixpkgs.hostPlatform and make sure containers-imperative test still evaluates.
              nixpkgs.system = hostPkgs.stdenv.hostPlatform.system;
            };
          })
          testModuleArgs.config.extraBaseModules
        ];
@@ -68,6 +83,30 @@ in
      default = { };
    };

    node.pkgs = mkOption {
      description = mdDoc ''
        The Nixpkgs to use for the nodes.

        Setting this will make the `nixpkgs.*` options read-only, to avoid mistakenly testing with a Nixpkgs configuration that diverges from regular use.
      '';
      type = types.nullOr types.pkgs;
      default = null;
      defaultText = literalMD ''
        `null`, so construct `pkgs` according to the `nixpkgs.*` options as usual.
      '';
    };

    node.pkgsReadOnly = mkOption {
      description = mdDoc ''
        Whether to make the `nixpkgs.*` options read-only. This is only relevant when [`node.pkgs`](#test-opt-node.pkgs) is set.

        Set this to `false` when any of the [`nodes`](#test-opt-nodes) needs to configure any of the `nixpkgs.*` options. This will slow down evaluation of your test a bit.
      '';
      type = types.bool;
      default = config.node.pkgs != null;
      defaultText = literalExpression ''node.pkgs != null'';
    };

    node.specialArgs = mkOption {
      type = types.lazyAttrsOf types.raw;
      default = { };
@@ -100,5 +139,11 @@ in
        config.nodes;

    passthru.nodes = config.nodesCompat;

    defaults = mkIf config.node.pkgsReadOnly {
      nixpkgs.pkgs = config.node.pkgs;
      imports = [ ../../modules/misc/nixpkgs/read-only.nix ];
    };

  };
}
Loading