Unverified Commit 6bb59d8a authored by Jörg Thalheim's avatar Jörg Thalheim Committed by GitHub
Browse files

treewide/nixos: remove `with lib;` part 4 (#335631)

parents be7d7efc b4b8ef5b
Loading
Loading
Loading
Loading
+2 −6
Original line number Diff line number Diff line
# This module contains the basic configuration for building a NixOS
# installation CD.

{ config, lib, options, pkgs, ... }:

with lib;

{
  imports =
    [ ./iso-image.nix
@@ -32,8 +28,8 @@ with lib;

  # An installation media cannot tolerate a host config defined file
  # system layout on a fresh machine, before it has been formatted.
  swapDevices = mkImageMediaOverride [ ];
  fileSystems = mkImageMediaOverride config.lib.isoFileSystems;
  swapDevices = lib.mkImageMediaOverride [ ];
  fileSystems = lib.mkImageMediaOverride config.lib.isoFileSystems;

  boot.postBootCommands = ''
    for o in $(</proc/cmdline); do
+1 −5
Original line number Diff line number Diff line
# This module contains the basic configuration for building a graphical NixOS
# installation CD.

{ lib, pkgs, ... }:

with lib;

{
  imports = [ ./installation-cd-base.nix ];

@@ -26,7 +22,7 @@ with lib;

  # Provide networkmanager for easy wireless configuration.
  networking.networkmanager.enable = true;
  networking.wireless.enable = mkImageMediaOverride false;
  networking.wireless.enable = lib.mkImageMediaOverride false;

  # KDE complains if power management is disabled (to be precise, if
  # there is no power management backend such as upower).
+1 −4
Original line number Diff line number Diff line
# List all devices which are detected by nixos-generate-config.
# Common devices are enabled by default.
{ lib, ... }:

with lib;

{
  config = mkDefault {
  config = lib.mkDefault {
    # Common firmware, i.e. for wifi cards
    hardware.enableRedistributableFirmware = true;
  };
+12 −15
Original line number Diff line number Diff line
{ config, options, lib, pkgs, ... }:

with lib;

let
  cfg = config.nixpkgs.flake;
in
{
  options.nixpkgs.flake = {
    source = mkOption {
    source = lib.mkOption {
      # In newer Nix versions, particularly with lazy trees, outPath of
      # flakes becomes a Nix-language path object. We deliberately allow this
      # to gracefully come through the interface in discussion with @roberth.
      #
      # See: https://github.com/NixOS/nixpkgs/pull/278522#discussion_r1460292639
      type = types.nullOr (types.either types.str types.path);
      type = lib.types.nullOr (lib.types.either lib.types.str lib.types.path);

      default = null;
      defaultText = "if (using nixpkgsFlake.lib.nixosSystem) then self.outPath else null";
@@ -34,8 +31,8 @@ in
      '';
    };

    setNixPath = mkOption {
      type = types.bool;
    setNixPath = lib.mkOption {
      type = lib.types.bool;

      default = cfg.source != null;
      defaultText = "config.nixpkgs.flake.source != null";
@@ -54,8 +51,8 @@ in
      '';
    };

    setFlakeRegistry = mkOption {
      type = types.bool;
    setFlakeRegistry = lib.mkOption {
      type = lib.types.bool;

      default = cfg.source != null;
      defaultText = "config.nixpkgs.flake.source != null";
@@ -75,7 +72,7 @@ in
    };
  };

  config = mkIf (cfg.source != null) (mkMerge [
  config = lib.mkIf (cfg.source != null) (lib.mkMerge [
    {
      assertions = [
        {
@@ -87,19 +84,19 @@ in
        }
      ];
    }
    (mkIf cfg.setFlakeRegistry {
      nix.registry.nixpkgs.to = mkDefault {
    (lib.mkIf cfg.setFlakeRegistry {
      nix.registry.nixpkgs.to = lib.mkDefault {
        type = "path";
        path = cfg.source;
      };
    })
    (mkIf cfg.setNixPath {
    (lib.mkIf cfg.setNixPath {
      # N.B. This does not include nixos-config in NIX_PATH unlike modules/config/nix-channel.nix
      # because we would need some kind of evil shim taking the *calling* flake's self path,
      # perhaps, to ever make that work (in order to know where the Nix expr for the system came
      # from and how to call it).
      nix.nixPath = mkDefault ([ "nixpkgs=flake:nixpkgs" ]
        ++ optional config.nix.channel.enable "/nix/var/nix/profiles/per-user/root/channels");
      nix.nixPath = lib.mkDefault ([ "nixpkgs=flake:nixpkgs" ]
        ++ lib.optional config.nix.channel.enable "/nix/var/nix/profiles/per-user/root/channels");
    })
  ]);
}
+39 −42
Original line number Diff line number Diff line
{ config, options, lib, pkgs, ... }:

with lib;

let
  cfg = config.nixpkgs;
  opt = options.nixpkgs;
@@ -19,19 +16,19 @@ let
      lhs = optCall lhs_ { inherit pkgs; };
      rhs = optCall rhs_ { inherit pkgs; };
    in
    recursiveUpdate lhs rhs //
    optionalAttrs (lhs ? packageOverrides) {
    lib.recursiveUpdate lhs rhs //
    lib.optionalAttrs (lhs ? packageOverrides) {
      packageOverrides = pkgs:
        optCall lhs.packageOverrides pkgs //
        optCall (attrByPath [ "packageOverrides" ] { } rhs) pkgs;
        optCall (lib.attrByPath [ "packageOverrides" ] { } rhs) pkgs;
    } //
    optionalAttrs (lhs ? perlPackageOverrides) {
    lib.optionalAttrs (lhs ? perlPackageOverrides) {
      perlPackageOverrides = pkgs:
        optCall lhs.perlPackageOverrides pkgs //
        optCall (attrByPath [ "perlPackageOverrides" ] { } rhs) pkgs;
        optCall (lib.attrByPath [ "perlPackageOverrides" ] { } rhs) pkgs;
    };

  configType = mkOptionType {
  configType = lib.mkOptionType {
    name = "nixpkgs-config";
    description = "nixpkgs config";
    check = x:
@@ -39,34 +36,34 @@ let
            if c x then true
            else lib.traceSeqN 1 x false;
      in traceXIfNot isConfig;
    merge = args: foldr (def: mergeConfig def.value) {};
    merge = args: lib.foldr (def: mergeConfig def.value) {};
  };

  overlayType = mkOptionType {
  overlayType = lib.mkOptionType {
    name = "nixpkgs-overlay";
    description = "nixpkgs overlay";
    check = lib.isFunction;
    merge = lib.mergeOneOption;
  };

  pkgsType = types.pkgs // {
  pkgsType = lib.types.pkgs // {
    # This type is only used by itself, so let's elaborate the description a bit
    # for the purpose of documentation.
    description = "An evaluation of Nixpkgs; the top level attribute set of packages";
  };

  hasBuildPlatform = opt.buildPlatform.highestPrio < (mkOptionDefault {}).priority;
  hasBuildPlatform = opt.buildPlatform.highestPrio < (lib.mkOptionDefault {}).priority;
  hasHostPlatform = opt.hostPlatform.isDefined;
  hasPlatform = hasHostPlatform || hasBuildPlatform;

  # Context for messages
  hostPlatformLine = optionalString hasHostPlatform "${showOptionWithDefLocs opt.hostPlatform}";
  buildPlatformLine = optionalString hasBuildPlatform "${showOptionWithDefLocs opt.buildPlatform}";
  hostPlatformLine = lib.optionalString hasHostPlatform "${lib.showOptionWithDefLocs opt.hostPlatform}";
  buildPlatformLine = lib.optionalString hasBuildPlatform "${lib.showOptionWithDefLocs opt.buildPlatform}";

  legacyOptionsDefined =
    optional (opt.localSystem.highestPrio < (mkDefault {}).priority) opt.system
    ++ optional (opt.localSystem.highestPrio < (mkOptionDefault {}).priority) opt.localSystem
    ++ optional (opt.crossSystem.highestPrio < (mkOptionDefault {}).priority) opt.crossSystem
    lib.optional (opt.localSystem.highestPrio < (lib.mkDefault {}).priority) opt.system
    ++ lib.optional (opt.localSystem.highestPrio < (lib.mkOptionDefault {}).priority) opt.localSystem
    ++ lib.optional (opt.crossSystem.highestPrio < (lib.mkOptionDefault {}).priority) opt.crossSystem
    ;

  defaultPkgs =
@@ -99,19 +96,19 @@ in
  imports = [
    ./assertions.nix
    ./meta.nix
    (mkRemovedOptionModule [ "nixpkgs" "initialSystem" ] "The NixOS options `nesting.clone` and `nesting.children` have been deleted, and replaced with named specialisation. Therefore `nixpgks.initialSystem` has no effect anymore.")
    (lib.mkRemovedOptionModule [ "nixpkgs" "initialSystem" ] "The NixOS options `nesting.clone` and `nesting.children` have been deleted, and replaced with named specialisation. Therefore `nixpgks.initialSystem` has no effect lib.anymore.")
  ];

  options.nixpkgs = {

    pkgs = mkOption {
      defaultText = literalExpression ''
    pkgs = lib.mkOption {
      defaultText = lib.literalExpression ''
        import "''${nixos}/.." {
          inherit (cfg) config overlays localSystem crossSystem;
        }
      '';
      type = pkgsType;
      example = literalExpression "import <nixpkgs> {}";
      example = lib.literalExpression "import <nixpkgs> {}";
      description = ''
        If set, the pkgs argument to all NixOS modules is the value of
        this option, extended with `nixpkgs.overlays`, if
@@ -145,9 +142,9 @@ in
      '';
    };

    config = mkOption {
    config = lib.mkOption {
      default = {};
      example = literalExpression
      example = lib.literalExpression
        ''
          { allowBroken = true; allowUnfree = true; }
        '';
@@ -160,9 +157,9 @@ in
      '';
    };

    overlays = mkOption {
    overlays = lib.mkOption {
      default = [];
      example = literalExpression
      example = lib.literalExpression
        ''
          [
            (self: super: {
@@ -173,7 +170,7 @@ in
            })
          ]
        '';
      type = types.listOf overlayType;
      type = lib.types.listOf overlayType;
      description = ''
        List of overlays to apply to Nixpkgs.
        This option allows modifying the Nixpkgs package set accessed through the `pkgs` module argument.
@@ -184,13 +181,13 @@ in
      '';
    };

    hostPlatform = mkOption {
      type = types.either types.str types.attrs; # TODO utilize lib.systems.parsedPlatform
    hostPlatform = lib.mkOption {
      type = lib.types.either lib.types.str lib.types.attrs; # TODO utilize lib.systems.parsedPlatform
      example = { system = "aarch64-linux"; };
      # Make sure that the final value has all fields for sake of other modules
      # referring to this. TODO make `lib.systems` itself use the module system.
      apply = lib.systems.elaborate;
      defaultText = literalExpression
      defaultText = lib.literalExpression
        ''(import "''${nixos}/../lib").lib.systems.examples.aarch64-multiplatform'';
      description = ''
        Specifies the platform where the NixOS configuration will run.
@@ -201,8 +198,8 @@ in
      '';
    };

    buildPlatform = mkOption {
      type = types.either types.str types.attrs; # TODO utilize lib.systems.parsedPlatform
    buildPlatform = lib.mkOption {
      type = lib.types.either lib.types.str lib.types.attrs; # TODO utilize lib.systems.parsedPlatform
      default = cfg.hostPlatform;
      example = { system = "x86_64-linux"; };
      # Make sure that the final value has all fields for sake of other modules
@@ -212,7 +209,7 @@ in
        in if lib.systems.equals elaborated cfg.hostPlatform
          then cfg.hostPlatform  # make identical, so that `==` equality works; see https://github.com/NixOS/nixpkgs/issues/278001
          else elaborated;
      defaultText = literalExpression
      defaultText = lib.literalExpression
        ''config.nixpkgs.hostPlatform'';
      description = ''
        Specifies the platform on which NixOS should be built.
@@ -228,14 +225,14 @@ in
      '';
    };

    localSystem = mkOption {
      type = types.attrs; # TODO utilize lib.systems.parsedPlatform
    localSystem = lib.mkOption {
      type = lib.types.attrs; # TODO utilize lib.systems.parsedPlatform
      default = { inherit (cfg) system; };
      example = { system = "aarch64-linux"; };
      # Make sure that the final value has all fields for sake of other modules
      # referring to this. TODO make `lib.systems` itself use the module system.
      apply = lib.systems.elaborate;
      defaultText = literalExpression
      defaultText = lib.literalExpression
        ''(import "''${nixos}/../lib").lib.systems.examples.aarch64-multiplatform'';
      description = ''
        Systems with a recently generated `hardware-configuration.nix`
@@ -262,8 +259,8 @@ in
    # TODO deprecate. "crossSystem" is a nonsense identifier, because "cross"
    #      is a relation between at least 2 systems in the context of a
    #      specific build step, not a single system.
    crossSystem = mkOption {
      type = types.nullOr types.attrs; # TODO utilize lib.systems.parsedPlatform
    crossSystem = lib.mkOption {
      type = lib.types.nullOr lib.types.attrs; # TODO utilize lib.systems.parsedPlatform
      default = null;
      example = { system = "aarch64-linux"; };
      description = ''
@@ -283,8 +280,8 @@ in
      '';
    };

    system = mkOption {
      type = types.str;
    system = lib.mkOption {
      type = lib.types.str;
      example = "i686-linux";
      default =
        if opt.hostPlatform.isDefined
@@ -372,12 +369,12 @@ in
      {
        assertion = constructedByMe -> hasPlatform -> legacyOptionsDefined == [];
        message = ''
          Your system configures nixpkgs with the platform parameter${optionalString hasBuildPlatform "s"}:
          Your system configures nixpkgs with the platform parameter${lib.optionalString hasBuildPlatform "s"}:
          ${hostPlatformLine
          }${buildPlatformLine
          }
          However, it also defines the legacy options:
          ${concatMapStrings showOptionWithDefLocs legacyOptionsDefined}
          ${lib.concatMapStrings lib.showOptionWithDefLocs legacyOptionsDefined}
          For a future proof system configuration, we recommend to remove
          the legacy definitions.
        '';
Loading