From ad42a784690449873fccb20192bd2150da81c56d Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 11 Jul 2019 13:54:53 +0200 Subject: [PATCH] Rename 'epoch' -> 'edition' --- doc/flakes/design.md | 10 +++++----- src/libexpr/flake/flake.cc | 24 +++++++++++++++--------- src/libexpr/flake/flake.hh | 2 +- src/nix/flake.cc | 4 ++-- 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/doc/flakes/design.md b/doc/flakes/design.md index c9520bcbf..97bd12ce3 100644 --- a/doc/flakes/design.md +++ b/doc/flakes/design.md @@ -65,7 +65,7 @@ Upcoming but not yet implemented: NixOS configuration can be reproduced unambiguously from the top-level flake. * Nix code can query flake metadata such as `commitHash` (the Git revision) or - `epoch` (the date of the last commit). This is useful for NixOS to compute + `edition` (the date of the last commit). This is useful for NixOS to compute the NixOS version string (which will be the revision of the top-level configuration flake, uniquely identifying the configuration). @@ -85,9 +85,9 @@ repository that provides a single package and a single NixOS module. # The flake identifier. name = "dwarffs"; - # The epoch may be used in the future to determine how Nix + # The edition may be used in the future to determine how Nix # expressions inside this flake are to be parsed. - epoch = 201906; + edition = 201906; # Some other metadata. description = "A filesystem that fetches DWARF debug info from the Internet on demand"; @@ -162,7 +162,7 @@ Similarly, a minimal `flake.nix` for Nixpkgs: { name = "nixpkgs"; - epoch = 201906; + edition = 201906; description = "A collection of packages for the Nix package manager"; @@ -449,7 +449,7 @@ flakes in (local) Git repositories. { name = "my-system"; - epoch = 201906; + edition = 201906; inputs = [ "nixpkgs/nixos-18.09" diff --git a/src/libexpr/flake/flake.cc b/src/libexpr/flake/flake.cc index 4f59c61bd..8b9525680 100644 --- a/src/libexpr/flake/flake.cc +++ b/src/libexpr/flake/flake.cc @@ -223,16 +223,21 @@ Flake getFlake(EvalState & state, const FlakeRef & flakeRef) state.forceAttrs(vInfo); - auto sEpoch = state.symbols.create("epoch"); + auto sEdition = state.symbols.create("edition"); + auto sEpoch = state.symbols.create("epoch"); // FIXME: remove soon - if (auto epoch = vInfo.attrs->get(sEpoch)) { - flake.epoch = state.forceInt(*(**epoch).value, *(**epoch).pos); - if (flake.epoch < 201906) - throw Error("flake '%s' has illegal epoch %d", flakeRef, flake.epoch); - if (flake.epoch > 201906) - throw Error("flake '%s' requires unsupported epoch %d; please upgrade Nix", flakeRef, flake.epoch); + auto edition = vInfo.attrs->get(sEdition); + if (!edition) + edition = vInfo.attrs->get(sEpoch); + + if (edition) { + flake.edition = state.forceInt(*(**edition).value, *(**edition).pos); + if (flake.edition < 201906) + throw Error("flake '%s' has illegal edition %d", flakeRef, flake.edition); + if (flake.edition > 201906) + throw Error("flake '%s' requires unsupported edition %d; please upgrade Nix", flakeRef, flake.edition); } else - throw Error("flake '%s' lacks attribute 'epoch'", flakeRef); + throw Error("flake '%s' lacks attribute 'edition'", flakeRef); if (auto name = vInfo.attrs->get(state.sName)) flake.id = state.forceStringNoCtx(*(**name).value, *(**name).pos); @@ -271,7 +276,8 @@ Flake getFlake(EvalState & state, const FlakeRef & flakeRef) throw Error("flake '%s' lacks attribute 'outputs'", flakeRef); for (auto & attr : *vInfo.attrs) { - if (attr.name != sEpoch && + if (attr.name != sEdition && + attr.name != sEpoch && attr.name != state.sName && attr.name != state.sDescription && attr.name != sInputs && diff --git a/src/libexpr/flake/flake.hh b/src/libexpr/flake/flake.hh index de0feb2c4..01fb421bd 100644 --- a/src/libexpr/flake/flake.hh +++ b/src/libexpr/flake/flake.hh @@ -67,7 +67,7 @@ struct Flake std::vector inputs; std::map nonFlakeInputs; Value * vOutputs; // FIXME: gc - unsigned int epoch; + unsigned int edition; Flake(const FlakeRef & origRef, const SourceInfo & sourceInfo) : originalRef(origRef), sourceInfo(sourceInfo) {}; diff --git a/src/nix/flake.cc b/src/nix/flake.cc index 49f7c33c7..aab29b626 100644 --- a/src/nix/flake.cc +++ b/src/nix/flake.cc @@ -105,7 +105,7 @@ static void printFlakeInfo(const Flake & flake) { std::cout << fmt("ID: %s\n", flake.id); std::cout << fmt("Description: %s\n", flake.description); - std::cout << fmt("Epoch: %s\n", flake.epoch); + std::cout << fmt("Edition: %s\n", flake.edition); printSourceInfo(flake.sourceInfo); } @@ -114,7 +114,7 @@ static nlohmann::json flakeToJson(const Flake & flake) nlohmann::json j; j["id"] = flake.id; j["description"] = flake.description; - j["epoch"] = flake.epoch; + j["edition"] = flake.edition; sourceInfoToJson(flake.sourceInfo, j); return j; }