Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

nixosSystem = args:
import ./nixos/lib/eval-config.nix (
args // {
{ lib = final; } // args // {
modules = args.modules ++ [{
system.nixos.versionSuffix =
".${final.substring 0 8 (self.lastModifiedDate or self.lastModified or "19700101")}.${self.shortRev or "dirty"}";
Expand Down
9 changes: 6 additions & 3 deletions lib/fixed-points.nix
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ rec {
# Same as `makeExtensible` but the name of the extending attribute is
# customized.
makeExtensibleWithCustomName = extenderName: rattrs:
fix' rattrs // {
${extenderName} = f: makeExtensibleWithCustomName extenderName (extends f rattrs);
};
let
self = rattrs self // {
${extenderName} = f: makeExtensibleWithCustomName extenderName (extends f rattrs);
__unfix__ = rattrs; # TODO: remove this?
};
in self;
}
26 changes: 23 additions & 3 deletions nixos/modules/misc/nixpkgs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,11 @@ let
};
in
import ../../.. ({
inherit (cfg) config overlays;
inherit (cfg) lib config overlays;
} // systemArgs)
else
import ../../.. {
inherit (cfg) config overlays localSystem crossSystem;
inherit (cfg) lib config overlays localSystem crossSystem;
};

finalPkgs = if opt.pkgs.isDefined then cfg.pkgs.appendOverlays cfg.overlays else defaultPkgs;
Expand All @@ -117,7 +117,7 @@ in
pkgs = mkOption {
defaultText = literalExpression ''
import "''${nixos}/.." {
inherit (cfg) config overlays localSystem crossSystem;
inherit (cfg) lib config overlays localSystem crossSystem;
}
'';
type = pkgsType;
Expand Down Expand Up @@ -155,6 +155,26 @@ in
'';
};

lib = mkOption {
default = lib;
defaultText = literalMD "the `lib` argument passed to modules";
example = literalExpression ''
lib.extend (final: prev: {
# Make lib.foo available in package expressions
foo = "bar";
})
'';
type = types.unique
{ message = "`lib` is not suitable for plain attrset merging, as it does not interact well with the `extend` function. Any fixes to `lib` should be applied by invoking `extend` on some original `lib` value."; }
(types.lazyAttrsOf types.raw);
description = lib.mdDoc ''
The library used in nixpkgs. You shouldn't need to set this
unless you know what you're doing.

Ignored when `nixpkgs.pkgs` is set.
'';
};

config = mkOption {
default = {};
example = literalExpression
Expand Down
4 changes: 2 additions & 2 deletions pkgs/stdenv/darwin/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ rec {
'' + mkExtraBuildCommands cc;
});

thisStdenv = import ../generic {
thisStdenv = import ../generic lib {
name = "${name}-stdenv-darwin";

inherit config shell extraBuildInputs;
Expand Down Expand Up @@ -665,7 +665,7 @@ rec {
inherit binutils binutils-unwrapped;
};
in
import ../generic rec {
import ../generic lib rec {
name = "stdenv-darwin";

inherit config;
Expand Down
6 changes: 3 additions & 3 deletions pkgs/stdenv/freebsd/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ in
curl = bootstrapTools;
};

stdenv = import ../generic {
stdenv = import ../generic lib {
name = "stdenv-freebsd-boot-1";
buildPlatform = localSystem;
hostPlatform = localSystem;
Expand All @@ -220,7 +220,7 @@ in

inherit (prevStage) bootstrapTools;

stdenv = import ../generic {
stdenv = import ../generic lib {
name = "stdenv-freebsd-boot-0";
inherit config;
initialPath = [ prevStage.bootstrapTools ];
Expand All @@ -234,7 +234,7 @@ in

(prevStage: {
inherit config overlays;
stdenv = import ../generic rec {
stdenv = import ../generic lib rec {
name = "stdenv-freebsd-boot-3";
inherit config;

Expand Down
4 changes: 3 additions & 1 deletion pkgs/stdenv/generic/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
let lib = import ../../../lib; stdenv-overridable = lib.makeOverridable (
lib:

let stdenv-overridable = lib.makeOverridable (

argsStdenv@{ name ? "stdenv", preHook ? "", initialPath

Expand Down
4 changes: 2 additions & 2 deletions pkgs/stdenv/linux/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ let

let

thisStdenv = import ../generic {
thisStdenv = import ../generic lib {
name = "${name}-stdenv-linux";
buildPlatform = localSystem;
hostPlatform = localSystem;
Expand Down Expand Up @@ -390,7 +390,7 @@ in
# binutils built.
(prevStage: {
inherit config overlays;
stdenv = import ../generic rec {
stdenv = import ../generic lib rec {
name = "stdenv-linux";

buildPlatform = localSystem;
Expand Down
2 changes: 1 addition & 1 deletion pkgs/stdenv/native/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ let
makeStdenv =
{ cc, fetchurl, extraPath ? [], overrides ? (self: super: { }), extraNativeBuildInputs ? [] }:

import ../generic {
import ../generic lib {
buildPlatform = localSystem;
hostPlatform = localSystem;
targetPlatform = localSystem;
Expand Down
2 changes: 1 addition & 1 deletion pkgs/stdenv/nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ bootStages ++ [
(prevStage: {
inherit config overlays;

stdenv = import ../generic rec {
stdenv = import ../generic lib rec {
inherit config;

inherit (prevStage.stdenv) buildPlatform hostPlatform targetPlatform;
Expand Down
7 changes: 4 additions & 3 deletions pkgs/top-level/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
evaluation is taking place, and the configuration from environment variables
or dot-files. */

{ # The system packages will be built on. See the manual for the
{ # The library to be used across pkgs.
lib ? import ../../lib

, # The system packages will be built on. See the manual for the
# subtle division of labor between these two `*System`s and the three
# `*Platform`s.
localSystem
Expand Down Expand Up @@ -47,8 +50,6 @@ let # Rename the function arguments
crossSystem0 = crossSystem;

in let
lib = import ../../lib;

inherit (lib) throwIfNot;

checked =
Expand Down