Commit 374e6bcc authored by Silvan Mosberger's avatar Silvan Mosberger
Browse files

treewide: Format all Nix files

Format all Nix files using the officially approved formatter,
making the CI check introduced in the previous commit succeed:

  nix-build ci -A fmt.check

This is the next step of the of the [implementation](https://github.com/NixOS/nixfmt/issues/153)
of the accepted [RFC 166](https://github.com/NixOS/rfcs/pull/166).

This commit will lead to merge conflicts for a number of PRs,
up to an estimated ~1100 (~33%) among the PRs with activity in the past 2
months, but that should be lower than what it would be without the previous
[partial treewide format](https://github.com/NixOS/nixpkgs/pull/322537).

Merge conflicts caused by this commit can now automatically be resolved while rebasing using the
[auto-rebase script](https://github.com/NixOS/nixpkgs/tree/8616af08d915377bd930395f3b700a0e93d08728/maintainers/scripts/auto-rebase).

If you run into any problems regarding any of this, please reach out to the
[formatting team](https://nixos.org/community/teams/formatting/) by
pinging @NixOS/nix-formatting.
parent 2140bf39
Loading
Loading
Loading
Loading
+137 −100
Original line number Diff line number Diff line
@@ -3,17 +3,21 @@
{
  description = "A collection of packages for the Nix package manager";

  outputs = { self }:
  outputs =
    { self }:
    let
      libVersionInfoOverlay = import ./lib/flake-version-info.nix self;
      lib = (import ./lib).extend libVersionInfoOverlay;

      forAllSystems = lib.genAttrs lib.systems.flakeExposed;

      jobs = forAllSystems (system: import ./pkgs/top-level/release.nix {
      jobs = forAllSystems (
        system:
        import ./pkgs/top-level/release.nix {
          nixpkgs = self;
          inherit system;
      });
        }
      );
    in
    {
      /**
@@ -26,7 +30,8 @@
      */
      # DON'T USE lib.extend TO ADD NEW FUNCTIONALITY.
      # THIS WAS A MISTAKE. See the warning in lib/default.nix.
      lib = lib.extend (final: prev: {
      lib = lib.extend (
        final: prev: {

          /**
            Other NixOS-provided functionality, such as [`runTest`](https://nixos.org/manual/nixos/unstable/#sec-call-nixos-test-outside-nixos).
@@ -56,7 +61,8 @@
            - `system`: Legacy alias for `nixpkgs.hostPlatform`, but this is already set in the generated `hardware-configuration.nix`, included by `configuration.nix`.
            - `pkgs`: Legacy alias for `nixpkgs.pkgs`; use `nixpkgs.pkgs` and `nixosModules.readOnlyPkgs` instead.
          */
        nixosSystem = args:
          nixosSystem =
            args:
            import ./nixos/lib/eval-config.nix (
              {
                lib = final;
@@ -72,17 +78,31 @@
                  #
                  # See: failed attempt to make pkgs.path not copy when using flakes:
                  # https://github.com/NixOS/nixpkgs/pull/153594#issuecomment-1023287913
                ({ config, pkgs, lib, ... }: {
                  (
                    {
                      config,
                      pkgs,
                      lib,
                      ...
                    }:
                    {
                      config.nixpkgs.flake.source = self.outPath;
                })
                    }
                  )
                ];
            } // builtins.removeAttrs args [ "modules" ]
              }
              // builtins.removeAttrs args [ "modules" ]
            );
        }
      );
      });

      checks = forAllSystems (system: {
      checks = forAllSystems (
        system:
        {
          tarball = jobs.${system}.tarball;
      } // lib.optionalAttrs
        }
        //
          lib.optionalAttrs
            (
              self.legacyPackages.${system}.stdenv.hostPlatform.isLinux
              # Exclude power64 due to "libressl is not available on the requested hostPlatform" with hostPlatform being power64
@@ -92,34 +112,45 @@
              # Test that ensures that the nixosSystem function can accept a lib argument
              # Note: prefer not to extend or modify `lib`, especially if you want to share reusable modules
              #       alternatives include: `import` a file, or put a custom library in an option or in `_module.args.<libname>`
        nixosSystemAcceptsLib = (self.lib.nixosSystem {
              nixosSystemAcceptsLib =
                (self.lib.nixosSystem {
                  pkgs = self.legacyPackages.${system};
          lib = self.lib.extend (final: prev: {
                  lib = self.lib.extend (
                    final: prev: {
                      ifThisFunctionIsMissingTheTestFails = final.id;
          });
                    }
                  );
                  modules = [
                    ./nixos/modules/profiles/minimal.nix
            ({ lib, ... }: lib.ifThisFunctionIsMissingTheTestFails {
                    (
                      { lib, ... }:
                      lib.ifThisFunctionIsMissingTheTestFails {
                        # Define a minimal config without eval warnings
                        nixpkgs.hostPlatform = "x86_64-linux";
                        boot.loader.grub.enable = false;
                        fileSystems."/".device = "nodev";
                        # See https://search.nixos.org/options?show=system.stateVersion&query=stateversion
                        system.stateVersion = lib.trivial.release; # DON'T do this in real configs!
            })
                      }
                    )
                  ];
                }).config.system.build.toplevel;
      });
            }
      );

      htmlDocs = {
        nixpkgsManual = builtins.mapAttrs (_: jobSet: jobSet.manual) jobs;
        nixosManual = (import ./nixos/release-small.nix {
        nixosManual =
          (import ./nixos/release-small.nix {
            nixpkgs = self;
          }).nixos.manual;
      };

      devShells = forAllSystems (system:
        { } // lib.optionalAttrs
      devShells = forAllSystems (
        system:
        { }
        //
          lib.optionalAttrs
            (
              # Exclude armv6l-linux because "Package ‘ghc-9.6.6’ in .../pkgs/development/compilers/ghc/common-hadrian.nix:579 is not available on the requested hostPlatform"
              system != "armv6l-linux"
@@ -129,9 +160,12 @@
              && !self.legacyPackages.${system}.stdenv.hostPlatform.isFreeBSD
            )
            {
          /** A shell to get tooling for Nixpkgs development. See nixpkgs/shell.nix. */
              /**
                A shell to get tooling for Nixpkgs development. See nixpkgs/shell.nix.
              */
              default = import ./shell.nix { inherit system; };
        });
            }
      );

      formatter = forAllSystems (system: (import ./ci { inherit system; }).fmt.pkg);

@@ -154,10 +188,13 @@
        evaluation. Evaluating the attribute value tends to require a significant
        amount of computation, even considering lazy evaluation.
      */
      legacyPackages = forAllSystems (system:
        (import ./. { inherit system; }).extend (final: prev: {
      legacyPackages = forAllSystems (
        system:
        (import ./. { inherit system; }).extend (
          final: prev: {
            lib = prev.lib.extend libVersionInfoOverlay;
        })
          }
        )
      );

      /**
+268 −325

File changed.

Preview size limit exceeded, changes collapsed.

+560 −206
Original line number Diff line number Diff line
/* Library of low-level helper functions for nix expressions.
 *
 * Please implement (mostly) exhaustive unit tests
 * for new functions in `./tests.nix`.
/*
  Library of low-level helper functions for nix expressions.

  Please implement (mostly) exhaustive unit tests
  for new functions in `./tests.nix`.
*/
let

@@ -9,7 +10,8 @@ let
  # It has been leading to some trouble, so we have to document it specially.
  makeExtensible' =
    rattrs:
    let self = rattrs self // {
    let
      self = rattrs self // {
        /**
          Patch the Nixpkgs library

@@ -37,11 +39,15 @@ let
        */
        extend = f: lib.makeExtensible (lib.extends f rattrs);
      };
    in self;
    in
    self;

  lib = makeExtensible' (self: let
  lib = makeExtensible' (
    self:
    let
      callLibs = file: import file { lib = self; };
  in {
    in
    {

      # often used, or depending on very little
      trivial = callLibs ./trivial.nix;
@@ -101,112 +107,460 @@ let

      # TODO: For consistency, all builtins should also be available from a sub-library;
      # these are the only ones that are currently not
    inherit (builtins) addErrorContext isPath trace typeOf unsafeGetAttrPos;
    inherit (self.trivial) id const pipe concat or and xor bitAnd bitOr bitXor
      bitNot boolToString mergeAttrs flip defaultTo mapNullable inNixShell isFloat min max
      importJSON importTOML warn warnIf warnIfNot throwIf throwIfNot checkListOfEnum
      info showWarnings nixpkgsVersion version isInOldestRelease oldestSupportedReleaseIsAtLeast
      mod compare splitByAndCompare seq deepSeq lessThan add sub
      functionArgs setFunctionArgs isFunction toFunction mirrorFunctionArgs
      fromHexString toHexString toBaseDigits inPureEvalMode isBool isInt pathExists
      genericClosure readFile;
    inherit (self.fixedPoints) fix fix' converge extends composeExtensions
      composeManyExtensions makeExtensible makeExtensibleWithCustomName
      toExtension;
    inherit (self.attrsets) attrByPath hasAttrByPath setAttrByPath
      getAttrFromPath attrVals attrNames attrValues getAttrs catAttrs filterAttrs
      filterAttrsRecursive foldlAttrs foldAttrs collect nameValuePair mapAttrs
      mapAttrs' mapAttrsToList attrsToList concatMapAttrs mapAttrsRecursive
      mapAttrsRecursiveCond genAttrs isDerivation toDerivation optionalAttrs
      zipAttrsWithNames zipAttrsWith zipAttrs recursiveUpdateUntil
      recursiveUpdate matchAttrs mergeAttrsList overrideExisting showAttrPath getOutput getFirstOutput
      getBin getLib getStatic getDev getInclude getMan chooseDevOutputs zipWithNames zip
      recurseIntoAttrs dontRecurseIntoAttrs cartesianProduct cartesianProductOfSets
      mapCartesianProduct updateManyAttrsByPath listToAttrs hasAttr getAttr isAttrs intersectAttrs removeAttrs;
    inherit (self.lists) singleton forEach map foldr fold foldl foldl' imap0 imap1
      filter ifilter0 concatMap flatten remove findSingle findFirst any all count
      optional optionals toList range replicate partition zipListsWith zipLists
      reverseList listDfs toposort sort sortOn naturalSort compareLists
      take drop dropEnd sublist last init
      crossLists unique allUnique intersectLists
      subtractLists mutuallyExclusive groupBy groupBy' concatLists genList
      length head tail elem elemAt isList;
    inherit (self.strings) concatStrings concatMapStrings concatImapStrings
      stringLength substring isString replaceStrings
      intersperse concatStringsSep concatMapStringsSep concatMapAttrsStringSep
      concatImapStringsSep concatLines makeSearchPath makeSearchPathOutput
      makeLibraryPath makeIncludePath makeBinPath optionalString
      hasInfix hasPrefix hasSuffix stringToCharacters stringAsChars escape
      escapeShellArg escapeShellArgs
      isStorePath isStringLike
      isValidPosixName toShellVar toShellVars trim trimWith
      escapeRegex escapeURL escapeXML replaceChars lowerChars
      upperChars toLower toUpper toSentenceCase addContextFrom splitString
      removePrefix removeSuffix versionOlder versionAtLeast
      getName getVersion match split
      cmakeOptionType cmakeBool cmakeFeature
      mesonOption mesonBool mesonEnable
      nameFromURL enableFeature enableFeatureAs withFeature
      withFeatureAs fixedWidthString fixedWidthNumber
      toInt toIntBase10 readPathsFromFile fileContents;
    inherit (self.stringsWithDeps) textClosureList textClosureMap
      noDepEntry fullDepEntry packEntry stringAfter;
    inherit (self.customisation) overrideDerivation makeOverridable
      callPackageWith callPackagesWith extendDerivation hydraJob
      makeScope makeScopeWithSplicing makeScopeWithSplicing'
      extendMkDerivation;
      inherit (builtins)
        addErrorContext
        isPath
        trace
        typeOf
        unsafeGetAttrPos
        ;
      inherit (self.trivial)
        id
        const
        pipe
        concat
        or
        and
        xor
        bitAnd
        bitOr
        bitXor
        bitNot
        boolToString
        mergeAttrs
        flip
        defaultTo
        mapNullable
        inNixShell
        isFloat
        min
        max
        importJSON
        importTOML
        warn
        warnIf
        warnIfNot
        throwIf
        throwIfNot
        checkListOfEnum
        info
        showWarnings
        nixpkgsVersion
        version
        isInOldestRelease
        oldestSupportedReleaseIsAtLeast
        mod
        compare
        splitByAndCompare
        seq
        deepSeq
        lessThan
        add
        sub
        functionArgs
        setFunctionArgs
        isFunction
        toFunction
        mirrorFunctionArgs
        fromHexString
        toHexString
        toBaseDigits
        inPureEvalMode
        isBool
        isInt
        pathExists
        genericClosure
        readFile
        ;
      inherit (self.fixedPoints)
        fix
        fix'
        converge
        extends
        composeExtensions
        composeManyExtensions
        makeExtensible
        makeExtensibleWithCustomName
        toExtension
        ;
      inherit (self.attrsets)
        attrByPath
        hasAttrByPath
        setAttrByPath
        getAttrFromPath
        attrVals
        attrNames
        attrValues
        getAttrs
        catAttrs
        filterAttrs
        filterAttrsRecursive
        foldlAttrs
        foldAttrs
        collect
        nameValuePair
        mapAttrs
        mapAttrs'
        mapAttrsToList
        attrsToList
        concatMapAttrs
        mapAttrsRecursive
        mapAttrsRecursiveCond
        genAttrs
        isDerivation
        toDerivation
        optionalAttrs
        zipAttrsWithNames
        zipAttrsWith
        zipAttrs
        recursiveUpdateUntil
        recursiveUpdate
        matchAttrs
        mergeAttrsList
        overrideExisting
        showAttrPath
        getOutput
        getFirstOutput
        getBin
        getLib
        getStatic
        getDev
        getInclude
        getMan
        chooseDevOutputs
        zipWithNames
        zip
        recurseIntoAttrs
        dontRecurseIntoAttrs
        cartesianProduct
        cartesianProductOfSets
        mapCartesianProduct
        updateManyAttrsByPath
        listToAttrs
        hasAttr
        getAttr
        isAttrs
        intersectAttrs
        removeAttrs
        ;
      inherit (self.lists)
        singleton
        forEach
        map
        foldr
        fold
        foldl
        foldl'
        imap0
        imap1
        filter
        ifilter0
        concatMap
        flatten
        remove
        findSingle
        findFirst
        any
        all
        count
        optional
        optionals
        toList
        range
        replicate
        partition
        zipListsWith
        zipLists
        reverseList
        listDfs
        toposort
        sort
        sortOn
        naturalSort
        compareLists
        take
        drop
        dropEnd
        sublist
        last
        init
        crossLists
        unique
        allUnique
        intersectLists
        subtractLists
        mutuallyExclusive
        groupBy
        groupBy'
        concatLists
        genList
        length
        head
        tail
        elem
        elemAt
        isList
        ;
      inherit (self.strings)
        concatStrings
        concatMapStrings
        concatImapStrings
        stringLength
        substring
        isString
        replaceStrings
        intersperse
        concatStringsSep
        concatMapStringsSep
        concatMapAttrsStringSep
        concatImapStringsSep
        concatLines
        makeSearchPath
        makeSearchPathOutput
        makeLibraryPath
        makeIncludePath
        makeBinPath
        optionalString
        hasInfix
        hasPrefix
        hasSuffix
        stringToCharacters
        stringAsChars
        escape
        escapeShellArg
        escapeShellArgs
        isStorePath
        isStringLike
        isValidPosixName
        toShellVar
        toShellVars
        trim
        trimWith
        escapeRegex
        escapeURL
        escapeXML
        replaceChars
        lowerChars
        upperChars
        toLower
        toUpper
        toSentenceCase
        addContextFrom
        splitString
        removePrefix
        removeSuffix
        versionOlder
        versionAtLeast
        getName
        getVersion
        match
        split
        cmakeOptionType
        cmakeBool
        cmakeFeature
        mesonOption
        mesonBool
        mesonEnable
        nameFromURL
        enableFeature
        enableFeatureAs
        withFeature
        withFeatureAs
        fixedWidthString
        fixedWidthNumber
        toInt
        toIntBase10
        readPathsFromFile
        fileContents
        ;
      inherit (self.stringsWithDeps)
        textClosureList
        textClosureMap
        noDepEntry
        fullDepEntry
        packEntry
        stringAfter
        ;
      inherit (self.customisation)
        overrideDerivation
        makeOverridable
        callPackageWith
        callPackagesWith
        extendDerivation
        hydraJob
        makeScope
        makeScopeWithSplicing
        makeScopeWithSplicing'
        extendMkDerivation
        ;
      inherit (self.derivations) lazyDerivation optionalDrvAttr warnOnInstantiate;
      inherit (self.generators) mkLuaInline;
    inherit (self.meta) addMetaAttrs dontDistribute setName updateName
      appendToName mapDerivationAttrset setPrio lowPrio lowPrioSet hiPrio
      hiPrioSet licensesSpdx getLicenseFromSpdxId getLicenseFromSpdxIdOr
      getExe getExe';
    inherit (self.filesystem) pathType pathIsDirectory pathIsRegularFile
      packagesFromDirectoryRecursive;
    inherit (self.sources) cleanSourceFilter
      cleanSource sourceByRegex sourceFilesBySuffices
      commitIdFromGitRepo cleanSourceWith pathHasContext
      canCleanSource pathIsGitRepo;
    inherit (self.modules) evalModules setDefaultModuleLocation
      unifyModuleSyntax applyModuleArgsIfFunction mergeModules
      mergeModules' mergeOptionDecls mergeDefinitions
      pushDownProperties dischargeProperties filterOverrides
      sortProperties fixupOptionType mkIf mkAssert mkMerge mkOverride
      mkOptionDefault mkDefault mkImageMediaOverride mkForce mkVMOverride
      mkFixStrictness mkOrder mkBefore mkAfter mkAliasDefinitions
      mkAliasAndWrapDefinitions fixMergeModules mkRemovedOptionModule
      mkRenamedOptionModule mkRenamedOptionModuleWith
      mkMergedOptionModule mkChangedOptionModule
      mkAliasOptionModule mkDerivedConfig doRename
      mkAliasOptionModuleMD;
      inherit (self.meta)
        addMetaAttrs
        dontDistribute
        setName
        updateName
        appendToName
        mapDerivationAttrset
        setPrio
        lowPrio
        lowPrioSet
        hiPrio
        hiPrioSet
        licensesSpdx
        getLicenseFromSpdxId
        getLicenseFromSpdxIdOr
        getExe
        getExe'
        ;
      inherit (self.filesystem)
        pathType
        pathIsDirectory
        pathIsRegularFile
        packagesFromDirectoryRecursive
        ;
      inherit (self.sources)
        cleanSourceFilter
        cleanSource
        sourceByRegex
        sourceFilesBySuffices
        commitIdFromGitRepo
        cleanSourceWith
        pathHasContext
        canCleanSource
        pathIsGitRepo
        ;
      inherit (self.modules)
        evalModules
        setDefaultModuleLocation
        unifyModuleSyntax
        applyModuleArgsIfFunction
        mergeModules
        mergeModules'
        mergeOptionDecls
        mergeDefinitions
        pushDownProperties
        dischargeProperties
        filterOverrides
        sortProperties
        fixupOptionType
        mkIf
        mkAssert
        mkMerge
        mkOverride
        mkOptionDefault
        mkDefault
        mkImageMediaOverride
        mkForce
        mkVMOverride
        mkFixStrictness
        mkOrder
        mkBefore
        mkAfter
        mkAliasDefinitions
        mkAliasAndWrapDefinitions
        fixMergeModules
        mkRemovedOptionModule
        mkRenamedOptionModule
        mkRenamedOptionModuleWith
        mkMergedOptionModule
        mkChangedOptionModule
        mkAliasOptionModule
        mkDerivedConfig
        doRename
        mkAliasOptionModuleMD
        ;
      evalOptionValue = lib.warn "External use of `lib.evalOptionValue` is deprecated. If your use case isn't covered by non-deprecated functions, we'd like to know more and perhaps support your use case well, instead of providing access to these low level functions. In this case please open an issue in https://github.com/nixos/nixpkgs/issues/." self.modules.evalOptionValue;
    inherit (self.options) isOption mkEnableOption mkSinkUndeclaredOptions
      mergeDefaultOption mergeOneOption mergeEqualOption mergeUniqueOption
      getValues getFiles
      optionAttrSetToDocList optionAttrSetToDocList'
      scrubOptionValue literalExpression literalExample
      showOption showOptionWithDefLocs showFiles
      unknownModule mkOption mkPackageOption mkPackageOptionMD
      literalMD;
    inherit (self.types) isType setType defaultTypeMerge defaultFunctor
      isOptionType mkOptionType;
      inherit (self.options)
        isOption
        mkEnableOption
        mkSinkUndeclaredOptions
        mergeDefaultOption
        mergeOneOption
        mergeEqualOption
        mergeUniqueOption
        getValues
        getFiles
        optionAttrSetToDocList
        optionAttrSetToDocList'
        scrubOptionValue
        literalExpression
        literalExample
        showOption
        showOptionWithDefLocs
        showFiles
        unknownModule
        mkOption
        mkPackageOption
        mkPackageOptionMD
        literalMD
        ;
      inherit (self.types)
        isType
        setType
        defaultTypeMerge
        defaultFunctor
        isOptionType
        mkOptionType
        ;
      inherit (self.asserts)
      assertMsg assertOneOf;
    inherit (self.debug) traceIf traceVal traceValFn
      traceSeq traceSeqN traceValSeq
      traceValSeqFn traceValSeqN traceValSeqNFn traceFnSeqN
      runTests testAllTrue;
    inherit (self.misc) maybeEnv defaultMergeArg defaultMerge foldArgs
      maybeAttrNullable maybeAttr ifEnable checkFlag getValue
      checkReqs uniqList uniqListExt condConcat lazyGenericClosure
      innerModifySumArgs modifySumArgs innerClosePropagation
      closePropagation mapAttrsFlatten nvs setAttr setAttrMerge
      mergeAttrsWithFunc mergeAttrsConcatenateValues
      mergeAttrsNoOverride mergeAttrByFunc mergeAttrsByFuncDefaults
      mergeAttrsByFuncDefaultsClean mergeAttrBy
      fakeHash fakeSha256 fakeSha512
      nixType imap;
        assertMsg
        assertOneOf
        ;
      inherit (self.debug)
        traceIf
        traceVal
        traceValFn
        traceSeq
        traceSeqN
        traceValSeq
        traceValSeqFn
        traceValSeqN
        traceValSeqNFn
        traceFnSeqN
        runTests
        testAllTrue
        ;
      inherit (self.misc)
        maybeEnv
        defaultMergeArg
        defaultMerge
        foldArgs
        maybeAttrNullable
        maybeAttr
        ifEnable
        checkFlag
        getValue
        checkReqs
        uniqList
        uniqListExt
        condConcat
        lazyGenericClosure
        innerModifySumArgs
        modifySumArgs
        innerClosePropagation
        closePropagation
        mapAttrsFlatten
        nvs
        setAttr
        setAttrMerge
        mergeAttrsWithFunc
        mergeAttrsConcatenateValues
        mergeAttrsNoOverride
        mergeAttrByFunc
        mergeAttrsByFuncDefaults
        mergeAttrsByFuncDefaultsClean
        mergeAttrBy
        fakeHash
        fakeSha256
        fakeSha512
        nixType
        imap
        ;
      inherit (self.versions)
      splitVersion;
  });
in lib
        splitVersion
        ;
    }
  );
in
lib
+310 −196

File changed.

Preview size limit exceeded, changes collapsed.

+109 −79

File changed.

Preview size limit exceeded, changes collapsed.

Loading