diff --git a/configs/flake/caisson/partitions/checks.nix b/configs/flake/caisson/partitions/checks.nix index b42450ad..f731c2d1 100644 --- a/configs/flake/caisson/partitions/checks.nix +++ b/configs/flake/caisson/partitions/checks.nix @@ -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 { @@ -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; } @@ -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} diff --git a/examples/literate-flake/flake.nix b/examples/literate-flake/flake.nix index a9e657f9..db50f3e1 100644 --- a/examples/literate-flake/flake.nix +++ b/examples/literate-flake/flake.nix @@ -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 diff --git a/flake.lock b/flake.lock index d4c181ed..7166251d 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "caisson-core": { "locked": { - "lastModified": 1792556427, - "narHash": "sha256-9XWV/rnEM90spykkF7cDcqXsyrvwB4MO6wa8gTEi+Ig=", + "lastModified": 1792651257, + "narHash": "sha256-5SMkHLn3uyGkzCl6/VAxLoZ08fRlq9lrhD0JbuO8eUI=", "owner": "nix-caisson", "repo": "caisson-core", - "rev": "502690fce026a3c009f254e38b47e7e95527ca4a", + "rev": "9e1bdf63c237d6559bd4291688ae992a9933f67e", "type": "github" }, "original": { diff --git a/lib-overlays/flake-parts/default.nix b/lib-overlays/flake-parts/default.nix index 990d408e..f598742d 100644 --- a/lib-overlays/flake-parts/default.nix +++ b/lib-overlays/flake-parts/default.nix @@ -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 diff --git a/lib-overlays/integrations/default.nix b/lib-overlays/integrations/default.nix index ddc32090..f5274b8c 100644 --- a/lib-overlays/integrations/default.nix +++ b/lib-overlays/integrations/default.nix @@ -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.;`, + but got a ${builtins.typeOf explicit}. + ''; + resolveEcosystemSrc = { # the integration's name for its ecosystem, e.g. "nixpkgs" @@ -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 { }; }; @@ -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.;` 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 = @@ -1630,6 +1652,7 @@ publish topValue resolveEcosystemSrc + selectedEcosystemSrc mkIntegration mkAltIntegration frameworkModules diff --git a/lib-overlays/nixos/default.nix b/lib-overlays/nixos/default.nix index 464d3812..c9bbf3dd 100644 --- a/lib-overlays/nixos/default.nix +++ b/lib-overlays/nixos/default.nix @@ -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"; }; diff --git a/lib-overlays/nixpkgs-lib/default.nix b/lib-overlays/nixpkgs-lib/default.nix index cadff9f5..611f3230 100644 --- a/lib-overlays/nixpkgs-lib/default.nix +++ b/lib-overlays/nixpkgs-lib/default.nix @@ -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.`, 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.`, 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 @@ -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}"; diff --git a/lib-overlays/nixpkgs/default.nix b/lib-overlays/nixpkgs/default.nix index f4c45bee..30bc2d84 100644 --- a/lib-overlays/nixpkgs/default.nix +++ b/lib-overlays/nixpkgs/default.nix @@ -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 @@ -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; } diff --git a/lib-overlays/system-manager/default.nix b/lib-overlays/system-manager/default.nix index 3dee39ae..98354c9a 100644 --- a/lib-overlays/system-manager/default.nix +++ b/lib-overlays/system-manager/default.nix @@ -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"; }; diff --git a/tests/activation-vm/default.nix b/tests/activation-vm/default.nix index 8d01f92e..293a4b4f 100644 --- a/tests/activation-vm/default.nix +++ b/tests/activation-vm/default.nix @@ -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 @@ -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 }: diff --git a/tests/darwin-system/default.nix b/tests/darwin-system/default.nix index 06ece0a9..d6a2e960 100644 --- a/tests/darwin-system/default.nix +++ b/tests/darwin-system/default.nix @@ -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 @@ -35,6 +32,9 @@ let nvf ; }; + systems = [ system ]; + projects.caisson = inputs.caisson; + defaultEcosystemSrc = sources: { nixpkgs-lib = sources.nixpkgs; }; pkgSets = _lib: { default = { name, parent }: diff --git a/tests/dependencies/flake.lock b/tests/dependencies/flake.lock index 16dd7590..961af29a 100644 --- a/tests/dependencies/flake.lock +++ b/tests/dependencies/flake.lock @@ -2,11 +2,11 @@ "nodes": { "caisson-core": { "locked": { - "lastModified": 1792556427, - "narHash": "sha256-9XWV/rnEM90spykkF7cDcqXsyrvwB4MO6wa8gTEi+Ig=", + "lastModified": 1792651257, + "narHash": "sha256-5SMkHLn3uyGkzCl6/VAxLoZ08fRlq9lrhD0JbuO8eUI=", "owner": "nix-caisson", "repo": "caisson-core", - "rev": "502690fce026a3c009f254e38b47e7e95527ca4a", + "rev": "9e1bdf63c237d6559bd4291688ae992a9933f67e", "type": "github" }, "original": { diff --git a/tests/drift-message/default.nix b/tests/drift-message/default.nix index 9b9ec8d6..31726749 100644 --- a/tests/drift-message/default.nix +++ b/tests/drift-message/default.nix @@ -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; }; }; diff --git a/tests/hjem-system/default.nix b/tests/hjem-system/default.nix index fb5adcfb..aef57aa0 100644 --- a/tests/hjem-system/default.nix +++ b/tests/hjem-system/default.nix @@ -6,8 +6,10 @@ # tree itself. # # The composition is for x86_64-linux, with a package config whose set -# there is nixpkgs, and with nixpkgs and hjem declared as its -# ecosystems. `user` is a hjem module with a file and a package. +# there is nixpkgs, and with nixpkgs, hjem, the library and the NixOS +# module collection declared as its ecosystems, the library and the +# module collection from the same nixpkgs pin. `user` is a hjem module +# with a file and a package. # `standalone` is a hjem configuration that is a top, for the user # `probe` with the home directory it sets itself. `top` is a structural # top holding a NixOS machine `probe-machine`, which declares the @@ -22,11 +24,19 @@ let pkgs = import inputs.nixpkgs { inherit system; }; lib = core.mkLib { - sources = { }; + sources = { + inherit (inputs) + nixpkgs + hjem + nvf + home-manager + ; + }; systems = [ system ]; projects.caisson = inputs.caisson; - defaultEcosystemSrc = { - inherit (inputs) nixpkgs hjem; + defaultEcosystemSrc = sources: { + nixpkgs-lib = sources.nixpkgs; + nixos = sources.nixpkgs; }; pkgSets = _lib: { default = diff --git a/tests/integration/basic-composition/flake.nix b/tests/integration/basic-composition/flake.nix index ec5b5942..b5aa2d88 100644 --- a/tests/integration/basic-composition/flake.nix +++ b/tests/integration/basic-composition/flake.nix @@ -29,6 +29,7 @@ # namespaces of the composed library (`caisson`, `caisson-core`). lib = parent.lib.caisson.mkLib { inherit (parent.lib.caisson.pins.flake inputs) sources root; + defaultEcosystemSrc = sources: { nixpkgs-lib = sources.nixpkgs; }; projects = { caisson = parent; }; diff --git a/tests/integration/lib-consumer-chain/final-consumer/flake.nix b/tests/integration/lib-consumer-chain/final-consumer/flake.nix index 9c58763c..943e9452 100644 --- a/tests/integration/lib-consumer-chain/final-consumer/flake.nix +++ b/tests/integration/lib-consumer-chain/final-consumer/flake.nix @@ -21,6 +21,7 @@ let lib = parent.lib.caisson.mkLib { inherit (parent.lib.caisson.pins.flake inputs) sources root; + defaultEcosystemSrc = sources: { nixpkgs-lib = sources.nixpkgs; }; name = "final-consumer"; projects = { caisson = parent; diff --git a/tests/integration/lib-consumer-chain/middle-flake/flake.nix b/tests/integration/lib-consumer-chain/middle-flake/flake.nix index 78894032..83c9c623 100644 --- a/tests/integration/lib-consumer-chain/middle-flake/flake.nix +++ b/tests/integration/lib-consumer-chain/middle-flake/flake.nix @@ -16,6 +16,7 @@ let lib = parent.lib.caisson.mkLib { inherit (parent.lib.caisson.pins.flake inputs) sources root; + defaultEcosystemSrc = sources: { nixpkgs-lib = sources.nixpkgs; }; # The name this flake holds, deliberately not the directory # name: the final consumer lists this flake in `projects` under diff --git a/tests/integration/minimal-consumer/flake.nix b/tests/integration/minimal-consumer/flake.nix index fb681bca..2c2ee5eb 100644 --- a/tests/integration/minimal-consumer/flake.nix +++ b/tests/integration/minimal-consumer/flake.nix @@ -24,6 +24,7 @@ # registers one lib overlay and no modules. lib = parent.lib.caisson.mkLib { inherit (parent.lib.caisson.pins.flake inputs) sources root; + defaultEcosystemSrc = sources: { nixpkgs-lib = sources.nixpkgs; }; projects = { caisson = parent; diff --git a/tests/integration/module-class-export/flake.nix b/tests/integration/module-class-export/flake.nix index 4cd7173d..c62b00cf 100644 --- a/tests/integration/module-class-export/flake.nix +++ b/tests/integration/module-class-export/flake.nix @@ -16,6 +16,7 @@ let lib = parent.lib.caisson.mkLib { inherit (parent.lib.caisson.pins.flake inputs) sources root; + defaultEcosystemSrc = sources: { nixpkgs-lib = sources.nixpkgs; }; projects = { caisson = parent; diff --git a/tests/integration/nixpkgs-consumer/flake.nix b/tests/integration/nixpkgs-consumer/flake.nix index aa89e864..465aa91e 100644 --- a/tests/integration/nixpkgs-consumer/flake.nix +++ b/tests/integration/nixpkgs-consumer/flake.nix @@ -25,6 +25,7 @@ # `pkgs.nixpkgs-consumer` because of this declaration. name = "nixpkgs-consumer"; systems = [ "x86_64-linux" ]; + defaultEcosystemSrc = sources: { nixpkgs-lib = sources.nixpkgs; }; projects = { caisson = parent; }; diff --git a/tests/integration/nixpkgs-lib-only/configs/flake/nixpkgs-lib-only/default.nix b/tests/integration/nixpkgs-lib-only/configs/flake/nixpkgs-lib-only/default.nix new file mode 100644 index 00000000..a52ad32e --- /dev/null +++ b/tests/integration/nixpkgs-lib-only/configs/flake/nixpkgs-lib-only/default.nix @@ -0,0 +1,51 @@ +# SPDX-License-Identifier: MIT +# +# Builds a package set on a library whose source holds only nixpkgs' +# `lib` directory. nixpkgs checks the maintainers of every derivation +# it creates, so the set evaluates only if its lib carries the +# `maintainers` and `teams` of the package set's source. The checks +# read where each function of the set's lib is defined: the +# package-set libraries and their top-level names come from the +# package set's source, and the general utilities from the library of +# the composition. +{ ... }: +{ + inputs, + lib, + ... +}: +{ + systems = [ "x86_64-linux" ]; + + perSystem = + { system, ... }: + let + pkgs = lib.caisson.nixpkgs.pkgSets.default.children.nixpkgs.${system}.value; + upstream = import inputs.nixpkgs { inherit system; }; + fileOf = name: set: (builtins.unsafeGetAttrPos name set).file; + # Whether the attribute `name` of `set` is defined in the library + # of the package set's source. + fromSet = name: set: lib.hasPrefix "${inputs.nixpkgs}/lib/" (fileOf name set); + marked = "marked by the composition"; + in + { + checks.nixpkgs-lib-only = + assert pkgs.hello.drvPath == upstream.hello.drvPath; + assert pkgs.lib.maintainers == upstream.lib.maintainers; + assert builtins.attrNames pkgs.lib.teams == builtins.attrNames upstream.lib.teams; + assert pkgs.lib.licenses == upstream.lib.licenses; + assert pkgs.lib.platforms == upstream.lib.platforms; + assert fromSet "getExe" pkgs.lib.meta; + assert fromSet "callPackageWith" pkgs.lib.customisation; + assert fromSet "elaborate" pkgs.lib.systems; + assert !(fromSet "splitString" pkgs.lib.strings); + assert !(fromSet "evalModules" pkgs.lib.modules); + # The test's lib overlay marks `getExe` and `splitString` in the + # composed lib. The package set's lib takes `getExe` from the + # package set's source and keeps the general `splitString`. + assert lib.getExe pkgs.hello == marked; + assert pkgs.lib.getExe pkgs.hello == upstream.lib.getExe upstream.hello; + assert pkgs.lib.splitString "," "a,b" == [ marked ]; + pkgs.runCommand "nixpkgs-lib-only" { } "touch $out"; + }; +} diff --git a/tests/integration/nixpkgs-lib-only/flake.nix b/tests/integration/nixpkgs-lib-only/flake.nix new file mode 100644 index 00000000..6b6d592a --- /dev/null +++ b/tests/integration/nixpkgs-lib-only/flake.nix @@ -0,0 +1,41 @@ +# SPDX-License-Identifier: MIT +{ + description = "Integration test: a package set built on a library source that holds only nixpkgs' lib directory"; + + inputs = { + deps.url = "path:../../dependencies"; + + parent.url = "path:../../.."; + + nixpkgs.follows = "deps/nixpkgs"; + flake-parts.follows = "deps/flake-parts"; + }; + + outputs = + inputs@{ parent, ... }: + let + core = parent.lib.caisson; + lib = core.mkLib { + inherit (core.pins.flake inputs) sources root; + name = "nixpkgs-lib-only"; + systems = [ "x86_64-linux" ]; + projects = { + caisson = parent; + }; + # The library comes from a copy of the `lib` directory alone, + # laid out as the nixpkgs.lib mirror is. The package set comes + # from the full checkout, pinned as `nixpkgs`. + defaultEcosystemSrc = sources: { + nixpkgs-lib = builtins.path { + path = "${sources.nixpkgs}/lib"; + name = "nixpkgs-lib-only"; + }; + }; + libOverlays = lib: lib.caisson.mkLibOverlays ./lib-overlays; + pkgSets = lib: { default = lib.caisson.nixpkgs.mkConfiguration { }; }; + }; + in + lib.caisson.flake-parts.mkTopConfiguration { + configModule = lib.caisson.flake-parts.mkModule ./configs/flake/nixpkgs-lib-only; + }; +} diff --git a/tests/integration/nixpkgs-lib-only/lib-overlays/default/default.nix b/tests/integration/nixpkgs-lib-only/lib-overlays/default/default.nix new file mode 100644 index 00000000..c744a6db --- /dev/null +++ b/tests/integration/nixpkgs-lib-only/lib-overlays/default/default.nix @@ -0,0 +1,12 @@ +# SPDX-License-Identifier: MIT +# +# Marks two functions of the composed lib: `getExe`, of the package-set +# library `meta`, and `splitString`, a general utility. The checks read +# which of the two a package set's lib still carries. +{ ... }: +{ + overlay = _final: _prev: { + getExe = _: "marked by the composition"; + splitString = _: _: [ "marked by the composition" ]; + }; +} diff --git a/tests/integration/nixpkgs-no-pkg-sets/flake.nix b/tests/integration/nixpkgs-no-pkg-sets/flake.nix index 1099e97d..fe58208f 100644 --- a/tests/integration/nixpkgs-no-pkg-sets/flake.nix +++ b/tests/integration/nixpkgs-no-pkg-sets/flake.nix @@ -21,6 +21,7 @@ let lib = parent.lib.caisson.mkLib { inherit (parent.lib.caisson.pins.flake inputs) sources root; + defaultEcosystemSrc = sources: { nixpkgs-lib = sources.nixpkgs; }; projects = { caisson = parent; }; diff --git a/tests/integration/nixpkgs-overlay-export/flake.nix b/tests/integration/nixpkgs-overlay-export/flake.nix index 0dc791f0..2019b21a 100644 --- a/tests/integration/nixpkgs-overlay-export/flake.nix +++ b/tests/integration/nixpkgs-overlay-export/flake.nix @@ -23,6 +23,7 @@ inherit (parent.lib.caisson.pins.flake inputs) sources root; name = "nixpkgs-overlay-export"; systems = [ "x86_64-linux" ]; + defaultEcosystemSrc = sources: { nixpkgs-lib = sources.nixpkgs; }; projects = { caisson = parent; }; diff --git a/tests/integration/nixpkgs-pkg-sets/flake.nix b/tests/integration/nixpkgs-pkg-sets/flake.nix index 8538b05b..0d213fc5 100644 --- a/tests/integration/nixpkgs-pkg-sets/flake.nix +++ b/tests/integration/nixpkgs-pkg-sets/flake.nix @@ -22,9 +22,7 @@ projects = { caisson = parent; }; - defaultEcosystemSrc = { - inherit (inputs) nixpkgs; - }; + defaultEcosystemSrc = sources: { nixpkgs-lib = sources.nixpkgs; }; modules = lib: lib.caisson.mkModules ./modules; pkgOverlays = lib: lib.caisson.mkPkgOverlays ./pkg-overlays; # The package configs: `default` takes the default selections, diff --git a/tests/integration/pkg-overlays-registry/consumer/flake.nix b/tests/integration/pkg-overlays-registry/consumer/flake.nix index bc911f82..b1d06cdf 100644 --- a/tests/integration/pkg-overlays-registry/consumer/flake.nix +++ b/tests/integration/pkg-overlays-registry/consumer/flake.nix @@ -20,6 +20,7 @@ inherit (core.pins.flake inputs) sources root; name = "consumer"; systems = [ "x86_64-linux" ]; + defaultEcosystemSrc = sources: { nixpkgs-lib = sources.nixpkgs; }; projects = { caisson = parent; inherit producer; diff --git a/tests/integration/pkg-overlays-registry/producer/flake.nix b/tests/integration/pkg-overlays-registry/producer/flake.nix index a4f8a0cf..348d16ef 100644 --- a/tests/integration/pkg-overlays-registry/producer/flake.nix +++ b/tests/integration/pkg-overlays-registry/producer/flake.nix @@ -19,6 +19,7 @@ inherit (core.pins.flake inputs) sources root; name = "producer"; systems = [ "x86_64-linux" ]; + defaultEcosystemSrc = sources: { nixpkgs-lib = sources.nixpkgs; }; projects = { caisson = parent; }; diff --git a/tests/pinned-world/default.nix b/tests/pinned-world/default.nix index aa5538ab..55c75f8c 100644 --- a/tests/pinned-world/default.nix +++ b/tests/pinned-world/default.nix @@ -38,8 +38,7 @@ let # last occurrence of a key supplies its value. registered = (core.mkLib { - sources = { }; - defaultEcosystemSrc.nixpkgs-lib = inputs.nixpkgs-lib; + sources = { inherit (inputs) nixpkgs-lib; }; projects.caisson = inputs.caisson; }).caisson-core.libManifest.libOverlays; @@ -202,23 +201,38 @@ let # The colmena and disko probes compose with declared ecosystems: a # node resolves the colmena source, a layout resolves the disko - # source, and nixpkgs resolves from the declaration, as it does in a - # consumer flake. + # source, and the package set, the library and the NixOS module + # collection resolve from the declaration, as they do in a consumer + # flake. The library and the NixOS module collection are the same + # nixpkgs pin as the package set. hiveLib = core.mkLib ( declaresPkgs // { - sources = { }; - projects = { - caisson = inputs.caisson; - }; - defaultEcosystemSrc = { + sources = { inherit (inputs) nixpkgs colmena flake-parts disko + home-manager + nvf + treefmt-nix + nixvim + nix-topology + kubenix + nixidy + system-manager + hjem + terranix ; }; + projects = { + caisson = inputs.caisson; + }; + defaultEcosystemSrc = sources: { + nixpkgs-lib = sources.nixpkgs; + nixos = sources.nixpkgs; + }; } ); @@ -379,14 +393,14 @@ let { lib, ... }: { caisson.nixos.configurations.probe = lib.caisson.nixos.mkConfiguration { - ecosystemSrc = inputs.nixpkgs; + ecosystemSrc = sources: sources.nixpkgs; configModule = { lib, ... }: let home = module: lib.caisson.home-manager.mkConfiguration { - ecosystemSrc = inputs.home-manager; + ecosystemSrc = sources: sources.home-manager; configModule = { imports = [ module ]; home.stateVersion = "25.05"; @@ -419,7 +433,7 @@ let # of the evaluation hands the library out through an option. nixosEvaluationLib = (hiveLib.caisson.nixos.mkTopConfiguration { - ecosystemSrc = inputs.nixpkgs; + ecosystemSrc = sources: sources.nixpkgs; configModule = { lib, ... }: { @@ -614,7 +628,7 @@ let minimalNixosSystemEvaluates = let system = hiveLib.caisson.nixos-minimal.mkTopConfiguration { - ecosystemSrc = inputs.nixpkgs; + ecosystemSrc = sources: sources.nixpkgs; # The minimal evaluator carries no nixpkgs module, so the # package set arrives as the `pkgs` module argument. configModule = @@ -638,20 +652,20 @@ let { lib, ... }: { caisson.caisson-colmena.configurations.default = lib.caisson.caisson-colmena.mkConfiguration { - ecosystemSrc = { }; + ecosystemSrc = sources: { }; }; }; }).colmenaHive && throws (hiveLib.caisson.terranix.mkTopConfiguration { - ecosystemSrc = { }; + ecosystemSrc = sources: { }; configModule = { }; }).drvPath && throws (hiveLib.caisson.system-manager.mkTopConfiguration { - ecosystemSrc = { }; + ecosystemSrc = sources: { }; configModule = { }; }).drvPath; @@ -662,7 +676,7 @@ let # home-manager CLI reads it: the evaluated home-manager # configuration. home = hiveLib.caisson.home-manager.mkTopConfiguration { - ecosystemSrc = inputs.home-manager; + ecosystemSrc = sources: sources.home-manager; configModule = { ... }: { @@ -883,7 +897,7 @@ let machine = lib: lib.caisson.nixos.mkConfiguration { - ecosystemSrc = inputs.nixpkgs; + ecosystemSrc = sources: sources.nixpkgs; configModule = minimalNixosBase; }; top = hiveLib.caisson.structural.mkTopConfiguration { @@ -1009,7 +1023,7 @@ let aMachineInsideAParentIsTheSameMachine = let machine = { - ecosystemSrc = inputs.nixpkgs; + ecosystemSrc = sources: sources.nixpkgs; configModule = { imports = [ minimalNixosBase ]; networking.hostName = "probe"; @@ -1046,7 +1060,7 @@ let { lib, ... }: { caisson.nixos.configurations.probe = lib.caisson.nixos.mkConfiguration { - ecosystemSrc = inputs.nixpkgs; + ecosystemSrc = sources: sources.nixpkgs; configModule = minimalNixosBase; }; }; @@ -1093,7 +1107,7 @@ let aHomeInsideAParentIsTheSameHome = let home = { - ecosystemSrc = inputs.home-manager; + ecosystemSrc = sources: sources.home-manager; configModule = { home.username = "probe"; home.homeDirectory = "/home/probe"; @@ -1117,7 +1131,7 @@ let { lib, ... }: { caisson.nixos.configurations.host = lib.caisson.nixos.mkConfiguration { - ecosystemSrc = inputs.nixpkgs; + ecosystemSrc = sources: sources.nixpkgs; configModule = { lib, ... }: { @@ -1219,7 +1233,7 @@ let top = colmenaTop { probe = hostModule; }; node = top.colmenaHive.nodes.probe; system = hiveLib.caisson.nixos.mkTopConfiguration { - ecosystemSrc = inputs.nixpkgs; + ecosystemSrc = sources: sources.nixpkgs; configModule = hostModule; }; in @@ -1292,11 +1306,12 @@ let "aarch64-linux" ]; twoSystemsLib = core.mkLib { - sources = { }; + sources = { inherit (inputs) nixpkgs colmena; }; inherit systems; projects.caisson = inputs.caisson; - defaultEcosystemSrc = { - inherit (inputs) nixpkgs colmena; + defaultEcosystemSrc = sources: { + nixpkgs-lib = sources.nixpkgs; + nixos = sources.nixpkgs; }; pkgSets = _lib: { default = @@ -1366,7 +1381,7 @@ let { lib, ... }: { caisson.caisson-colmena.configurations.default = lib.caisson.caisson-colmena.mkConfiguration { - inherit ecosystemSrc; + ecosystemSrc = _sources: ecosystemSrc; configModule = { lib, ... }: { @@ -2177,7 +2192,7 @@ let nvfConfiguration = lib: module: lib.caisson.nvf.mkConfiguration { - ecosystemSrc = inputs.nvf; + ecosystemSrc = sources: sources.nvf; configModule = module; }; top = probe.lib.caisson.structural.mkTopConfiguration { @@ -2269,7 +2284,7 @@ let { lib, ... }: { caisson.nvf.configurations.editor = lib.caisson.nvf.mkConfiguration { - ecosystemSrc = inputs.nvf; + ecosystemSrc = sources: sources.nvf; configModule.vim.viAlias = true; }; }; @@ -2511,11 +2526,11 @@ let { lib, ... }: { caisson.treefmt.configurations.default = lib.caisson.treefmt.mkConfiguration { - ecosystemSrc = inputs.treefmt-nix; + ecosystemSrc = sources: sources.treefmt-nix; configModule = module; }; caisson.treefmt.configurations.docs = lib.caisson.treefmt.mkConfiguration { - ecosystemSrc = inputs.treefmt-nix; + ecosystemSrc = sources: sources.treefmt-nix; configModule = { projectRootFile = "book.toml"; programs.nixfmt.enable = true; @@ -2532,12 +2547,10 @@ let rootedLib = core.mkLib ( declaresPkgs // { - sources = { }; + sources = { inherit (inputs) nixpkgs treefmt-nix; }; inherit root; projects.caisson = inputs.caisson; - defaultEcosystemSrc = { - inherit (inputs) nixpkgs; - }; + defaultEcosystemSrc = sources: { nixpkgs-lib = sources.nixpkgs; }; } ); rooted = rootedLib.caisson.structural.mkTopConfiguration { @@ -2579,7 +2592,7 @@ let nvfConfiguration = lib: lib.caisson.nvf.mkConfiguration { - ecosystemSrc = inputs.nvf; + ecosystemSrc = sources: sources.nvf; configModule = module; }; top = hiveLib.caisson.structural.mkTopConfiguration { @@ -2602,7 +2615,7 @@ let }; }; caisson.home-manager.configurations.alice = lib.caisson.home-manager.mkConfiguration { - ecosystemSrc = inputs.home-manager; + ecosystemSrc = sources: sources.home-manager; configModule = { lib, ... }: { @@ -2671,7 +2684,7 @@ let { lib, ... }: { caisson.nixvim.configurations.editor = lib.caisson.nixvim.mkConfiguration { - ecosystemSrc = inputs.nixvim; + ecosystemSrc = sources: sources.nixvim; configModule = module; }; }; @@ -2710,7 +2723,7 @@ let { imports = [ minimalNixosBase ]; caisson.nixvim.configurations.machine-editor = lib.caisson.nixvim.mkConfiguration { - ecosystemSrc = inputs.nixvim; + ecosystemSrc = sources: sources.nixvim; configModule = module; }; }; @@ -2762,7 +2775,7 @@ let { lib, ... }: { caisson.topology.configurations.default = lib.caisson.topology.mkConfiguration { - ecosystemSrc = inputs.nix-topology; + ecosystemSrc = sources: sources.nix-topology; configModule = { lib, ... }: { @@ -2825,7 +2838,7 @@ let { lib, ... }: { caisson.kubenix.configurations.cluster = lib.caisson.kubenix.mkConfiguration { - ecosystemSrc = inputs.kubenix; + ecosystemSrc = sources: sources.kubenix; configModule = module; }; }; @@ -2855,7 +2868,7 @@ let { lib, ... }: { caisson.nixidy.configurations.prod = lib.caisson.nixidy.mkConfiguration { - ecosystemSrc = inputs.nixidy; + ecosystemSrc = sources: sources.nixidy; configModule = module; }; }; @@ -2883,7 +2896,7 @@ let editor = lib: lib.caisson.nvf.mkConfiguration { - ecosystemSrc = inputs.nvf; + ecosystemSrc = sources: sources.nvf; configModule.vim.viAlias = true; }; withEditor = @@ -2912,7 +2925,7 @@ let bob = lib.caisson.hjem.mkConfiguration { configModule = withEditor "bob-editor"; }; }; caisson.home-manager.configurations.carol = lib.caisson.home-manager.mkConfiguration { - ecosystemSrc = inputs.home-manager; + ecosystemSrc = sources: sources.home-manager; configModule = { imports = [ (withEditor "carol-editor") ]; home.stateVersion = "25.05"; @@ -2950,7 +2963,7 @@ let { lib, ... }: { caisson.system-manager.configurations.box = lib.caisson.system-manager.mkConfiguration { - ecosystemSrc = inputs.system-manager; + ecosystemSrc = sources: sources.system-manager; configModule = { lib, ... }: { @@ -2963,24 +2976,24 @@ let home = "/home/probe"; }; caisson.home-manager.configurations.probe = lib.caisson.home-manager.mkConfiguration { - ecosystemSrc = inputs.home-manager; + ecosystemSrc = sources: sources.home-manager; configModule.home.stateVersion = "25.05"; }; caisson.hjem.configurations.probe = lib.caisson.hjem.mkConfiguration { - ecosystemSrc = inputs.hjem; + ecosystemSrc = sources: sources.hjem; configModule = { lib, pkgs, ... }: { files.".config/probe/greeting".text = "hello"; packages = [ pkgs.hello ]; caisson.nvf.configurations.hjem-editor = lib.caisson.nvf.mkConfiguration { - ecosystemSrc = inputs.nvf; + ecosystemSrc = sources: sources.nvf; configModule.vim.vimAlias = true; }; }; }; caisson.nvf.configurations.editor = lib.caisson.nvf.mkConfiguration { - ecosystemSrc = inputs.nvf; + ecosystemSrc = sources: sources.nvf; configModule.vim.viAlias = true; }; }; @@ -3040,7 +3053,7 @@ let config.output.composed.value = lib ? caisson-core; }; terraform = hiveLib.caisson.terranix.mkTopConfiguration { - ecosystemSrc = inputs.terranix; + ecosystemSrc = sources: sources.terranix; configModule = module; }; published = hiveLib.caisson.structural.mkTopConfiguration { @@ -3049,7 +3062,7 @@ let { lib, ... }: { caisson.terranix.configurations.infra = lib.caisson.terranix.mkConfiguration { - ecosystemSrc = inputs.terranix; + ecosystemSrc = sources: sources.terranix; configModule = module; }; }; @@ -3078,11 +3091,11 @@ let config.environment.etc.composed.text = builtins.toJSON (lib ? caisson-core); }; system = hiveLib.caisson.system-manager.mkTopConfiguration { - ecosystemSrc = inputs.system-manager; + ecosystemSrc = sources: sources.system-manager; configModule = module; }; withOverlay = hiveLib.caisson.system-manager.mkTopConfiguration { - ecosystemSrc = inputs.system-manager; + ecosystemSrc = sources: sources.system-manager; configModule = { imports = [ module ]; nixpkgs.overlays = [ (_final: _prev: { }) ]; @@ -3097,7 +3110,7 @@ let { lib, ... }: { caisson.system-manager.configurations.default = lib.caisson.system-manager.mkConfiguration { - ecosystemSrc = inputs.system-manager; + ecosystemSrc = sources: sources.system-manager; configModule = module; }; }; @@ -3128,7 +3141,7 @@ let hiveLib.caisson.integrations.topValue ( hiveLib.caisson-core.finalizeTop ( hiveLib.caisson.nixos-minimal.mkConfigurationWithEcosystemArgs { - ecosystemSrc = inputs.nixpkgs; + ecosystemSrc = sources: sources.nixpkgs; configModule = { lib, ... }: { @@ -3143,7 +3156,7 @@ let terraform = hiveLib.caisson.integrations.topValue ( hiveLib.caisson-core.finalizeTop ( hiveLib.caisson.terranix.mkConfigurationWithEcosystemArgs { - ecosystemSrc = inputs.terranix; + ecosystemSrc = sources: sources.terranix; configModule = { config.terraform.required_version = ">= 1.0"; }; @@ -3154,7 +3167,7 @@ let home = hiveLib.caisson.integrations.topValue ( hiveLib.caisson-core.finalizeTop ( hiveLib.caisson.home-manager.mkConfigurationWithEcosystemArgs { - ecosystemSrc = inputs.home-manager; + ecosystemSrc = sources: sources.home-manager; configModule = { home.username = "probe"; home.homeDirectory = "/home/probe"; @@ -3174,8 +3187,7 @@ let registeringLib = core.mkLib ( declaresPkgs // { - sources = { }; - defaultEcosystemSrc.nixpkgs-lib = inputs.nixpkgs-lib; + sources = { inherit (inputs) nixpkgs-lib nixpkgs; }; projects.caisson = inputs.caisson; modules = lib: { nixos.pinned-world-probe = lib.caisson-core.mkModule "nixos" ( @@ -3192,7 +3204,7 @@ let } ); system = registeringLib.caisson.nixos-minimal.mkTopConfiguration { - ecosystemSrc = inputs.nixpkgs; + ecosystemSrc = sources: sources.nixpkgs; configModule = { lib, ... }: { @@ -3208,8 +3220,7 @@ let manifestTravelsWithMkLibCompositions = let composedWithMkLib = core.mkLib { - sources = { }; - defaultEcosystemSrc.nixpkgs-lib = inputs.nixpkgs-lib; + sources = { inherit (inputs) nixpkgs-lib; }; projects.caisson = inputs.caisson; }; manifest = composedWithMkLib.caisson-core.libManifest; @@ -3255,9 +3266,7 @@ let systemsDeclaredOnMkLibReachFlakeParts = let composedWithSystems = core.mkLib { - sources = { }; - defaultEcosystemSrc.nixpkgs-lib = inputs.nixpkgs-lib; - defaultEcosystemSrc.flake-parts = inputs.flake-parts; + sources = { inherit (inputs) nixpkgs-lib flake-parts; }; systems = [ "x86_64-linux" "aarch64-linux" @@ -3285,15 +3294,14 @@ let composedFromProject = core.mkLib ( declaresPkgs // { - sources = { }; - defaultEcosystemSrc.nixpkgs-lib = inputs.nixpkgs-lib; + sources = { inherit (inputs) nixpkgs-lib nixpkgs; }; projects = { caisson = inputs.caisson; }; } ); system = composedFromProject.caisson.nixos-minimal.mkTopConfiguration { - ecosystemSrc = inputs.nixpkgs; + ecosystemSrc = sources: sources.nixpkgs; configModule = { pkgs, lib, ... }: { @@ -3306,13 +3314,24 @@ let && composedFromProject.caisson-core.libManifest.modules.flake ? "caisson/default" && system.config.probe; + # A tree's declared ecosystem sources reach the nixos-minimal + # adapter with no `ecosystemSrc` passed to its configuration: the + # package set from `nixpkgs`, the library from `nixpkgs-lib` and + # the NixOS module collection from `nixos`, each key declared + # separately, all three pointing at the same nixpkgs pin. declaredEcosystemServesAdapters = let composedWithDeclaration = core.mkLib ( declaresPkgs // { - sources = { }; - defaultEcosystemSrc.nixpkgs = inputs.nixpkgs; + sources = { + pinned-nixpkgs = inputs.nixpkgs; + }; + defaultEcosystemSrc = sources: { + nixpkgs = sources.pinned-nixpkgs; + nixpkgs-lib = sources.pinned-nixpkgs; + nixos = sources.pinned-nixpkgs; + }; projects.caisson = inputs.caisson; } ); @@ -3353,9 +3372,7 @@ let structuralTopMatchesFlakeParts = let composedWithBoth = core.mkLib { - sources = { }; - defaultEcosystemSrc.nixpkgs-lib = inputs.nixpkgs-lib; - defaultEcosystemSrc.flake-parts = inputs.flake-parts; + sources = { inherit (inputs) nixpkgs-lib flake-parts; }; systems = [ "x86_64-linux" ]; projects.caisson = inputs.caisson; }; diff --git a/tests/system-manager/sequence.nix b/tests/system-manager/sequence.nix index dec15dc2..444dc8fc 100644 --- a/tests/system-manager/sequence.nix +++ b/tests/system-manager/sequence.nix @@ -34,10 +34,7 @@ let pkgs = import inputs.nixpkgs { inherit system; }; lib = core.mkLib { - sources = { }; - systems = [ system ]; - projects.caisson = inputs.caisson; - defaultEcosystemSrc = { + sources = { inherit (inputs) nixpkgs system-manager @@ -46,6 +43,12 @@ let nvf ; }; + systems = [ system ]; + projects.caisson = inputs.caisson; + defaultEcosystemSrc = sources: { + nixpkgs-lib = sources.nixpkgs; + nixos = sources.nixpkgs; + }; pkgSets = _lib: { default = { name, parent }: diff --git a/tests/unit/flake.nix b/tests/unit/flake.nix index 27faa244..4f2d1061 100644 --- a/tests/unit/flake.nix +++ b/tests/unit/flake.nix @@ -48,7 +48,6 @@ pins = import (parent.outPath + "/lib-overlays/framework/pins"); lib = core.mkLib { inherit (pins.flake inputs) sources root; - defaultEcosystemSrc.nixpkgs-lib = inputs.nixpkgs-lib.outPath; # Registered from the parent's source path: a flake cannot # reference files outside its tree, and reading the # source forces none of the parent's outputs. The overlays diff --git a/tests/unit/lib-overlays.nix b/tests/unit/lib-overlays.nix index 1ad1be71..3cecd164 100644 --- a/tests/unit/lib-overlays.nix +++ b/tests/unit/lib-overlays.nix @@ -1752,7 +1752,7 @@ in "test: a declared ecosystem resolves for an adapter" = { expr = let - myLib = mkResolutionLib { defaultEcosystemSrc.terranix = terranixStub "declared"; }; + myLib = mkResolutionLib { defaultEcosystemSrc = sources: { terranix = terranixStub "declared"; }; }; in (myLib.caisson.terranix.mkTopConfiguration { configModule = { }; @@ -1763,15 +1763,33 @@ in "test: an explicit ecosystemSrc beats the declaration" = { expr = let - myLib = mkResolutionLib { defaultEcosystemSrc.terranix = terranixStub "declared"; }; + myLib = mkResolutionLib { defaultEcosystemSrc = sources: { terranix = terranixStub "declared"; }; }; in (myLib.caisson.terranix.mkTopConfiguration { - ecosystemSrc = terranixStub "explicit"; + ecosystemSrc = sources: terranixStub "explicit"; configModule = { }; }).stubbed; expected = "explicit"; }; + # `ecosystemSrc` selects from the tree's sources, so a + # configuration gives it as a function; a value is refused before + # resolution runs. + "test: an ecosystemSrc given as a value is refused" = { + expr = + let + myLib = mkResolutionLib { }; + in + (myLib.caisson.terranix.mkTopConfiguration { + ecosystemSrc = terranixStub "explicit"; + configModule = { }; + }).stubbed; + expectedError = { + type = "ThrownError"; + msg = "caisson\\.terranix: `ecosystemSrc` is a function of the tree's sources that\\s+returns the source to use, `ecosystemSrc = sources: sources\\.;`,\\s+but got a set\\."; + }; + }; + "test: an input with the exact name is the last channel" = { expr = let @@ -1794,7 +1812,7 @@ in sources = mockSources // { terranix = terranixStub "input"; }; - defaultEcosystemSrc.terranix = terranixStub "declared"; + defaultEcosystemSrc = sources: { terranix = terranixStub "declared"; }; }; in (myLib.caisson.terranix.mkTopConfiguration { @@ -1818,7 +1836,7 @@ in "test: declarations join the manifest" = { expr = let - myLib = mkResolutionLib { defaultEcosystemSrc.terranix = terranixStub "declared"; }; + myLib = mkResolutionLib { defaultEcosystemSrc = sources: { terranix = terranixStub "declared"; }; }; in (myLib.caisson-core.libManifest.defaultEcosystemSrc.terranix.lib.terranixConfiguration { }).stubbed; expected = "declared"; @@ -1838,11 +1856,20 @@ in nixosLib = let nixosStub = ./nixos-stub; + # mockSources with the nixos stub added, under a name a + # composition's `defaultEcosystemSrc` selects. + sourcesWithNixos = mockSources // { + inherit nixosStub; + }; + nixosEcosystemSrc = sources: { + nixpkgs = sources.nixosStub; + nixos = sources.nixosStub; + }; mkComposition = extraOverlays: caisson.mkLib { - sources = mockSources; - defaultEcosystemSrc.nixpkgs = nixosStub; + sources = sourcesWithNixos; + defaultEcosystemSrc = nixosEcosystemSrc; # A configuration takes its system and its package set from # the composition. systems = [ "x86_64-linux" ]; @@ -1879,9 +1906,9 @@ in # `machine`, which records the name and the system its evaluation # carries. publishingLib = caisson.mkLib { - sources = mockSources; + sources = sourcesWithNixos; name = "publishing"; - defaultEcosystemSrc.nixpkgs = nixosStub; + defaultEcosystemSrc = nixosEcosystemSrc; systems = [ "x86_64-linux" ]; pkgSets = stubPkgSets { default = { }; }; libOverlays = _lib: { @@ -2205,9 +2232,9 @@ in expr = let noDefault = caisson.mkLib { - sources = mockSources; + sources = sourcesWithNixos; name = "no-default"; - defaultEcosystemSrc.nixpkgs = nixosStub; + defaultEcosystemSrc = nixosEcosystemSrc; systems = [ "x86_64-linux" ]; pkgSets = stubPkgSets { stable = { }; }; libOverlays = _lib: { @@ -2269,9 +2296,9 @@ in on = systems: caisson.mkLib { - sources = mockSources; + sources = sourcesWithNixos; name = "machine"; - defaultEcosystemSrc.nixpkgs = nixosStub; + defaultEcosystemSrc = nixosEcosystemSrc; inherit systems; libOverlays = _lib: { nixos = mkLibOverlay (inputs.parent.outPath + "/lib-overlays/nixos"); @@ -2362,9 +2389,9 @@ in expr = let minimalLib = caisson.mkLib { - sources = mockSources; + sources = sourcesWithNixos; name = "publishing"; - defaultEcosystemSrc.nixpkgs = nixosStub; + defaultEcosystemSrc = nixosEcosystemSrc; systems = [ "x86_64-linux" ]; pkgSets = stubPkgSets { default = { }; }; libOverlays = _lib: { @@ -2474,9 +2501,9 @@ in }; }; everyLib = caisson.mkLib { - sources = mockSources; + sources = sourcesWithNixos; name = "publishing"; - defaultEcosystemSrc.nixpkgs = nixosStub; + defaultEcosystemSrc = nixosEcosystemSrc; systems = [ "x86_64-linux" ]; pkgSets = stubPkgSets { default = { }; }; libOverlays = _lib: { @@ -2580,9 +2607,9 @@ in # The modules are registered in the composition. A # configuration selects from that registry. registeringModulesLib = caisson.mkLib { - sources = mockSources; + sources = sourcesWithNixos; name = "registering-modules"; - defaultEcosystemSrc.nixpkgs = nixosStub; + defaultEcosystemSrc = nixosEcosystemSrc; systems = [ "x86_64-linux" ]; pkgSets = stubPkgSets { default = { }; }; libOverlays = _lib: { @@ -2879,9 +2906,9 @@ in expr = let severalLib = caisson.mkLib { - sources = mockSources; + sources = sourcesWithNixos; name = "several"; - defaultEcosystemSrc.nixpkgs = nixosStub; + defaultEcosystemSrc = nixosEcosystemSrc; systems = [ "x86_64-linux" "aarch64-linux" @@ -2924,9 +2951,9 @@ in expr = let oneSystemLib = caisson.mkLib { - sources = mockSources; + sources = sourcesWithNixos; name = "one-system"; - defaultEcosystemSrc.nixpkgs = nixosStub; + defaultEcosystemSrc = nixosEcosystemSrc; systems = [ "x86_64-linux" ]; libOverlays = _lib: { nixos = mkLibOverlay (inputs.parent.outPath + "/lib-overlays/nixos"); @@ -3108,7 +3135,9 @@ in caisson.mkLib ( homeComposition // { - sources = mockSources; + sources = mockSources // { + inherit hmStub hmStubCopy; + }; libOverlays = _lib: { @@ -3129,7 +3158,9 @@ in } // declaration ); - mkComposition = mkCompositionWith { defaultEcosystemSrc.home-manager = hmStub; }; + mkComposition = mkCompositionWith { + defaultEcosystemSrc = sources: { home-manager = sources.hmStub; }; + }; myLib = mkComposition { }; # A composition that declares no home-manager: no # `defaultEcosystemSrc.home-manager`, and no input of that name. @@ -3151,7 +3182,9 @@ in caisson.mkLib ( homeComposition // { - sources = mockSources; + sources = mockSources // { + inherit hmStub; + }; libOverlays = _lib: { home-manager = { imports = [ @@ -3198,11 +3231,15 @@ in treeLibWith = systems: caisson.mkLib { - sources = mockSources; + sources = mockSources // { + nixosStub = ./nixos-stub; + inherit hmStub; + }; name = "homes"; - defaultEcosystemSrc = { - nixpkgs = ./nixos-stub; - home-manager = hmStub; + defaultEcosystemSrc = sources: { + nixpkgs = sources.nixosStub; + nixos = sources.nixosStub; + home-manager = sources.hmStub; }; inherit systems; pkgSets = @@ -3343,7 +3380,8 @@ in "test: lib.maintainers carries both lists" = { expr = builtins.attrNames - (mkMaintainersComposition { defaultEcosystemSrc.home-manager = hmStub; }).maintainers; + (mkMaintainersComposition { defaultEcosystemSrc = sources: { home-manager = sources.hmStub; }; }) + .maintainers; expected = [ "a-nixpkgs-maintainer" "home-manager-stub-maintainer" @@ -3363,7 +3401,7 @@ in "test: an evaluation naming its home-manager merges its maintainers" = { expr = ((mkMaintainersComposition { }).caisson.home-manager.mkTopConfiguration { - ecosystemSrc = hmStub; + ecosystemSrc = sources: sources.hmStub; configModule = { lib, ... }: { @@ -3484,7 +3522,7 @@ in "test: an evaluation naming the declared tree runs on the composed library" = { expr = (myLib.caisson.home-manager.mkTopConfiguration { - ecosystemSrc = hmStub; + ecosystemSrc = sources: sources.hmStub; configModule = probeModule; check = false; }).config.seenLib; @@ -3505,7 +3543,7 @@ in expr = builtins.deepSeq (myLib.caisson.home-manager.mkTopConfiguration { - ecosystemSrc = hmStubCopy; + ecosystemSrc = sources: sources.hmStubCopy; configModule = probeModule; check = false; }).config.seenLib @@ -3524,7 +3562,7 @@ in "test: an evaluation names its home-manager when the composition declares none" = { expr = (undeclaredLib.caisson.home-manager.mkTopConfiguration { - ecosystemSrc = hmStub; + ecosystemSrc = sources: sources.hmStub; configModule = probeModule; check = false; }).config.seenLib; @@ -3544,7 +3582,7 @@ in expr = let evaluated = undeclaredLib.caisson.home-manager.mkTopConfiguration { - ecosystemSrc = hmStub; + ecosystemSrc = sources: sources.hmStub; configModule = { config, lib, ... }: { @@ -3606,7 +3644,7 @@ in in { declared = seenUnder myLib { }; - named = seenUnder undeclaredLib { ecosystemSrc = hmStub; }; + named = seenUnder undeclaredLib { ecosystemSrc = sources: sources.hmStub; }; }; expected = { declared = { @@ -5490,7 +5528,7 @@ in { lib, ... }: { caisson.caisson-colmena.configurations.default = lib.caisson.caisson-colmena.mkConfiguration { - ecosystemSrc = colmenaStub; + ecosystemSrc = _sources: colmenaStub; configModule.meta.description = "probe"; }; }; @@ -5540,8 +5578,10 @@ in mkCompositionWith = sets: caisson.mkLib { - sources = mockSources; - defaultEcosystemSrc.home-manager = hmStub; + sources = mockSources // { + inherit hmStub; + }; + defaultEcosystemSrc = sources: { home-manager = sources.hmStub; }; # A home-manager configuration takes its system and its # package set from the composition. systems = [ "x86_64-linux" ];