From 1441806c27f3775db580360e072ead2afbe00ae9 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Thu, 7 Dec 2017 20:30:45 +0100 Subject: [PATCH] nixpkgs: add nixos function --- nixos/doc/manual/release-notes/rl-1809.xml | 14 +++++++ pkgs/top-level/all-packages.nix | 46 ++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/nixos/doc/manual/release-notes/rl-1809.xml b/nixos/doc/manual/release-notes/rl-1809.xml index 61f9ec8ba995..29abea1afd6a 100644 --- a/nixos/doc/manual/release-notes/rl-1809.xml +++ b/nixos/doc/manual/release-notes/rl-1809.xml @@ -77,6 +77,20 @@ following incompatible changes: + The pkgs argument to NixOS modules can now be set directly using nixpkgs.pkgs. Previously, only the system, config and overlays arguments could be used to influence pkgs. + + + + + A NixOS system can now be constructed more easily based on a preexisting invocation of Nixpkgs. For example: + +inherit (pkgs.nixos { + boot.loader.grub.enable = false; + fileSystems."/".device = "/dev/xvda1"; +}) toplevel kernel initialRamdisk manual; + + + This benefits evaluation performance, lets you write Nixpkgs packages that depend on NixOS images and is consistent with a deployment architecture that would be centered around Nixpkgs overlays. diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 86500ece4610..1a4fa144708e 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -20690,6 +20690,52 @@ with pkgs; nixops-dns = callPackage ../tools/package-management/nixops/nixops-dns.nix { }; + /* + * Evaluate a NixOS configuration using this evaluation of Nixpkgs. + * + * With this function you can write, for example, a package that + * depends on a custom virtual machine image. + * + * Parameter: A module, path or list of those that represent the + * configuration of the NixOS system to be constructed. + * + * Result: An attribute set containing packages produced by this + * evaluation of NixOS, such as toplevel, kernel and + * initialRamdisk. + * The result can be extended in the modules by defining + * extra options in system.build. + * + * Unlike in plain NixOS, the nixpkgs.config, nixpkgs.overlays and + * nixpkgs.system options will be ignored by default. Instead, + * nixpkgs.pkgs will have the default value of pkgs as it was + * constructed right after invoking the nixpkgs function (e.g. the + * value of import { overlays = [./my-overlay.nix]; } + * but not the value of (import {} // { extra = ...; }). + * + * If you do want to use the config.nixpkgs options, you are + * probably better off by calling nixos/lib/eval-config.nix + * directly, even though it is possible to set config.nixpkgs.pkgs. + * + * For more information about writing NixOS modules, see + * https://nixos.org/nixos/manual/index.html#sec-writing-modules + * + * Note that you will need to have called Nixpkgs with the system + * parameter set to the right value for your deployment target. + */ + nixos = configuration: + (import (self.path + "/nixos/lib/eval-config.nix") { + inherit (pkgs) system; + modules = [( + { lib, ... }: { + config.nixpkgs.pkgs = lib.mkDefault pkgs; + } + )] ++ ( + if builtins.isList configuration + then configuration + else [configuration] + ); + }).config.system.build; + nixui = callPackage ../tools/package-management/nixui { node_webkit = nwjs_0_12; }; nix-bundle = callPackage ../tools/package-management/nix-bundle { };