Remove flake 'edition' field

Future editions of flakes or the Nix language can be supported by
renaming flake.nix (e.g. flake-v2.nix). This avoids a bootstrap
problem where we don't know which grammar to use to parse
flake*.nix. It also allows a project to support multiple flake
editions, in theory.
This commit is contained in:
Eelco Dolstra 2020-04-10 10:24:09 +02:00
parent 3aaceeb7e2
commit e5ea01c1a8
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE
7 changed files with 6 additions and 64 deletions

View file

@ -1,7 +1,7 @@
{ {
description = "The purely functional package manager"; description = "The purely functional package manager";
edition = 201909; edition = 201909; # FIXME: remove
inputs.nixpkgs.uri = "nixpkgs/nixos-20.03-small"; inputs.nixpkgs.uri = "nixpkgs/nixos-20.03-small";

View file

@ -19,7 +19,6 @@ let
result = outputs // sourceInfo // { inherit inputs; inherit outputs; inherit sourceInfo; }; result = outputs // sourceInfo // { inherit inputs; inherit outputs; inherit sourceInfo; };
in in
if node.flake or true then if node.flake or true then
assert flake.edition or flake.epoch or 0 == 201909;
assert builtins.isFunction flake.outputs; assert builtins.isFunction flake.outputs;
result result
else else

View file

@ -231,22 +231,14 @@ static Flake getFlake(
expectType(state, tAttrs, vInfo, Pos(state.symbols.create(flakeFile), 0, 0)); expectType(state, tAttrs, vInfo, Pos(state.symbols.create(flakeFile), 0, 0));
auto sEdition = state.symbols.create("edition"); auto sEdition = state.symbols.create("edition"); // FIXME: remove soon
auto sEpoch = state.symbols.create("epoch"); // FIXME: remove soon auto sEpoch = state.symbols.create("epoch"); // FIXME: remove soon
auto edition = vInfo.attrs->get(sEdition); if (vInfo.attrs->get(sEdition))
if (!edition) warn("flake '%s' has deprecated attribution 'edition'", lockedRef);
edition = vInfo.attrs->get(sEpoch);
if (edition) { if (vInfo.attrs->get(sEpoch))
expectType(state, tInt, *edition->value, *edition->pos); warn("flake '%s' has deprecated attribution 'epoch'", lockedRef);
flake.edition = edition->value->integer;
if (flake.edition > 201909)
throw Error("flake '%s' requires unsupported edition %d; please upgrade Nix", lockedRef, flake.edition);
if (flake.edition < 201909)
throw Error("flake '%s' has illegal edition %d", lockedRef, flake.edition);
} else
throw Error("flake '%s' lacks attribute 'edition'", lockedRef);
if (auto description = vInfo.attrs->get(state.sDescription)) { if (auto description = vInfo.attrs->get(state.sDescription)) {
expectType(state, tString, *description->value, *description->pos); expectType(state, tString, *description->value, *description->pos);

View file

@ -34,7 +34,6 @@ struct Flake
std::shared_ptr<const fetchers::Tree> sourceInfo; std::shared_ptr<const fetchers::Tree> sourceInfo;
FlakeInputs inputs; FlakeInputs inputs;
Value * vOutputs; // FIXME: gc Value * vOutputs; // FIXME: gc
unsigned int edition;
~Flake(); ~Flake();
}; };

View file

@ -1,8 +1,6 @@
{ {
description = "A flake for building Hello World"; description = "A flake for building Hello World";
edition = 201909;
outputs = { self, nixpkgs }: { outputs = { self, nixpkgs }: {
packages.x86_64-linux.hello = nixpkgs.legacyPackages.x86_64-linux.hello; packages.x86_64-linux.hello = nixpkgs.legacyPackages.x86_64-linux.hello;

View file

@ -82,7 +82,6 @@ static void printFlakeInfo(const Store & store, const Flake & flake)
{ {
std::cout << fmt("Resolved URL: %s\n", flake.resolvedRef.to_string()); std::cout << fmt("Resolved URL: %s\n", flake.resolvedRef.to_string());
std::cout << fmt("Locked URL: %s\n", flake.lockedRef.to_string()); std::cout << fmt("Locked URL: %s\n", flake.lockedRef.to_string());
std::cout << fmt("Edition: %s\n", flake.edition);
if (flake.description) if (flake.description)
std::cout << fmt("Description: %s\n", *flake.description); std::cout << fmt("Description: %s\n", *flake.description);
std::cout << fmt("Path: %s\n", store.printStorePath(flake.sourceInfo->storePath)); std::cout << fmt("Path: %s\n", store.printStorePath(flake.sourceInfo->storePath));
@ -100,7 +99,6 @@ static nlohmann::json flakeToJson(const Store & store, const Flake & flake)
nlohmann::json j; nlohmann::json j;
if (flake.description) if (flake.description)
j["description"] = *flake.description; j["description"] = *flake.description;
j["edition"] = flake.edition;
j["originalUrl"] = flake.originalRef.to_string(); j["originalUrl"] = flake.originalRef.to_string();
j["original"] = attrsToJson(flake.originalRef.toAttrs()); j["original"] = attrsToJson(flake.originalRef.toAttrs());
j["resolvedUrl"] = flake.resolvedRef.to_string(); j["resolvedUrl"] = flake.resolvedRef.to_string();

View file

@ -35,8 +35,6 @@ done
cat > $flake1Dir/flake.nix <<EOF cat > $flake1Dir/flake.nix <<EOF
{ {
edition = 201909;
description = "Bla bla"; description = "Bla bla";
outputs = inputs: rec { outputs = inputs: rec {
@ -55,8 +53,6 @@ git -C $flake1Dir commit -m 'Initial'
cat > $flake2Dir/flake.nix <<EOF cat > $flake2Dir/flake.nix <<EOF
{ {
edition = 201909;
description = "Fnord"; description = "Fnord";
outputs = { self, flake1 }: rec { outputs = { self, flake1 }: rec {
@ -70,8 +66,6 @@ git -C $flake2Dir commit -m 'Initial'
cat > $flake3Dir/flake.nix <<EOF cat > $flake3Dir/flake.nix <<EOF
{ {
edition = 201909;
description = "Fnord"; description = "Fnord";
outputs = { self, flake2 }: rec { outputs = { self, flake2 }: rec {
@ -246,8 +240,6 @@ rm $flake3Dir/flake.nix
cat > $flake3Dir/flake.nix <<EOF cat > $flake3Dir/flake.nix <<EOF
{ {
edition = 201909;
description = "Fnord"; description = "Fnord";
outputs = { self, flake1, flake2 }: rec { outputs = { self, flake1, flake2 }: rec {
@ -271,10 +263,6 @@ git -C $flake3Dir add flake.lock
git -C $flake3Dir commit -m 'Add lockfile' git -C $flake3Dir commit -m 'Add lockfile'
# Unsupported editions should be an error.
sed -i $flake3Dir/flake.nix -e s/201909/201912/
nix build -o $TEST_ROOT/result $flake3Dir#sth 2>&1 | grep 'unsupported edition'
# Test whether registry caching works. # Test whether registry caching works.
nix flake list --flake-registry file://$registry | grep -q flake3 nix flake list --flake-registry file://$registry | grep -q flake3
mv $registry $registry.tmp mv $registry $registry.tmp
@ -300,8 +288,6 @@ rm $flake3Dir/flake.nix
cat > $flake3Dir/flake.nix <<EOF cat > $flake3Dir/flake.nix <<EOF
{ {
edition = 201909;
inputs = { inputs = {
flake1 = {}; flake1 = {};
flake2 = {}; flake2 = {};
@ -370,8 +356,6 @@ rm $flake3Dir/flake.nix
cat > $flake3Dir/flake.nix <<EOF cat > $flake3Dir/flake.nix <<EOF
{ {
edition = 201909;
inputs = { inputs = {
nonFlake = { nonFlake = {
url = "$nonFlakeDir"; url = "$nonFlakeDir";
@ -428,8 +412,6 @@ nix flake clone flake1 --dest $TEST_ROOT/flake1-v2
# More 'nix flake check' tests. # More 'nix flake check' tests.
cat > $flake3Dir/flake.nix <<EOF cat > $flake3Dir/flake.nix <<EOF
{ {
edition = 201909;
outputs = { flake1, self }: { outputs = { flake1, self }: {
overlay = final: prev: { overlay = final: prev: {
}; };
@ -441,8 +423,6 @@ nix flake check $flake3Dir
cat > $flake3Dir/flake.nix <<EOF cat > $flake3Dir/flake.nix <<EOF
{ {
edition = 201909;
outputs = { flake1, self }: { outputs = { flake1, self }: {
overlay = finalll: prev: { overlay = finalll: prev: {
}; };
@ -454,8 +434,6 @@ EOF
cat > $flake3Dir/flake.nix <<EOF cat > $flake3Dir/flake.nix <<EOF
{ {
edition = 201909;
outputs = { flake1, self }: { outputs = { flake1, self }: {
nixosModules.foo = { nixosModules.foo = {
a.b.c = 123; a.b.c = 123;
@ -469,8 +447,6 @@ nix flake check $flake3Dir
cat > $flake3Dir/flake.nix <<EOF cat > $flake3Dir/flake.nix <<EOF
{ {
edition = 201909;
outputs = { flake1, self }: { outputs = { flake1, self }: {
nixosModules.foo = { nixosModules.foo = {
a.b.c = 123; a.b.c = 123;
@ -484,8 +460,6 @@ EOF
cat > $flake3Dir/flake.nix <<EOF cat > $flake3Dir/flake.nix <<EOF
{ {
edition = 201909;
outputs = { flake1, self }: { outputs = { flake1, self }: {
nixosModule = { config, pkgs, ... }: { nixosModule = { config, pkgs, ... }: {
a.b.c = 123; a.b.c = 123;
@ -498,8 +472,6 @@ nix flake check $flake3Dir
cat > $flake3Dir/flake.nix <<EOF cat > $flake3Dir/flake.nix <<EOF
{ {
edition = 201909;
outputs = { flake1, self }: { outputs = { flake1, self }: {
nixosModule = { config, pkgs }: { nixosModule = { config, pkgs }: {
a.b.c = 123; a.b.c = 123;
@ -513,8 +485,6 @@ EOF
# Test 'follows' inputs. # Test 'follows' inputs.
cat > $flake3Dir/flake.nix <<EOF cat > $flake3Dir/flake.nix <<EOF
{ {
edition = 201909;
inputs.foo = { inputs.foo = {
type = "indirect"; type = "indirect";
id = "flake1"; id = "flake1";
@ -531,8 +501,6 @@ nix flake update $flake3Dir
cat > $flake3Dir/flake.nix <<EOF cat > $flake3Dir/flake.nix <<EOF
{ {
edition = 201909;
inputs.bar.follows = "flake2/flake1"; inputs.bar.follows = "flake2/flake1";
outputs = { self, flake2, bar }: { outputs = { self, flake2, bar }: {
@ -545,8 +513,6 @@ nix flake update $flake3Dir
cat > $flake3Dir/flake.nix <<EOF cat > $flake3Dir/flake.nix <<EOF
{ {
edition = 201909;
inputs.bar.follows = "flake2"; inputs.bar.follows = "flake2";
outputs = { self, flake2, bar }: { outputs = { self, flake2, bar }: {
@ -560,8 +526,6 @@ nix flake update $flake3Dir
# Test overriding inputs of inputs. # Test overriding inputs of inputs.
cat > $flake3Dir/flake.nix <<EOF cat > $flake3Dir/flake.nix <<EOF
{ {
edition = 201909;
inputs.flake2.inputs.flake1 = { inputs.flake2.inputs.flake1 = {
type = "git"; type = "git";
url = file://$flake7Dir; url = file://$flake7Dir;
@ -577,8 +541,6 @@ nix flake update $flake3Dir
cat > $flake3Dir/flake.nix <<EOF cat > $flake3Dir/flake.nix <<EOF
{ {
edition = 201909;
inputs.flake2.inputs.flake1.follows = "foo"; inputs.flake2.inputs.flake1.follows = "foo";
inputs.foo.url = git+file://$flake7Dir; inputs.foo.url = git+file://$flake7Dir;
@ -596,8 +558,6 @@ hg init $flake5Dir
cat > $flake5Dir/flake.nix <<EOF cat > $flake5Dir/flake.nix <<EOF
{ {
edition = 201909;
outputs = { self, flake1 }: { outputs = { self, flake1 }: {
defaultPackage.$system = flake1.defaultPackage.$system; defaultPackage.$system = flake1.defaultPackage.$system;
@ -669,8 +629,6 @@ nix flake list-inputs $flake3Dir --json | jq .
# Test circular flake dependencies. # Test circular flake dependencies.
cat > $flakeA/flake.nix <<EOF cat > $flakeA/flake.nix <<EOF
{ {
edition = 201909;
inputs.b.url = git+file://$flakeB; inputs.b.url = git+file://$flakeB;
inputs.b.inputs.a.follows = "/"; inputs.b.inputs.a.follows = "/";
@ -685,8 +643,6 @@ git -C $flakeA add flake.nix
cat > $flakeB/flake.nix <<EOF cat > $flakeB/flake.nix <<EOF
{ {
edition = 201909;
inputs.a.url = git+file://$flakeA; inputs.a.url = git+file://$flakeA;
outputs = { self, nixpkgs, a }: { outputs = { self, nixpkgs, a }: {