Skip to content
Merged
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
8 changes: 6 additions & 2 deletions configs/flake/caisson/partitions/checks.nix
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@
path = self.outPath + "/tests/integration/nixpkgs-pkg-sets";
};

nixpkgsLibOnlyOutputs = callConsumer {
path = self.outPath + "/tests/integration/nixpkgs-lib-only";
};

# A project that registers package overlays, and a consumer
# that takes them through `projects`.
pkgOverlaysProducerOutputs = callConsumer {
Expand Down Expand Up @@ -139,8 +143,7 @@
core = import ${inputs.caisson-core.outPath};
in
core.mkLib {
sources = { };
defaultEcosystemSrc.nixpkgs-lib = ${inputs.nixpkgs-lib.outPath};
sources.nixpkgs-lib = ${inputs.nixpkgs-lib.outPath};
modules = lib: lib.caisson-core.mkModules ${self.outPath}/modules;
libOverlays = lib: lib.caisson-core.mkLibOverlays ${self.outPath}/lib-overlays;
}
Expand All @@ -162,6 +165,7 @@
// nixpkgsOverlayExportOutputs.checks.${system}
// nixpkgsNoPkgSetsOutputs.checks.${system}
// nixpkgsPkgSetsOutputs.checks.${system}
// nixpkgsLibOnlyOutputs.checks.${system}
// pkgOverlaysProducerOutputs.checks.${system}
// pkgOverlaysConsumerOutputs.checks.${system}
// unitTestOutputs.checks.${system}
Expand Down
5 changes: 5 additions & 0 deletions examples/literate-flake/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@
# composition closes over, and the root from `self`.
inherit (caisson.lib.caisson.pins.flake inputs) sources root;

# The library the composition runs on: the `lib` of the
# nixpkgs input, selected under the `nixpkgs-lib` key since
# this flake names no separate nixpkgs.lib mirror.
defaultEcosystemSrc = sources: { nixpkgs-lib = sources.nixpkgs; };

# The project's name, which this flake holds and which is the
# namespace it contributes to the composed library: the `lib`
# flake output holds `lib.literate-flake` because of this
Expand Down
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions lib-overlays/flake-parts/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,13 @@
let
selection = lib.caisson.integrations;

flakeParts =
if (args.ecosystemSrc or null) == null then flakePartsDefault else flakePartsFor args.ecosystemSrc;
# The flake-parts source the configuration selects from the
# tree's sources, null when it selects none.
selected =
selection.selectedEcosystemSrc "lib.caisson.flake-parts.mkConfiguration"
(lib.caisson-core.libManifest or { })
(args.ecosystemSrc or null);
flakeParts = if selected == null then flakePartsDefault else flakePartsFor selected;

# The flake class of the registry, the same source every
# adapter selects from, so modules arriving by any channel
Expand Down
31 changes: 27 additions & 4 deletions lib-overlays/integrations/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,25 @@
inherit (final.caisson-core.strings) hasInfix;
inherit (final.caisson-core.functions) functionArgs setFunctionArgs;

# The source a configuration's `ecosystemSrc` selects: the
# argument is a function of the tree's pinned sources, as
# `defaultEcosystemSrc` on mkLib is, so a configuration chooses
# among the sources the tree pins. Null when the configuration
# passes none. `manifest` is the manifest whose `sources` it
# selects from, the lib manifest of the evaluation.
selectedEcosystemSrc =
context: manifest: explicit:
if explicit == null then
null
else if builtins.isFunction explicit then
explicit (manifest.sources or { })
else
throw ''
${context}: `ecosystemSrc` is a function of the tree's sources that
returns the source to use, `ecosystemSrc = sources: sources.<name>;`,
but got a ${builtins.typeOf explicit}.
'';

resolveEcosystemSrc =
{
# the integration's name for its ecosystem, e.g. "nixpkgs"
Expand All @@ -117,7 +136,8 @@
}:
let
resolved = final.caisson-core.resolve {
inherit name explicit;
inherit name;
explicit = selectedEcosystemSrc context manifest explicit;
defaults = manifest.defaultEcosystemSrc or { };
sources = manifest.sources or { };
};
Expand All @@ -126,9 +146,11 @@
resolved
else
throw ''
${context}: no ${name} ecosystem source. Pass `ecosystemSrc`
explicitly, declare `defaultEcosystemSrc.${name}` in the mkLib call,
or pin a source named `${name}` in the `sources` passed to mkLib.
${context}: no ${name} ecosystem source. Select one with
`ecosystemSrc = sources: sources.<name>;` on the configuration,
return a `${name}` from the `defaultEcosystemSrc` function of the
mkLib call, or pin a source named `${name}` in the `sources` passed
to mkLib.
'';

named =
Expand Down Expand Up @@ -1630,6 +1652,7 @@
publish
topValue
resolveEcosystemSrc
selectedEcosystemSrc
mkIntegration
mkAltIntegration
frameworkModules
Expand Down
7 changes: 6 additions & 1 deletion lib-overlays/nixos/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@
overlay =
final: prev:
let
# The source of the NixOS module collection: `nixos/modules` and
# `nixos/lib/eval-config.nix`, of the composition's `nixos` key.
# The library the modules run on is the composed lib, from the
# `nixpkgs-lib` key, and the package set is a package config,
# from the `nixpkgs` key: three parts, each from a separate key.
resolveEcosystemSrc = final.caisson.integrations.resolveEcosystemSrc {
name = "nixpkgs";
name = "nixos";
context = "caisson.nixos";
};

Expand Down
26 changes: 14 additions & 12 deletions lib-overlays/nixpkgs-lib/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
# merges that source's `lib` into the composed library, as the source
# fixes it.
#
# The source is the one the composition supplies for the ecosystem
# `nixpkgs-lib` (the library part declared separately: the nixpkgs.lib
# mirror, or nixpkgs' `lib` directory), else the one it supplies for
# the ecosystem `nixpkgs` (a nixpkgs checkout, one pin supplying every
# part). What a composition supplies for an ecosystem is its
# `defaultEcosystemSrc.<name>`, else the source it pins under that
# exact name.
# The source is the source the composition supplies for the part
# `nixpkgs-lib`: the nixpkgs.lib mirror, a tree holding nixpkgs' `lib`
# directory such as a nixpkgs checkout, or that directory. The library
# is a part of the nixpkgs stack separate from the package set and from
# the NixOS module collection, each supplied from a separate key, so a
# tree that takes the library from its nixpkgs checkout names that
# checkout under `nixpkgs-lib` as well. What a composition supplies for
# a part is its `defaultEcosystemSrc.<name>`, else the source it pins
# under that exact name.
#
# The source is read from `prev.caisson-core.ecosystemSrc`, which
# caisson-core publishes in the first layers of a library from the
Expand Down Expand Up @@ -52,15 +54,15 @@
# Null for every name in a library that caisson-core's entries
# are not part of.
supplied = (prev.caisson-core or { }).ecosystemSrc or (_name: null);
src = if supplied "nixpkgs-lib" != null then supplied "nixpkgs-lib" else supplied "nixpkgs";
src = supplied "nixpkgs-lib";
root =
if src == null then
builtins.throw ''
caisson: the `nixpkgs-lib` entry has no source. Declare
`defaultEcosystemSrc.nixpkgs-lib` (the nixpkgs.lib mirror, or nixpkgs'
`lib` directory) or `defaultEcosystemSrc.nixpkgs` (a nixpkgs checkout)
in the mkLib call, or pin a source named exactly `nixpkgs-lib` or
`nixpkgs` in the `sources` passed to mkLib.
`defaultEcosystemSrc.nixpkgs-lib` in the mkLib call (the nixpkgs.lib
mirror, or a nixpkgs checkout: `defaultEcosystemSrc.nixpkgs-lib =
inputs.nixpkgs;`), or pin a source named exactly `nixpkgs-lib` in the
`sources` passed to mkLib.
''
else
"${src}";
Expand Down
91 changes: 90 additions & 1 deletion lib-overlays/nixpkgs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,95 @@
final.filterAttrs (name: _: name == "default" || final.hasSuffix "/default" name) registry
);

