at 24.11-pre 4.4 kB view raw
1# Experimental flake interface to Nixpkgs. 2# See https://github.com/NixOS/rfcs/pull/49 for details. 3{ 4 description = "A collection of packages for the Nix package manager"; 5 6 outputs = { self }: 7 let 8 jobs = import ./pkgs/top-level/release.nix { 9 nixpkgs = self; 10 }; 11 12 libVersionInfoOverlay = import ./lib/flake-version-info.nix self; 13 lib = (import ./lib).extend libVersionInfoOverlay; 14 15 forAllSystems = lib.genAttrs lib.systems.flakeExposed; 16 in 17 { 18 lib = lib.extend (final: prev: { 19 20 nixos = import ./nixos/lib { lib = final; }; 21 22 nixosSystem = args: 23 import ./nixos/lib/eval-config.nix ( 24 { 25 lib = final; 26 # Allow system to be set modularly in nixpkgs.system. 27 # We set it to null, to remove the "legacy" entrypoint's 28 # non-hermetic default. 29 system = null; 30 31 modules = args.modules ++ [ 32 # This module is injected here since it exposes the nixpkgs self-path in as 33 # constrained of contexts as possible to avoid more things depending on it and 34 # introducing unnecessary potential fragility to changes in flakes itself. 35 # 36 # See: failed attempt to make pkgs.path not copy when using flakes: 37 # https://github.com/NixOS/nixpkgs/pull/153594#issuecomment-1023287913 38 ({ config, pkgs, lib, ... }: { 39 config.nixpkgs.flake.source = self.outPath; 40 }) 41 ]; 42 } // builtins.removeAttrs args [ "modules" ] 43 ); 44 }); 45 46 checks.x86_64-linux = { 47 tarball = jobs.tarball; 48 # Test that ensures that the nixosSystem function can accept a lib argument 49 # Note: prefer not to extend or modify `lib`, especially if you want to share reusable modules 50 # alternatives include: `import` a file, or put a custom library in an option or in `_module.args.<libname>` 51 nixosSystemAcceptsLib = (self.lib.nixosSystem { 52 lib = self.lib.extend (final: prev: { 53 ifThisFunctionIsMissingTheTestFails = final.id; 54 }); 55 modules = [ 56 ./nixos/modules/profiles/minimal.nix 57 ({ lib, ... }: lib.ifThisFunctionIsMissingTheTestFails { 58 # Define a minimal config without eval warnings 59 nixpkgs.hostPlatform = "x86_64-linux"; 60 boot.loader.grub.enable = false; 61 fileSystems."/".device = "nodev"; 62 # See https://search.nixos.org/options?show=system.stateVersion&query=stateversion 63 system.stateVersion = lib.versions.majorMinor lib.version; # DON'T do this in real configs! 64 }) 65 ]; 66 }).config.system.build.toplevel; 67 }; 68 69 htmlDocs = { 70 nixpkgsManual = jobs.manual; 71 nixosManual = (import ./nixos/release-small.nix { 72 nixpkgs = self; 73 }).nixos.manual.x86_64-linux; 74 }; 75 76 # The "legacy" in `legacyPackages` doesn't imply that the packages exposed 77 # through this attribute are "legacy" packages. Instead, `legacyPackages` 78 # is used here as a substitute attribute name for `packages`. The problem 79 # with `packages` is that it makes operations like `nix flake show 80 # nixpkgs` unusably slow due to the sheer number of packages the Nix CLI 81 # needs to evaluate. But when the Nix CLI sees a `legacyPackages` 82 # attribute it displays `omitted` instead of evaluating all packages, 83 # which keeps `nix flake show` on Nixpkgs reasonably fast, though less 84 # information rich. 85 legacyPackages = forAllSystems (system: 86 (import ./. { inherit system; }).extend (final: prev: { 87 lib = prev.lib.extend libVersionInfoOverlay; 88 }) 89 ); 90 91 nixosModules = { 92 notDetected = ./nixos/modules/installer/scan/not-detected.nix; 93 94 /* 95 Make the `nixpkgs.*` configuration read-only. Guarantees that `pkgs` 96 is the way you initialize it. 97 98 Example: 99 100 { 101 imports = [ nixpkgs.nixosModules.readOnlyPkgs ]; 102 nixpkgs.pkgs = nixpkgs.legacyPackages.x86_64-linux; 103 } 104 */ 105 readOnlyPkgs = ./nixos/modules/misc/nixpkgs/read-only.nix; 106 }; 107 }; 108}