Disallow uninitialized meta.nixpkgs in Flakes

This commit is contained in:
Zhaofeng Li 2021-10-28 17:10:58 -07:00
parent 765f42fa24
commit f7eb121260
3 changed files with 27 additions and 6 deletions

View file

@ -143,7 +143,9 @@ Here is a short example:
outputs = { nixpkgs, ... }: {
colmena = {
meta = {
inherit nixpkgs;
nixpkgs = import nixpkgs {
system = "x86_64-linux";
};
};
# Also see the non-Flakes hive.nix example above.

View file

@ -291,15 +291,32 @@ let
};
in mergedHive // meta;
mkNixpkgs = configName: pkgConf:
mkNixpkgs = configName: pkgConf: let
uninitializedError = typ: ''
Passing ${typ} is no longer accepted with Flakes. Please initialize Nixpkgs like the following:
{
# ...
outputs = { nixpkgs, ... }: {
colmena = {
meta = {
nixpkgs = import nixpkgs {
system = "${currentSystem}";
};
};
};
};
}
'';
in
if typeOf pkgConf == "path" then
if hermetic then throw (uninitializedError "a path to Nixpkgs")
# The referenced file might return an initialized Nixpkgs attribute set directly
mkNixpkgs configName (import pkgConf)
else mkNixpkgs configName (import pkgConf)
else if typeOf pkgConf == "lambda" then
pkgConf {}
else if typeOf pkgConf == "set" then
# FIXME: Allow configuring `system`
if pkgConf ? outputs then mkNixpkgs configName pkgConf.outputs.legacyPackages.${currentSystem}.path
if pkgConf ? outputs then throw (uninitializedError "an uninitialized Nixpkgs input")
else pkgConf
else throw ''
${configName} must be one of:

View file

@ -5,7 +5,9 @@
outputs = { nixpkgs, ... }: {
colmena = {
meta = {
inherit nixpkgs;
nixpkgs = import nixpkgs {
system = "x86_64-linux";
};
};
host-a = { name, nodes, pkgs, ... }: {