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 } // lib.optionalAttrs
85 self.legacyPackages.${system}.stdenv.hostPlatform.isLinux
86 # Exclude power64 due to "libressl is not available on the requested hostPlatform" with hostPlatform being power64
87 && !self.legacyPackages.${system}.targetPlatform.isPower64
88 # Exclude armv6l-linux due to "cannot bootstrap GHC on this platform ('armv6l-linux' with libc 'defaultLibc')"
89 && system != "armv6l-linux"
90 # Exclude riscv64-linux due to "cannot bootstrap GHC on this platform ('riscv64-linux' with libc 'defaultLibc')"
91 && system != "riscv64-linux"
94 # Test that ensures that the nixosSystem function can accept a lib argument
95 # Note: prefer not to extend or modify `lib`, especially if you want to share reusable modules
96 # alternatives include: `import` a file, or put a custom library in an option or in `_module.args.<libname>`
97 nixosSystemAcceptsLib = (self.lib.nixosSystem {
98 pkgs = self.legacyPackages.${system};
99 lib = self.lib.extend (final: prev: {
100 ifThisFunctionIsMissingTheTestFails = final.id;
103 ./nixos/modules/profiles/minimal.nix
104 ({ lib, ... }: lib.ifThisFunctionIsMissingTheTestFails {
105 # Define a minimal config without eval warnings
106 nixpkgs.hostPlatform = "x86_64-linux";
107 boot.loader.grub.enable = false;
108 fileSystems."/".device = "nodev";
109 # See https://search.nixos.org/options?show=system.stateVersion&query=stateversion
110 system.stateVersion = lib.trivial.release; # DON'T do this in real configs!
113 }).config.system.build.toplevel;
117 nixpkgsManual = builtins.mapAttrs (_: jobSet: jobSet.manual) jobs;
118 nixosManual = (import ./nixos/release-small.nix {
123 devShells = forAllSystems (system:
124 { } // lib.optionalAttrs
126 # 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"
127 system != "armv6l-linux"
128 # Exclude riscv64-linux because "Package ‘ghc-9.6.6’ in .../pkgs/development/compilers/ghc/common-hadrian.nix:579 is not available on the requested hostPlatform"
129 && system != "riscv64-linux"
130 # Exclude FreeBSD because "Package ‘ghc-9.6.6’ in .../pkgs/development/compilers/ghc/common-hadrian.nix:579 is not available on the requested hostPlatform"
131 && !self.legacyPackages.${system}.stdenv.hostPlatform.isFreeBSD
134 /** A shell to get tooling for Nixpkgs development. See nixpkgs/shell.nix. */
135 default = import ./shell.nix { inherit system; };
139 A nested structure of [packages](https://nix.dev/manual/nix/latest/glossary#package-attribute-set) and other values.
141 The "legacy" in `legacyPackages` doesn't imply that the packages exposed
142 through this attribute are "legacy" packages. Instead, `legacyPackages`
143 is used here as a substitute attribute name for `packages`. The problem
144 with `packages` is that it makes operations like `nix flake show
145 nixpkgs` unusably slow due to the sheer number of packages the Nix CLI
146 needs to evaluate. But when the Nix CLI sees a `legacyPackages`
147 attribute it displays `omitted` instead of evaluating all packages,
148 which keeps `nix flake show` on Nixpkgs reasonably fast, though less
151 The reason why finding the tree structure of `legacyPackages` is slow,
152 is that for each attribute in the tree, it is necessary to check whether
153 the attribute value is a package or a package set that needs further
154 evaluation. Evaluating the attribute value tends to require a significant
155 amount of computation, even considering lazy evaluation.
157 legacyPackages = forAllSystems (system:
158 (import ./. { inherit system; }).extend (final: prev: {
159 lib = prev.lib.extend libVersionInfoOverlay;
164 Optional modules that can be imported into a NixOS configuration.
169 outputs = { nixpkgs, ... }: {
170 nixosConfigurations = {
171 foo = nixpkgs.lib.nixosSystem {
173 ./foo/configuration.nix
174 nixpkgs.nixosModules.notDetected
181 notDetected = ./nixos/modules/installer/scan/not-detected.nix;
184 Make the `nixpkgs.*` configuration read-only. Guarantees that `pkgs`
185 is the way you initialize it.
190 imports = [ nixpkgs.nixosModules.readOnlyPkgs ];
191 nixpkgs.pkgs = nixpkgs.legacyPackages.x86_64-linux;
194 readOnlyPkgs = ./nixos/modules/misc/nixpkgs/read-only.nix;