Unverified Commit 6c656483 authored by Silvan Mosberger's avatar Silvan Mosberger Committed by GitHub
Browse files

Merge pull request #293835 from philiptaron/remove-top-level-with-lib-in-pkgs/top-level

Remove top level `with lib;` and `with import ...` in `pkgs/top-level/`
parents 1d14cc51 dbf0a30c
Loading
Loading
Loading
Loading
+19 −13
Original line number Diff line number Diff line
@@ -2,14 +2,20 @@

{ config, lib, ... }:

with lib;

let
  inherit (lib)
    literalExpression
    mapAttrsToList
    mdDoc
    mkOption
    optionals
    types
    ;

  mkMassRebuild = args: mkOption (builtins.removeAttrs args [ "feature" ] // {
    type = args.type or (types.uniq types.bool);
    default = args.default or false;
    description = lib.mdDoc ((args.description or ''
    description = mdDoc ((args.description or ''
      Whether to ${args.feature} while building nixpkgs packages.
    '') + ''
      Changing the default may cause a mass rebuild.
@@ -34,7 +40,7 @@ let
    /* Config options */

    warnUndeclaredOptions = mkOption {
      description = lib.mdDoc "Whether to warn when `config` contains an unrecognized attribute.";
      description = mdDoc "Whether to warn when `config` contains an unrecognized attribute.";
      type = types.bool;
      default = false;
    };
@@ -66,7 +72,7 @@ let
    allowAliases = mkOption {
      type = types.bool;
      default = true;
      description = lib.mdDoc ''
      description = mdDoc ''
        Whether to expose old attribute names for compatibility.

        The recommended setting is to enable this, as it
@@ -86,7 +92,7 @@ let
      default = false;
      # getEnv part is in check-meta.nix
      defaultText = literalExpression ''false || builtins.getEnv "NIXPKGS_ALLOW_UNFREE" == "1"'';
      description = lib.mdDoc ''
      description = mdDoc ''
        Whether to allow unfree packages.

        See [Installing unfree packages](https://nixos.org/manual/nixpkgs/stable/#sec-allow-unfree) in the NixOS manual.
@@ -98,7 +104,7 @@ let
      default = false;
      # getEnv part is in check-meta.nix
      defaultText = literalExpression ''false || builtins.getEnv "NIXPKGS_ALLOW_BROKEN" == "1"'';
      description = lib.mdDoc ''
      description = mdDoc ''
        Whether to allow broken packages.

        See [Installing broken packages](https://nixos.org/manual/nixpkgs/stable/#sec-allow-broken) in the NixOS manual.
@@ -110,7 +116,7 @@ let
      default = false;
      # getEnv part is in check-meta.nix
      defaultText = literalExpression ''false || builtins.getEnv "NIXPKGS_ALLOW_UNSUPPORTED_SYSTEM" == "1"'';
      description = lib.mdDoc ''
      description = mdDoc ''
        Whether to allow unsupported packages.

        See [Installing packages on unsupported systems](https://nixos.org/manual/nixpkgs/stable/#sec-allow-unsupported-system) in the NixOS manual.
@@ -132,7 +138,7 @@ let
    showDerivationWarnings = mkOption {
      type = types.listOf (types.enum [ "maintainerless" ]);
      default = [];
      description = lib.mdDoc ''
      description = mdDoc ''
        Which warnings to display for potentially dangerous
        or deprecated values passed into `stdenv.mkDerivation`.

@@ -147,7 +153,7 @@ let
    checkMeta = mkOption {
      type = types.bool;
      default = false;
      description = lib.mdDoc ''
      description = mdDoc ''
        Whether to check that the `meta` attribute of derivations are correct during evaluation time.
      '';
    };
@@ -156,7 +162,7 @@ let
in {

  freeformType =
    let t = lib.types.lazyAttrsOf lib.types.raw;
    let t = types.lazyAttrsOf types.raw;
    in t // {
      merge = loc: defs:
        let r = t.merge loc defs;
@@ -166,8 +172,8 @@ in {
  inherit options;

  config = {
    warnings = lib.optionals config.warnUndeclaredOptions (
      lib.mapAttrsToList (k: v: "undeclared Nixpkgs option set: config.${k}") config._undeclared or {}
    warnings = optionals config.warnUndeclaredOptions (
      mapAttrsToList (k: v: "undeclared Nixpkgs option set: config.${k}") config._undeclared or {}
    );
  };

+107 −102
Original line number Diff line number Diff line
{ config, lib, newScope, kodi, libretro }:

with lib;

let
  inherit (lib)
    catAttrs
    concatLists
    filter
    optionalAttrs
    unique
    ;

  inherit (libretro) fuse genesis-plus-gx mgba nestopia snes9x twenty-fortyeight;
in

let self = rec {
  callPackage = newScope self;

  # Check whether a derivation provides a Kodi addon.
  hasKodiAddon = drv: drv ? kodiAddonFor && drv.kodiAddonFor == kodi;

  # Get list of required Kodi addons given a list of derivations.
  requiredKodiAddons = drvs:
    let
      modules = filter hasKodiAddon drvs;
    in
      unique (modules ++ concatLists (catAttrs "requiredKodiAddons" modules));

  self = {
    addonDir = "/share/kodi/addons";
  rel = "Nexus";

  callPackage = newScope self;
    rel = "Nexus";

  inherit kodi;
    inherit callPackage kodi hasKodiAddon requiredKodiAddons;

    # Convert derivation to a kodi module. Stolen from ../../../top-level/python-packages.nix
    toKodiAddon = drv: drv.overrideAttrs (oldAttrs: {
@@ -24,16 +39,6 @@ let self = rec {
      };
    });

  # Check whether a derivation provides a Kodi addon.
  hasKodiAddon = drv: drv ? kodiAddonFor && drv.kodiAddonFor == kodi;

  # Get list of required Kodi addons given a list of derivations.
  requiredKodiAddons = drvs:
    let
      modules = filter hasKodiAddon drvs;
    in
      unique (modules ++ concatLists (catAttrs "requiredKodiAddons" modules));

    # package update scripts

    addonUpdateScript = callPackage ../applications/video/kodi/addons/addon-update-script { };
@@ -197,7 +202,7 @@ let self = rec {
    trakt-module = callPackage ../applications/video/kodi/addons/trakt-module { };

    trakt = callPackage ../applications/video/kodi/addons/trakt { };
}; in self // lib.optionalAttrs config.allowAliases {
}; in self // optionalAttrs config.allowAliases {
  # deprecated or renamed packages

  controllers = throw "kodi.packages.controllers has been replaced with kodi.packages.controller-topology-project - a package which contains a large number of controller profiles." { };
+9 −1
Original line number Diff line number Diff line
@@ -19,7 +19,15 @@
, octave
}:

with lib;
let
  inherit (lib)
    catAttrs
    concatLists
    filter
    makeScope
    unique
    ;
in

makeScope newScope (self:
  let
+101 −68
Original line number Diff line number Diff line
@@ -20,9 +20,40 @@
  nixpkgsArgs ? { config = { allowUnfree = false; inHydra = true; }; }
}:

with import ./release-lib.nix { inherit supportedSystems scrubJobs nixpkgsArgs; };

let
  release-lib = import ./release-lib.nix {
    inherit supportedSystems scrubJobs nixpkgsArgs;
  };

  inherit (release-lib)
    all
    assertTrue
    darwin
    forMatchingSystems
    hydraJob'
    linux
    mapTestOnCross
    pkgsForCross
    unix
    ;

  inherit (release-lib.lib)
    mapAttrs
    addMetaAttrs
    elem
    getAttrFromPath
    isDerivation
    maintainers
    mapAttrsRecursive
    mapAttrsRecursiveCond
    recursiveUpdate
    systems
    ;

  inherit (release-lib.lib.attrsets)
    removeAttrs
    ;

  nativePlatforms = all;

  embedded = {
@@ -42,14 +73,14 @@ let
    cargo = nativePlatforms;
  };

  gnuCommon = lib.recursiveUpdate common {
  gnuCommon = recursiveUpdate common {
    buildPackages.gcc = nativePlatforms;
    coreutils = nativePlatforms;
    haskell.packages.ghcHEAD.hello = nativePlatforms;
    haskellPackages.hello = nativePlatforms;
  };

  linuxCommon = lib.recursiveUpdate gnuCommon {
  linuxCommon = recursiveUpdate gnuCommon {
    buildPackages.gdb = nativePlatforms;

    bison = nativePlatforms;
@@ -60,7 +91,7 @@ let
    patch = nativePlatforms;
  };

  windowsCommon = lib.recursiveUpdate gnuCommon {
  windowsCommon = recursiveUpdate gnuCommon {
    boehmgc = nativePlatforms;
    guile_1_8 = nativePlatforms;
    libffi = nativePlatforms;
@@ -120,7 +151,7 @@ in
    # good idea lest there be some irrelevant pass-through debug attrs that
    # cause false negatives.
    testEqualOne = path: system: let
      f = path: crossSystem: system: builtins.toString (lib.getAttrFromPath path (pkgsForCross crossSystem system));
      f = path: crossSystem: system: toString (getAttrFromPath path (pkgsForCross crossSystem system));
    in assertTrue (
        f path null system
        ==
@@ -129,7 +160,7 @@ in

    testEqual = path: systems: forMatchingSystems systems (testEqualOne path);

    mapTestEqual = lib.mapAttrsRecursive testEqual;
    mapTestEqual = mapAttrsRecursive testEqual;

  in mapTestEqual {
    boehmgc = nativePlatforms;
@@ -142,105 +173,107 @@ in
    guile = nativePlatforms;
  };

  crossIphone64 = mapTestOnCross lib.systems.examples.iphone64 darwinCommon;
  crossIphone64 = mapTestOnCross systems.examples.iphone64 darwinCommon;

  crossIphone32 = mapTestOnCross lib.systems.examples.iphone32 darwinCommon;
  crossIphone32 = mapTestOnCross systems.examples.iphone32 darwinCommon;

  /* Test some cross builds to the Sheevaplug */
  crossSheevaplugLinux = mapTestOnCross lib.systems.examples.sheevaplug (linuxCommon // {
  crossSheevaplugLinux = mapTestOnCross systems.examples.sheevaplug (linuxCommon // {
    ubootSheevaplug = nativePlatforms;
  });

  /* Test some cross builds on 32 bit mingw-w64 */
  crossMingw32 = mapTestOnCross lib.systems.examples.mingw32 windowsCommon;
  crossMingw32 = mapTestOnCross systems.examples.mingw32 windowsCommon;

  /* Test some cross builds on 64 bit mingw-w64 */
  crossMingwW64 = mapTestOnCross lib.systems.examples.mingwW64 windowsCommon;
  crossMingwW64 = mapTestOnCross systems.examples.mingwW64 windowsCommon;

  /* Linux on mipsel */
  fuloongminipc = mapTestOnCross lib.systems.examples.fuloongminipc linuxCommon;
  ben-nanonote = mapTestOnCross lib.systems.examples.ben-nanonote linuxCommon;
  fuloongminipc = mapTestOnCross systems.examples.fuloongminipc linuxCommon;
  ben-nanonote = mapTestOnCross systems.examples.ben-nanonote linuxCommon;

  /* Javacript */
  ghcjs = mapTestOnCross lib.systems.examples.ghcjs {
  ghcjs = mapTestOnCross systems.examples.ghcjs {
    haskell.packages.ghcjs.hello = nativePlatforms;
    haskell.packages.native-bignum.ghcHEAD.hello = nativePlatforms;
    haskellPackages.hello = nativePlatforms;
  };

  /* Linux on Raspberrypi */
  rpi = mapTestOnCross lib.systems.examples.raspberryPi rpiCommon;
  rpi-musl = mapTestOnCross lib.systems.examples.muslpi rpiCommon;
  rpi = mapTestOnCross systems.examples.raspberryPi rpiCommon;
  rpi-musl = mapTestOnCross systems.examples.muslpi rpiCommon;

  /* Linux on the Remarkable */
  remarkable1 = mapTestOnCross lib.systems.examples.remarkable1 linuxCommon;
  remarkable2 = mapTestOnCross lib.systems.examples.remarkable2 linuxCommon;
  remarkable1 = mapTestOnCross systems.examples.remarkable1 linuxCommon;
  remarkable2 = mapTestOnCross systems.examples.remarkable2 linuxCommon;

  /* Linux on armv7l-hf */
  armv7l-hf = mapTestOnCross lib.systems.examples.armv7l-hf-multiplatform linuxCommon;
  armv7l-hf = mapTestOnCross systems.examples.armv7l-hf-multiplatform linuxCommon;

  pogoplug4 = mapTestOnCross lib.systems.examples.pogoplug4 linuxCommon;
  pogoplug4 = mapTestOnCross systems.examples.pogoplug4 linuxCommon;

  /* Linux on aarch64 */
  aarch64 = mapTestOnCross lib.systems.examples.aarch64-multiplatform linuxCommon;
  aarch64-musl = mapTestOnCross lib.systems.examples.aarch64-multiplatform-musl linuxCommon;
  aarch64 = mapTestOnCross systems.examples.aarch64-multiplatform linuxCommon;
  aarch64-musl = mapTestOnCross systems.examples.aarch64-multiplatform-musl linuxCommon;

  /* Linux on RISCV */
  riscv64 = mapTestOnCross lib.systems.examples.riscv64 linuxCommon;
  riscv32 = mapTestOnCross lib.systems.examples.riscv32 linuxCommon;
  riscv64 = mapTestOnCross systems.examples.riscv64 linuxCommon;
  riscv32 = mapTestOnCross systems.examples.riscv32 linuxCommon;

  /* Linux on LoongArch */
  loongarch64-linux = mapTestOnCross lib.systems.examples.loongarch64-linux linuxCommon;
  loongarch64-linux = mapTestOnCross systems.examples.loongarch64-linux linuxCommon;

  m68k = mapTestOnCross lib.systems.examples.m68k linuxCommon;
  s390x = mapTestOnCross lib.systems.examples.s390x linuxCommon;
  m68k = mapTestOnCross systems.examples.m68k linuxCommon;
  s390x = mapTestOnCross systems.examples.s390x linuxCommon;

  /* (Cross-compiled) Linux on x86 */
  x86_64-musl = mapTestOnCross lib.systems.examples.musl64 linuxCommon;
  x86_64-gnu = mapTestOnCross lib.systems.examples.gnu64 linuxCommon;
  i686-musl = mapTestOnCross lib.systems.examples.musl32 linuxCommon;
  i686-gnu = mapTestOnCross lib.systems.examples.gnu32 linuxCommon;

  ppc64le = mapTestOnCross lib.systems.examples.powernv linuxCommon;
  ppc64le-musl = mapTestOnCross lib.systems.examples.musl-power linuxCommon;

  android64 = mapTestOnCross lib.systems.examples.aarch64-android-prebuilt linuxCommon;
  android32 = mapTestOnCross lib.systems.examples.armv7a-android-prebuilt linuxCommon;

  wasi32 = mapTestOnCross lib.systems.examples.wasi32 wasiCommon;

  msp430 = mapTestOnCross lib.systems.examples.msp430 embedded;
  mmix = mapTestOnCross lib.systems.examples.mmix embedded;
  vc4 = mapTestOnCross lib.systems.examples.vc4 embedded;
  or1k = mapTestOnCross lib.systems.examples.or1k embedded;
  avr = mapTestOnCross lib.systems.examples.avr embedded;
  arm-embedded = mapTestOnCross lib.systems.examples.arm-embedded embedded;
  armhf-embedded = mapTestOnCross lib.systems.examples.armhf-embedded embedded;
  aarch64-embedded = mapTestOnCross lib.systems.examples.aarch64-embedded embedded;
  aarch64be-embedded = mapTestOnCross lib.systems.examples.aarch64be-embedded embedded;
  powerpc-embedded = mapTestOnCross lib.systems.examples.ppc-embedded embedded;
  powerpcle-embedded = mapTestOnCross lib.systems.examples.ppcle-embedded embedded;
  i686-embedded = mapTestOnCross lib.systems.examples.i686-embedded embedded;
  x86_64-embedded = mapTestOnCross lib.systems.examples.x86_64-embedded embedded;
  riscv64-embedded = mapTestOnCross lib.systems.examples.riscv64-embedded embedded;
  riscv32-embedded = mapTestOnCross lib.systems.examples.riscv32-embedded embedded;
  rx-embedded = mapTestOnCross lib.systems.examples.rx-embedded embedded;

  x86_64-freebsd = mapTestOnCross lib.systems.examples.x86_64-freebsd common;
  x86_64-netbsd = mapTestOnCross lib.systems.examples.x86_64-netbsd common;
  x86_64-musl = mapTestOnCross systems.examples.musl64 linuxCommon;
  x86_64-gnu = mapTestOnCross systems.examples.gnu64 linuxCommon;
  i686-musl = mapTestOnCross systems.examples.musl32 linuxCommon;
  i686-gnu = mapTestOnCross systems.examples.gnu32 linuxCommon;

  ppc64le = mapTestOnCross systems.examples.powernv linuxCommon;
  ppc64le-musl = mapTestOnCross systems.examples.musl-power linuxCommon;

  android64 = mapTestOnCross systems.examples.aarch64-android-prebuilt linuxCommon;
  android32 = mapTestOnCross systems.examples.armv7a-android-prebuilt linuxCommon;

  wasi32 = mapTestOnCross systems.examples.wasi32 wasiCommon;

  msp430 = mapTestOnCross systems.examples.msp430 embedded;
  mmix = mapTestOnCross systems.examples.mmix embedded;
  vc4 = mapTestOnCross systems.examples.vc4 embedded;
  or1k = mapTestOnCross systems.examples.or1k embedded;
  avr = mapTestOnCross systems.examples.avr embedded;
  arm-embedded = mapTestOnCross systems.examples.arm-embedded embedded;
  armhf-embedded = mapTestOnCross systems.examples.armhf-embedded embedded;
  aarch64-embedded = mapTestOnCross systems.examples.aarch64-embedded embedded;
  aarch64be-embedded = mapTestOnCross systems.examples.aarch64be-embedded embedded;
  powerpc-embedded = mapTestOnCross systems.examples.ppc-embedded embedded;
  powerpcle-embedded = mapTestOnCross systems.examples.ppcle-embedded embedded;
  i686-embedded = mapTestOnCross systems.examples.i686-embedded embedded;
  x86_64-embedded = mapTestOnCross systems.examples.x86_64-embedded embedded;
  riscv64-embedded = mapTestOnCross systems.examples.riscv64-embedded embedded;
  riscv32-embedded = mapTestOnCross systems.examples.riscv32-embedded embedded;
  rx-embedded = mapTestOnCross systems.examples.rx-embedded embedded;

  x86_64-freebsd = mapTestOnCross systems.examples.x86_64-freebsd common;
  x86_64-netbsd = mapTestOnCross systems.examples.x86_64-netbsd common;

  # we test `embedded` instead of `linuxCommon` because very few packages
  # successfully cross-compile to Redox so far
  x86_64-redox = mapTestOnCross lib.systems.examples.x86_64-unknown-redox embedded;
  x86_64-redox = mapTestOnCross systems.examples.x86_64-unknown-redox embedded;

  /* Cross-built bootstrap tools for every supported platform */
  bootstrapTools = let
    tools = import ../stdenv/linux/make-bootstrap-tools-cross.nix { system = "x86_64-linux"; };
    maintainers = [ lib.maintainers.dezgeg ];
    meta = {
      maintainers = [ maintainers.dezgeg ];
    };
    mkBootstrapToolsJob = drv:
      assert lib.elem drv.system supportedSystems;
      hydraJob' (lib.addMetaAttrs { inherit maintainers; } drv);
  in lib.mapAttrsRecursiveCond (as: !lib.isDerivation as) (name: mkBootstrapToolsJob)
      assert elem drv.system supportedSystems;
      hydraJob' (addMetaAttrs meta drv);
  in mapAttrsRecursiveCond (as: !isDerivation as) (name: mkBootstrapToolsJob)
    # The `bootstrapTools.${platform}.bootstrapTools` derivation
    # *unpacks* the bootstrap-files using their own `busybox` binary,
    # so it will fail unless buildPlatform.canExecute hostPlatform.
@@ -248,9 +281,9 @@ in
    # attribute, so there is no way to detect this -- we must add it
    # as a special case.  We filter the "test" attribute (only from
     # *cross*-built bootstrapTools) for the same reason.
    (builtins.mapAttrs (_: v: builtins.removeAttrs v ["bootstrapTools" "test"]) tools);
    (mapAttrs (_: v: removeAttrs v ["bootstrapTools" "test"]) tools);

  # Cross-built nixStatic for platforms for enabled-but-unsupported platforms
  mips64el-nixCrossStatic = mapTestOnCross lib.systems.examples.mips64el-linux-gnuabi64 nixCrossStatic;
  powerpc64le-nixCrossStatic = mapTestOnCross lib.systems.examples.powernv nixCrossStatic;
  mips64el-nixCrossStatic = mapTestOnCross systems.examples.mips64el-linux-gnuabi64 nixCrossStatic;
  powerpc64le-nixCrossStatic = mapTestOnCross systems.examples.powernv nixCrossStatic;
}
+8 −3
Original line number Diff line number Diff line
@@ -18,10 +18,15 @@
  nixpkgsArgs ? { config = { allowUnfree = true; inHydra = true; }; }
}:

with import ./release-lib.nix {inherit supportedSystems nixpkgsArgs; };
with lib;

let
  release-lib = import ./release-lib.nix {
    inherit supportedSystems nixpkgsArgs;
  };

  inherit (release-lib) linux mapTestOn packagePlatforms pkgs;

  inherit (release-lib.lib) genAttrs;

  # Package sets to evaluate
  packageSets = [
    "cudaPackages_10_0"
Loading