Unverified Commit 68ec46f4 authored by Wolfgang Walther's avatar Wolfgang Walther Committed by GitHub
Browse files

recurseIntoAttrsWith: init (#482817)

parents 3bf6cbe6 9f1ea860
Loading
Loading
Loading
Loading
+72 −10
Original line number Diff line number Diff line
@@ -108,13 +108,62 @@ with pkgs;
  gccStdenvNoLibs = mkStdenvNoLibs gccStdenv;
  clangStdenvNoLibs = mkStdenvNoLibs clangStdenv;

  /**
    Recurse into an attribute set depending on which `config.recursionMode` is set.

    This function only affects a single attribute set;
    it does not apply itself recursively for nested attribute sets.

    # Inputs
    `modes`
    : An attribute set containg keys from `config.recursionMode` defaulting to true.
    `attrs`
    : An attribute set to scan for derivations.

    # Type
    ```
    recurseIntoAttrsWith :: AttrSet -> AttrSet -> AttrSet
    ```

    # Examples
    :::{.example}
    ## `pkgs.recurseIntoAttrsWith` usage example
    ```nix
    { pkgs ? import <nixpkgs> {} }:
    {
      myTools = pkgs.recurseIntoAttrsWith { } {
        inherit (pkgs) hello figlet;
      };
    }
    ```
    :::
  */
  recurseIntoAttrsWith =
    {
      hydra ? true,
      eval ? true,
      search ? true,
    }:
    attrs:
    attrs
    // {
      recurseForDerivations =
        let
          modes = {
            inherit hydra eval search;
          };
        in
        modes.${config.recursionMode};
    };

  ### Evaluating the entire Nixpkgs naively will likely fail, make failure fast
  AAAAAASomeThingsFailToEvaluate = throw ''
    This pseudo-package is likely not the only part of Nixpkgs that fails to evaluate.
    You should not evaluate entire Nixpkgs without measures to handle failing packages.
  '';

  tests = recurseIntoAttrs (callPackages ../test { });
  # Tests should not appear in search results
  tests = recurseIntoAttrsWith { search = false; } (callPackages ../test { });

  defaultPkgConfigPackages =
    # We don't want nix-env -q to enter this, because all of these are aliases.
@@ -7975,7 +8024,13 @@ with pkgs;

  rstudioServerWrapper = rstudioWrapper.override { rstudio = rstudio-server; };

  rPackages = dontRecurseIntoAttrs (
  rPackages =
    recurseIntoAttrsWith
      {
        hydra = false;
        eval = false;
      }
      (
        callPackage ../development/r-modules {
          overrides = (config.rPackageOverrides or (_: { })) pkgs;
        }
@@ -8701,7 +8756,12 @@ with pkgs;
  };

  mdadm = mdadm4;
  minimal-bootstrap = recurseIntoAttrs (

  # minimal-bootstrap packages aren't used for anything but bootstrapping our
  # stdenv. They should not be used for any other purpose and therefore not
  # show up in search results or repository tracking services that consume our
  # packages.json https://github.com/NixOS/nixpkgs/issues/244966
  minimal-bootstrap = recurseIntoAttrsWith { search = false; } (
    import ../os-specific/linux/minimal-bootstrap {
      inherit (stdenv) buildPlatform hostPlatform;
      inherit lib config;
@@ -9397,9 +9457,11 @@ with pkgs;
      pkgs' = pkgs; # default pkgs used for bootstrapping the emacs package set
    };

  # emacsPackages is exposed on search.nixos.org.
  # Also see pkgs/top-level/packages-config.nix
  emacsPackages = dontRecurseIntoAttrs emacs.pkgs;
  # We want emacsPackages to be visible in search but not be build on hydra
  emacsPackages = recurseIntoAttrsWith {
    hydra = false;
    eval = false;
  } emacs.pkgs;

  espeak-classic = callPackage ../applications/audio/espeak { };

+15 −0
Original line number Diff line number Diff line
@@ -393,6 +393,21 @@ let
      '';
    };

    recursionMode = mkOption {
      type = types.uniq (
        types.enum [
          "hydra"
          "eval"
          "search"
        ]
      );
      default = "eval";
      description = ''
        In which way to recurse through Nixpkgs. In most cases you want keep this as the default.
        You can use this to emulate how `hydra` and `search` are going through Nixpkgs.
      '';
    };

    hashedMirrors = mkOption {
      type = types.listOf types.str;
      default = [ "https://tarballs.nixos.org" ];
+1 −25
Original line number Diff line number Diff line
@@ -3,29 +3,5 @@
  # Ensures no aliases are in the results.
  allowAliases = false;
  allowVariants = false;

  # Enable recursion into attribute sets that nix-env normally doesn't look into
  # so that we can get a more complete picture of the available packages for the
  # purposes of the index.
  packageOverrides =
    super:
    with super;
    lib.mapAttrs (_: set: lib.recurseIntoAttrs set) {
      inherit (super)
        rPackages
        ;

      # emacsPackages is an alias for emacs.pkgs
      # Re-introduce emacsPackages here so that emacs.pkgs can be searched.
      emacsPackages = emacs.pkgs;

      # minimal-bootstrap packages aren't used for anything but bootstrapping our
      # stdenv. They should not be used for any other purpose and therefore not
      # show up in search results or repository tracking services that consume our
      # packages.json https://github.com/NixOS/nixpkgs/issues/244966
      minimal-bootstrap = { };

      # This makes it so that tests are not appering on search.nixos.org
      tests = { };
    };
  recursionMode = "search";
}
+1 −0
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@
      allowAliases = false;
      allowUnfree = false;
      inHydra = true;
      recursionMode = "hydra";
      # Exceptional unsafe packages that we still build and distribute,
      # so users choosing to allow don't have to rebuild them every time.
      permittedInsecurePackages = [