83 Commits

Author SHA1 Message Date
Emily
681aca54e6 pkgs/toplevel: avoid elaborating crossSystem if not passed (#519223) 2026-05-13 00:57:17 +00:00
Eman Resu
75429919df pkgs/toplevel: avoid elaborating crossSystem if not passed
Later on, `if crossSystem0 == null` is performed to avoid a
`lib.systems.elaborate` if possible. We'd like to take that chance!
2026-05-11 22:05:09 -04:00
Martin Weinelt
6cba250893 Revert "Reapply "nixos/nixpkgs.config: make use of the module defined in config.nix"" 2026-05-10 20:27:56 +02:00
Johannes Kirschbauer
86cd4e7bc8 Reapply "nixos/nixpkgs.config: make use of the module defined in config.nix"
This reverts commit a06a6caa6b.
2026-05-07 19:11:47 +02:00
K900
a06a6caa6b Revert "nixos/nixpkgs.config: make use of the module defined in config.nix" 2026-05-07 15:38:29 +03:00
Johannes Kirschbauer
1d1e96211e nixos/nixpkgs.config: use deferredModule to avoid double evaluation
Switch the option type to `deferredModuleWith`, which collects definitions without evaluating them.
The raw definitions are forwarded to nixpkgs function via a new internal `_configDefinitions` parameter.

`apply` on the option returns `finalPkgs.config`, preserving
backwards compatibility for external readers of `config.nixpkgs.config`
2026-05-04 10:05:11 +02:00
Emily
4a20fb1916 top-level: add warning for x86_64-darwin deprecation
We’ve never deprecated a platform in widespread use before, and it
seems prudent to warn users about the upcoming end of support so they
can plan appropriately.

I tried to make this relatively unobtrusive by taking advantage of
the import cache and offering a way to turn it off, but I anticipate
there might still be issues with e.g. `nix shell nixpkgs#…` and
spammy warnings from multiple instantiations of Nixpkgs. I’m
not sure there’s much we can do about that unless we take a
different strategy entirely; `nix shell --impure nixpkgs#…` with a
`~/.config/nixpkgs/config.nix` is about the best UX we can hope to
offer with the restrictions of flakes.
2026-02-27 22:27:02 +00:00
Silvan Mosberger
27dd434480 stdenv.mkDerivation: Initial RFC 127 implementation
See https://github.com/NixOS/rfcs/blob/master/rfcs/0127-issues-warnings.md

Co-Authored-By: piegames <git@piegames.de>
Co-Authored-By: AkechiShiro <14914796+AkechiShiro@users.noreply.github.com>
2026-02-26 14:53:30 +01:00
Adam Dinwoodie
8e94561d62 nixpkgs: pass lib to config function
Nixpkgs config, for defining things like which licenses are
permitted, can either be an attrset or a function that is passed a
`pkgs` argument.  Evaluating that `pkgs` argument requires computing the
Nixpkgs fixpoint, which requires checking whether the derivations used
in the Nixpkgs bootstrap have valid licenses.  This works provided
nothing tries to use Nixpkgs functions to validate or merge anything
included in the configuration.

f5deefd463 (config: add and document {allow,block}listedLicenses,
2025-08-31), in #437723, added type checking and merging to the lists of
permitted/forbidden licenses.  That resulted in a recursion loop if a
list of licenses included, say, `pkgs.lib.licenses.bsd0`.

To allow licenses to be specified from Nixpkgs' library, pass `lib` as
well as `pkgs` to any config function.  Computing `lib` doesn't require
working out the full Nixpkgs fixpoint.  The change in #437723 will still
break things for some people, but it at least provides a sensible route
to getting the config working again.

Fixes #456994.
2026-01-05 21:36:29 +00:00
Matt Sturgeon
321006d2d9 top-level: simplify checked using lib.all 2025-10-24 07:29:39 +01:00
Matt Sturgeon
e92214c3a4 top-level: use parentheses to group checks
Group `throwIfNot` chains with parentheses to improve readability and
hint to nixfmt the intended formatting.

This makes the result visually closer to the pre-nixfmt layout:

    checked =
      throwIfNot (lib.isList overlays) "The overlays argument to nixpkgs must be a list."
      lib.foldr (x: throwIfNot (lib.isFunction x) "All overlays passed to nixpkgs must be functions.") (r: r) overlays
      throwIfNot (lib.isList crossOverlays) "The crossOverlays argument to nixpkgs must be a list."
      lib.foldr (x: throwIfNot (lib.isFunction x) "All crossOverlays passed to nixpkgs must be functions.") (r: r) crossOverlays
      ;
2025-10-24 07:26:03 +01:00
Silvan Mosberger
374e6bcc40 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](8616af08d9/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.
2025-04-01 20:10:43 +02:00
Peder Bergebakken Sundt
5aba99242e treewide: fix typos in comments
Made with

```shell
git restore .
fd '\.nix$' pkgs/ --type f -j1 -x bash -xc "$(cat <<"EOF"
    typos --no-check-filenames --write-changes "$1"
    git diff --exit-code "$1" && exit
    #( git diff "$1" | grep -qE "^\+ +[^# ]") && git restore "$1"
    count1="$( bat --language nix --diff --style changes "$1" --theme "Monokai Extended" --color always | aha --no-header | grep -E '^<span style="color:olive;">~</span> ' | wc -l )"
    count2="$( bat --language nix --diff --style changes "$1" --theme "Monokai Extended" --color always | aha --no-header | grep -E '^<span style="color:olive;">~</span> (<span style="color:#f8f8f2;"> *</span>)?<span style="color:#75715e;">.*</span>$' | wc -l )"
    [[ $count1 -ne $count2 ]] && git restore "$1"
EOF
)" -- {}
```

and filtered with `GIT_DIFF_OPTS='--unified=15' git -c interactive.singleKey=true add --patch`

I initially tried using the tree-sitter cli, python bindings and even ast-grep through various means, but this is what I ended up with.
2025-02-24 10:44:41 +01:00
Robert Hensing
692a57e61d Revert "Reapply "pkgs/top-level: make package sets composable""
This reverts commit d2faa1bbca.
2025-02-05 14:29:11 +01:00
Robert Hensing
623541a18b Revert "pkgs/top-level: add assert to prevent passing elaborated systems"
This reverts commit 434e36ab91.
2025-02-05 14:29:04 +01:00
Wolfgang Walther
434e36ab91 pkgs/top-level: add assert to prevent passing elaborated systems
The commit to make package sets composable depends on the fact that
localSystem and crossSystem can be passed forward to lower package sets
for composition. Once we pass a fully elaborated system, this will break
down - getters like "isStatic", "isMusl" etc. will not change with the
package set anymore, but be stuck on the value passed in via those
options.

This is a limitation of lib.systems.elaborate primarily, because it
can't deal with arbitrary overrides properly.

freshBootstrapTools on darwin used to do this, although in this case it
didn't do any harm: There shouldn't be any package sets composed during
bootstrap anyway. Refactor it, to avoid throwing the assert.
2025-02-01 12:05:00 +01:00
Wolfgang Walther
d2faa1bbca Reapply "pkgs/top-level: make package sets composable"
This reverts commit 7c251e2b5f.

Left out eec21001b0, which changed
nixos/nixpkgs, doing it differently this time.
2025-02-01 12:04:59 +01:00
K900
7c251e2b5f Revert "pkgs/top-level: make package sets composable" 2025-01-26 09:43:44 +03:00
Wolfgang Walther
01a02e41f7 pkgs/top-level: make package sets composable
The various pkgsXYZ top-level package sets did not pass localSystem /
crossSystem to lower levels, so far. This change propagates original
arguments to lower levels, which include the overrides made by an upper
package sets.

There is an extensive test-suite to test various combinations of package
sets in pkgs/test/top-level. There are a few basic promises made:

- Package sets must be idempotent. pkgsMusl.pkgsMusl === pkgsMusl.

- Once pkgsCross is used any subsequent package sets should affect the
  **host platform** and not the build platform. Examples:
  - pkgsMusl.pkgsCross.aarch64-multiplatform is a cross compilation from
musl to glibc/aarch64
  - pkgsCross.aarch64-multiplatform.pkgsMusl is a cross compilation to
musl/aarch64

- Modifications from an earlier layer should not be lost, unless
  explicitly overwritten. Examples:
  - pkgsStatic.pkgsMusl should still be static.
  - pkgsStatic.pkgsCross.gnu64 should be static, but with glibc instead
of musl.

Exceptions / TODOs:
- pkgsExtraHardening is currently not idempotent, because it applies the
  same flags over and over again.

Supersedes #136549
Resolves #114510
Resolves #212494
Resolves #281596
2025-01-25 18:55:03 +01:00
Wolfgang Walther
4e7cc47a22 pkgs/top-level: rewrite some outdated comments
This removes all specific references to pkgsCross or pkgsi686Linux, because
they have become outdated with the addition of many more package sets.
2025-01-25 17:59:54 +01:00
Emily
8725e466ef release: forbid use of lib.fileset in Nixpkgs
Due to Nix bug <https://github.com/NixOS/nix/issues/11503>,
`builtins.filterSource` and chroot stores interact in a confusing
and broken way that breaks `lib.fileset`. This means that uses of
the API inside Nixpkgs keep breaking the NixOS installer, blocking
the channel. The resulting error messages are inscrutable (they look
like “the installer test is trying to download `curl`…?” and
eventually bottom out in a derivation that has the wrong `outPath`
because of the chroot store causing an incorrect `lib.fileset` result).

Whenever this happens, someone (well, in practice K900 or I)
has to bisect the change that introduced it and remove the use of
`lib.fileset`. This has happened at least three times in the past
four months (I believe I might actually be missing one here, but
these are the ones I remember and could easily dig up):

* <https://github.com/NixOS/nixpkgs/pull/340046>
* <https://github.com/NixOS/nixpkgs/pull/352491>
* <https://github.com/NixOS/nixpkgs/pull/369459>

The options I see here are:

1. Forbid use of `lib.fileset` within Nixpkgs until the Nix bug is
   fixed. This is the approach taken here. External users of Nixpkgs
   can continue to use the API as normal, but using it from within
   something that affects any release jobset `outPath`s will cause an
   evaluation failure with a hopefully‐helpful error message.

2. Forbid `lib.fileset` and also all of the other library APIs that use
   `builtins.filterSource`. I’m happy to do this, but so far none of
   those have broken the installer, so I decided to start small and
   worry about the others if they end up causing a problem in practice.

3. Forbid `builtins.filterSource` directly. This is hard and would
   require more invasive `builtins.scopedImport` crimes to do at
   evaluation time. I think this would realistically have to be done in
   something like nixpkgs-vet instead and I didn’t have much luck
   shoehorning a check like this into that codebase when I tried.

4. Fix the Nix bug. This would be great! But also it doesn’t seem to be
   happening any time soon, it seems difficult to fix in a way that
   doesn’t subtly break compatibility with the previous semantics, and
   arguably the fix would need backporting all the way back to 2.3
   given our minimum version policy.

5. Do nothing; have people continue to innocuously use `lib.fileset`
   throughout Nixpkgs, breaking the installer whenever one of them
   sneaks in to that closure, causing the channel to be blocked and
   requiring expensive bisections to narrow down the inscrutable test
   failure to the package using `lib.fileset`, which then needs moving
   back off it. This sucks for the people who keep having to track it
   down, holds back important channel bumps, and the criteria for when
   it’s okay to use `lib.fileset` are not realistically possible to
   teach to all contributors.

I'd be happy to work on (2) as an alternative; (3) would be difficult
and seems like overkill, (4) is not really something I trust myself
to do and wouldn’t address the immediate problem, and (5) isn’t
sustainable. I think that the current approach here is the best
trade‐off for now, as `lib.fileset` seems to be the only prominent
user of the `builtins.filterSource` API that works with full store
paths, exposing it to the Nix bug. It’s unfortunate to lose the
nice API, but since we can’t rely on it to produce correct results
and the channels keep getting blocked as a result, I don’t think
we really have an alternative right now.
2024-12-31 15:01:04 +00:00
Ivan Trubach
d4063e0330 pkgs/top-level: use lib.systems.equals for crossSystem
Fixes otherwise equivalent systems being treated as different by
packages that compare `stdenv.*Platform`s using `==` operator.
2023-09-13 07:22:52 +03:00
Robert Hensing
8054785157 lib/modules: Move class out of specialArgs 2023-05-06 18:32:58 +02:00
Robert Hensing
79703eef08 nixos,nixpkgs: Add module classes
This allows modules that declare their class to be checked.
While that's not most user modules, frameworks can take advantage
of this by setting declaring the module class for their users.
That way, the mistake of importing a module into the wrong hierarchy
can be reported more clearly in some cases.
2023-05-06 18:29:04 +02:00
Robert Hensing
596b3663a5 pkgs/top-level/config.nix: Add warnUndeclaredOptions 2022-05-10 07:01:00 +02:00
Robert Hensing
f2c5c706f4 lib.throwIfNot: init 2021-12-22 13:13:50 +01:00
Robert Hensing
cf73196411 nixpkgs: Check overlays types
This seems to be a common mistake and is worth checking so we can
provide a better error message.
2021-12-22 13:13:16 +01:00
John Ericson
2dde58903e top-level: Simplify impure and pure fallback
This is now possible, since the `platform` attribute has been removed in
PR #107214. I've been waiting to do a cleanup like this for a long time!
2021-01-23 10:01:38 -05:00
Cole Helbling
11eddd61bc top-level: ignore unexpected args
This fixes both `nix-shell` failing to eval with `nixUnstable`, as well
as ofborg's failure to eval on aarch64 due to passing an "unexpected
arg" (1112e3a8c8/ofborg/src/nix.rs (L334-L340)).
2020-10-01 11:21:32 -07:00
Matthew Bauer
635b762569 systems: allow passing in string for cross/localSystem
This makes things a little bit more convenient. Just pass in like:

$ nix-build ’<nixpkgs>’ -A hello --argstr localSystem x86_64-linux --argstr crossSystem aarch64-linux
2019-06-04 11:17:25 -04:00
Jan Malakhovski
83ae1ffed4 pkgs/top-level/stage.nix: don't override overlays and config in nixpkgsFun
`nixpkgsFun` already sets them via `args`. Doing this also introduces unexpected
hard to debug errors, see the patch.
2019-03-08 11:37:20 +02:00
Jan Malakhovski
4a647dd225 pkgs/top-level: check types of nixpkgs.config
This patch simply introduces a plain simple NixOS module and passes
`nixpkgs.config` through it via `evalModules` (with some temporary hackery to
passthru undefined options).
2019-03-08 11:19:38 +02:00
Jan Malakhovski
849b10a419 top-level: fix a typo 2019-02-03 15:30:13 +00:00
Matthew Bauer
a3a6ad7a01 stdenv: implement crossOverlays
crossOverlays only apply to the packages being built, not the build
packages. It is useful when you don’t care what is used to build your
packages, just what is being built. The idea relies heavily on the
cross compiling infrastructure. Using this implies that we need to
create a cross stdenv.
2018-12-04 21:06:46 -06:00
John Ericson
abf27609c6 top-level: Move comma for stylistic consistency 2018-03-20 15:37:34 -04:00
Shea Levy
943592f698 Add setFunctionArgs lib function.
Among other things, this will allow *2nix tools to output plain data
while still being composable with the traditional
callPackage/.override interfaces.
2018-01-31 14:02:19 -05:00
Bjørn Forsman
ff252c799d Fix typo in comment 2017-04-19 20:30:44 +02:00
John Ericson
3efc661a1d Elaborate localSystem and crossSystem in a consistent manner 2017-04-17 17:13:01 -04:00
John Ericson
2227789392 lib: Collect system/platform related files
Previously, platforms was a random thing in top-level
2017-04-17 17:13:01 -04:00
John Ericson
8cd4c31d6b top-level: Allow nixpkgs to take localSystem directly
This is instead of both system and platform, which is kind of ugly.
2017-02-08 22:06:57 -05:00
John Ericson
4c17cd555f top-level: Document the {local,cross}System, contrasting with *Platform`
This is an implementation detail of how the bootstrapping chain is chosen,
and thus need not be in the manual.
2017-01-24 11:37:56 -05:00
John Ericson
92edcb7ebb top-level: Lay the groundwork for {build,host,target}Platform
The long term goal is a big replace:
  { inherit system platform; } => buildPlatform
  crossSystem => hostPlatform
  stdenv.cross => targetPlatform
And additionally making sure each is defined even when not cross compiling.

This commit refactors the bootstrapping code along that vision, but leaves
the old identifiers with their null semantics in place so packages can be
modernized incrementally.
2017-01-24 11:37:56 -05:00
Nicolas B. Pierron
f5dfe78a1e Add overlays mechanism to Nixpkgs.
This patch add a new argument to Nixpkgs default expression named "overlays".

By default, the value of the argument is either taken from the environment variable `NIXPKGS_OVERLAYS`,
or from the directory `~/.nixpkgs/overlays/`.  If the environment variable does not name a valid directory
then this mechanism would fallback on the home directory.  If the home directory does not exists it will
fallback on an empty list of overlays.

The overlays directory should contain the list of extra Nixpkgs stages which would be used to extend the
content of Nixpkgs, with additional set of packages.  The overlays, i-e directory, files, symbolic links
are used in alphabetical order.

The simplest overlay which extends Nixpkgs with nothing looks like:

```nix
self: super: {
}
```

More refined overlays can use `super` as the basis for building new packages, and `self` as a way to query
the final result of the fix-point.

An example of overlay which extends Nixpkgs with a small set of packages can be found at:
  https://github.com/nbp/nixpkgs-mozilla/blob/nixpkgs-overlay/moz-overlay.nix

To use this file, checkout the repository and add a symbolic link to
the `moz-overlay.nix` file in `~/.nixpkgs/overlays` directory.
2017-01-16 01:17:33 +01:00
John Ericson
3e197f7d81 top-level: Normalize stdenv booting
Introduce new abstraction, `stdenv/booter.nix` for composing bootstraping
stages, and use it everywhere for consistency. See that file for more doc.

Stdenvs besides Linux and Darwin are completely refactored to utilize this.
Those two, due to their size and complexity, are minimally edited for
easier reviewing.

No hashes should be changed.
2017-01-13 13:23:23 -05:00
Eric Litak
489ba1744c top-level: missing parentheses 2016-12-20 16:27:04 -08:00
John Ericson
19fbe80c3d top-level: avoid another assert false while we're at it 2016-12-15 17:09:46 -05:00
John Ericson
5c6234a7d3 top-level: Allow manually specifying a stdenv, and fix stdenv tests
- The darwin test can now force the use of the freshly-booted darwin stdenv
 - The linux test now passes enough dummy arguments

This may make debugging harder, if so, check out #20889
2016-12-03 17:21:07 -08:00
John Ericson
a55d1ecc90 top-level: Document why nixpkgsFun doesn't close over inferred default arguments 2016-12-01 11:24:33 -05:00
John Ericson
05c12f147e top-level: Move default-choosing logic to top-level/platforms.nix
This mirrors stdenv/default.nix
2016-12-01 11:24:32 -05:00
John Ericson
39753f5360 top-level: Close over fewer arguments for stdenv stages
This makes the flow of data easier to understand. There's little downside
because the args in question are already inspected by the stdenvs.

cross-compiling in particular is simpler because we don't need to worry
about overriding the config closed over by `allPackages`.
2016-11-30 19:11:03 -05:00