1 # Experimental flake interface to Nixpkgs.
2 # See https://github.com/NixOS/rfcs/pull/49 for details.
4 description = "A collection of packages for the Nix package manager";
8 libVersionInfoOverlay = import ./lib/flake-version-info.nix self;
9 lib = (import ./lib).extend libVersionInfoOverlay;
11 forAllSystems = lib.genAttrs lib.systems.flakeExposed;
13 jobs = forAllSystems (system: import ./pkgs/top-level/release.nix {
20 `nixpkgs.lib` is a combination of the [Nixpkgs library](https://nixos.org/manual/nixpkgs/unstable/#id-1.4), and other attributes
21 that are _not_ part of the Nixpkgs library, but part of the Nixpkgs flake:
23 - `lib.nixosSystem` for creating a NixOS system configuration
25 - `lib.nixos` for other NixOS-provided functionality, such as [`runTest`](https://nixos.org/manual/nixos/unstable/#sec-call-nixos-test-outside-nixos)
27 lib = lib.extend (final: prev: {
30 Other NixOS-provided functionality, such as [`runTest`](https://nixos.org/manual/nixos/unstable/#sec-call-nixos-test-outside-nixos).
31 See also `lib.nixosSystem`.
33 nixos = import ./nixos/lib { lib = final; };
36 Create a NixOS system configuration.
41 modules = [ ./configuration.nix ];
46 - `modules` (list of paths or inline modules): The NixOS modules to include in the system configuration.
48 - `specialArgs` (attribute set): Extra arguments to pass to all modules, that are available in `imports` but can not be extended or overridden by the `modules`.
50 - `modulesLocation` (path): A default location for modules that aren't passed by path, used for error messages.
54 - `system`: Legacy alias for `nixpkgs.hostPlatform`, but this is already set in the generated `hardware-configuration.nix`, included by `configuration.nix`.
55 - `pkgs`: Legacy alias for `nixpkgs.pkgs`; use `nixpkgs.pkgs` and `nixosModules.readOnlyPkgs` instead.
58 import ./nixos/lib/eval-config.nix (
61 # Allow system to be set modularly in nixpkgs.system.
62 # We set it to null, to remove the "legacy" entrypoint's
63 # non-hermetic default.
66 modules = args.modules ++ [
67 # This module is injected here since it exposes the nixpkgs self-path in as
68 # constrained of contexts as possible to avoid more things depending on it and
69 # introducing unnecessary potential fragility to changes in flakes itself.
71 # See: failed attempt to make pkgs.path not copy when using flakes:
72 # https://github.com/NixOS/nixpkgs/pull/153594#issuecomment-1023287913
73 ({ config, pkgs, lib, ... }: {
74 config.nixpkgs.flake.source = self.outPath;
77 } // builtins.removeAttrs args [ "modules" ]
81 checks = forAllSystems (system: {
82 tarball = jobs.${system}.tarball;
83 # Exclude power64 due to "libressl is not available on the requested hostPlatform" with hostPlatform being power64
84 } // lib.optionalAttrs (self.legacyPackages.${system}.stdenv.hostPlatform.isLinux && !self.legacyPackages.${system}.targetPlatform.isPower64) {
85 # Test that ensures that the nixosSystem function can accept a lib argument
86 # Note: prefer not to extend or modify `lib`, especially if you want to share reusable modules
87 # alternatives include: `import` a file, or put a custom library in an option or in `_module.args.<libname>`
88 nixosSystemAcceptsLib = (self.lib.nixosSystem {
89 pkgs = self.legacyPackages.${system};
90 lib = self.lib.extend (final: prev: {
91 ifThisFunctionIsMissingTheTestFails = final.id;
94 ./nixos/modules/profiles/minimal.nix
95 ({ lib, ... }: lib.ifThisFunctionIsMissingTheTestFails {
96 # Define a minimal config without eval warnings
97 nixpkgs.hostPlatform = "x86_64-linux";
98 boot.loader.grub.enable = false;
99 fileSystems."/".device = "nodev";
100 # See https://search.nixos.org/options?show=system.stateVersion&query=stateversion
101 system.stateVersion = lib.trivial.release; # DON'T do this in real configs!
104 }).config.system.build.toplevel;
108 nixpkgsManual = builtins.mapAttrs (_: jobSet: jobSet.manual) jobs;
109 nixosManual = (import ./nixos/release-small.nix {
114 devShells = forAllSystems (system: {
115 /** A shell to get tooling for Nixpkgs development. See nixpkgs/shell.nix. */
116 default = import ./shell.nix { inherit system; };
120 A nested structure of [packages](https://nix.dev/manual/nix/latest/glossary#package-attribute-set) and other values.
122 The "legacy" in `legacyPackages` doesn't imply that the packages exposed
123 through this attribute are "legacy" packages. Instead, `legacyPackages`
124 is used here as a substitute attribute name for `packages`. The problem
125 with `packages` is that it makes operations like `nix flake show
126 nixpkgs` unusably slow due to the sheer number of packages the Nix CLI
127 needs to evaluate. But when the Nix CLI sees a `legacyPackages`
128 attribute it displays `omitted` instead of evaluating all packages,
129 which keeps `nix flake show` on Nixpkgs reasonably fast, though less
132 The reason why finding the tree structure of `legacyPackages` is slow,
133 is that for each attribute in the tree, it is necessary to check whether
134 the attribute value is a package or a package set that needs further
135 evaluation. Evaluating the attribute value tends to require a significant
136 amount of computation, even considering lazy evaluation.
138 legacyPackages = forAllSystems (system:
139 (import ./. { inherit system; }).extend (final: prev: {
140 lib = prev.lib.extend libVersionInfoOverlay;
145 Optional modules that can be imported into a NixOS configuration.
150 outputs = { nixpkgs, ... }: {
151 nixosConfigurations = {
152 foo = nixpkgs.lib.nixosSystem {
154 ./foo/configuration.nix
155 nixpkgs.nixosModules.notDetected
162 notDetected = ./nixos/modules/installer/scan/not-detected.nix;
165 Make the `nixpkgs.*` configuration read-only. Guarantees that `pkgs`
166 is the way you initialize it.
171 imports = [ nixpkgs.nixosModules.readOnlyPkgs ];
172 nixpkgs.pkgs = nixpkgs.legacyPackages.x86_64-linux;
175 readOnlyPkgs = ./nixos/modules/misc/nixpkgs/read-only.nix;