# nixpkgs' library holds two kinds of library. The general
# utilities and the module system serve every evaluation, and the
# composition supplies them from the `nixpkgs-lib` key. The
# package-set libraries describe and build packages: the platform
# model, the package metadata and its tables, the `callPackage`
# machinery, the fetchers and version comparison. The packages of
# a set are written against the package-set libraries of the
# revision of the set, so a package set's lib takes them from the
# source of the set.
#
# `packageSetLibraries` are sublibraries whose functions nixpkgs
# also publishes at the top level of its library. `packageSetData`
# are tables taken whole. `generalLibraries` are the general
# sublibraries. A top-level name that belongs to a package-set
# library and to a general library stays with the general
# library: `compareVersions` is one, defined in `versions` and in
# `strings` as the same builtin.
packageSetLibraries = [
"systems"
"meta"
"customisation"
"derivations"
"fetchers"
"versions"
];
packageSetData = [
"licenses"
"sourceTypes"
"maintainers"
"teams"
"platforms"
];
generalLibraries = [
"trivial"
"fixedPoints"
"attrsets"
"lists"
"strings"
"stringsWithDeps"
"modules"
"options"
"types"
"cli"
"gvariant"
"generators"
"asserts"
"debug"
"services"
"path"
"filesystem"
"fileset"
"sources"
"kernel"
"network"
"flakes"
];

# The lib a package set at `src` runs on: `base`, the composed lib
# with the set's manifest, with the package-set libraries of the
# library at `src`. The top-level names taken are the
# package-set libraries, the tables, and every top-level name of
# the library at `src` that is also a function of a package-set
# library and of no general library, which is how nixpkgs
# publishes `callPackageWith`,
# `getExe` and the rest. Each value is the value at `src`, and a
# function taken from there runs on the fixpoint of the library at
# `src`. The lib is an attribute merge over `base`: nixpkgs hands
# it to the packages as `pkgs.lib` and builds no fixpoint over it.
packageSetLib =
src: base:
let
sourceLib = builtins.import "${src}/lib";
present = builtins.filter (name: sourceLib ? ${name});
libraries = present packageSetLibraries;
general = present generalLibraries;
memberOf = group: name: builtins.any (library: sourceLib.${library} ? ${name}) group;
reExports = builtins.filter (
name: !(builtins.elem name libraries) && memberOf libraries name && !(memberOf general name)
) (builtins.attrNames sourceLib);
names = libraries ++ present packageSetData ++ reExports;
in
base
// builtins.listToAttrs (
builtins.map (name: {
inherit name;
value = sourceLib.${name};
}) names
);

# The package set of nixpkgs at `src`, instantiated as
# `pkgs/top-level/default.nix` instantiates it, from arguments
# caisson has already resolved: `lib` is the composed lib the
Expand Down Expand Up @@ -288,7 +377,7 @@
};
pkgs = instantiate src (
{
lib = lib.caisson-core.withManifests { pkgsManifest = setManifest; };
lib = packageSetLib src (lib.caisson-core.withManifests { pkgsManifest = setManifest; });
localSystem = { inherit system; };
inherit config overlays;
}
Expand Down
7 changes: 4 additions & 3 deletions lib-overlays/system-manager/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@
context = "caisson.system-manager";
};

# The nixpkgs the evaluation runs on: the one the composition
# declares, as for a NixOS configuration.
# The source of the NixOS module collection the evaluation reads
# modules from: the composition's `nixos` key, as for a NixOS
# configuration.
resolveNixpkgsSrc = final.caisson.integrations.resolveEcosystemSrc {
name = "nixpkgs";
name = "nixos";
context = "caisson.system-manager";
};

Expand Down
11 changes: 7 additions & 4 deletions tests/activation-vm/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ let
pkgs = import inputs.nixpkgs { inherit system; };

lib = core.mkLib {
sources = { };
systems = [ system ];
projects.caisson = inputs.caisson;
defaultEcosystemSrc = {
sources = {
inherit (inputs)
nixpkgs
nvf
Expand All @@ -70,6 +67,12 @@ let
home-manager
;
};
systems = [ system ];
projects.caisson = inputs.caisson;
defaultEcosystemSrc = sources: {
nixpkgs-lib = sources.nixpkgs;
nixos = sources.nixpkgs;
};
pkgSets = _lib: {
default =
{ name, parent }:
Expand Down
8 changes: 4 additions & 4 deletions tests/darwin-system/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ let
pkgs = import inputs.nixpkgs { inherit system; };

lib = core.mkLib {
sources = { };
systems = [ system ];
projects.caisson = inputs.caisson;
defaultEcosystemSrc = {
sources = {
inherit (inputs)
nixpkgs
nix-darwin
Expand All @@ -35,6 +32,9 @@ let
nvf
;
};
systems = [ system ];
projects.caisson = inputs.caisson;
defaultEcosystemSrc = sources: { nixpkgs-lib = sources.nixpkgs; };
pkgSets = _lib: {
default =
{ name, parent }:
Expand Down
6 changes: 3 additions & 3 deletions tests/dependencies/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/drift-message/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ let
user = "probe";
directory = "/home/probe";
caisson.nvf.configurations.editor = lib.caisson.nvf.mkConfiguration {
ecosystemSrc = inputs.nvf;
ecosystemSrc = sources: sources.nvf;
configModule.vim.viAlias = true;
};
};
Expand Down
Loading
Loading