Skip to content

Commit

Permalink
Remove flake 'edition' field
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
edolstra committed Apr 10, 2020
1 parent 3aaceeb commit e5ea01c
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 65 deletions.
2 changes: 1 addition & 1 deletion flake.nix
@@ -1,7 +1,7 @@
{
description = "The purely functional package manager";

edition = 201909;
edition = 201909; # FIXME: remove

inputs.nixpkgs.uri = "nixpkgs/nixos-20.03-small";

Expand Down
1 change: 0 additions & 1 deletion src/libexpr/flake/call-flake.nix
Expand Up @@ -19,7 +19,6 @@ let
result = outputs // sourceInfo // { inherit inputs; inherit outputs; inherit sourceInfo; };
in
if node.flake or true then
assert flake.edition or flake.epoch or 0 == 201909;
assert builtins.isFunction flake.outputs;
result
else
Expand Down
20 changes: 6 additions & 14 deletions src/libexpr/flake/flake.cc
Expand Up @@ -231,22 +231,14 @@ static Flake getFlake(

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 edition = vInfo.attrs->get(sEdition);
if (!edition)
edition = vInfo.attrs->get(sEpoch);

if (edition) {
expectType(state, tInt, *edition->value, *edition->pos);
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 (vInfo.attrs->get(sEdition))
warn("flake '%s' has deprecated attribution 'edition'", lockedRef);

if (vInfo.attrs->get(sEpoch))
warn("flake '%s' has deprecated attribution 'epoch'", lockedRef);

if (auto description = vInfo.attrs->get(state.sDescription)) {
expectType(state, tString, *description->value, *description->pos);
Expand Down
1 change: 0 additions & 1 deletion src/libexpr/flake/flake.hh
Expand Up @@ -34,7 +34,6 @@ struct Flake
std::shared_ptr<const fetchers::Tree> sourceInfo;
FlakeInputs inputs;
Value * vOutputs; // FIXME: gc
unsigned int edition;
~Flake();
};

Expand Down
2 changes: 0 additions & 2 deletions src/nix/flake-template.nix
@@ -1,8 +1,6 @@
{
description = "A flake for building Hello World";

edition = 201909;

outputs = { self, nixpkgs }: {

packages.x86_64-linux.hello = nixpkgs.legacyPackages.x86_64-linux.hello;
Expand Down
2 changes: 0 additions & 2 deletions src/nix/flake.cc
Expand Up @@ -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("Locked URL: %s\n", flake.lockedRef.to_string());
std::cout << fmt("Edition: %s\n", flake.edition);
if (flake.description)
std::cout << fmt("Description: %s\n", *flake.description);
std::cout << fmt("Path: %s\n", store.printStorePath(flake.sourceInfo->storePath));
Expand All @@ -100,7 +99,6 @@ static nlohmann::json flakeToJson(const Store & store, const Flake & flake)
nlohmann::json j;
if (flake.description)
j["description"] = *flake.description;
j["edition"] = flake.edition;
j["originalUrl"] = flake.originalRef.to_string();
j["original"] = attrsToJson(flake.originalRef.toAttrs());
j["resolvedUrl"] = flake.resolvedRef.to_string();
Expand Down
44 changes: 0 additions & 44 deletions tests/flakes.sh
Expand Up @@ -35,8 +35,6 @@ done

cat > $flake1Dir/flake.nix <<EOF
{
edition = 201909;
description = "Bla bla";
outputs = inputs: rec {
Expand All @@ -55,8 +53,6 @@ git -C $flake1Dir commit -m 'Initial'

cat > $flake2Dir/flake.nix <<EOF
{
edition = 201909;
description = "Fnord";
outputs = { self, flake1 }: rec {
Expand All @@ -70,8 +66,6 @@ git -C $flake2Dir commit -m 'Initial'

cat > $flake3Dir/flake.nix <<EOF
{
edition = 201909;
description = "Fnord";
outputs = { self, flake2 }: rec {
Expand Down Expand Up @@ -246,8 +240,6 @@ rm $flake3Dir/flake.nix

cat > $flake3Dir/flake.nix <<EOF
{
edition = 201909;
description = "Fnord";
outputs = { self, flake1, flake2 }: rec {
Expand All @@ -271,10 +263,6 @@ git -C $flake3Dir add flake.lock

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.
nix flake list --flake-registry file://$registry | grep -q flake3
mv $registry $registry.tmp
Expand All @@ -300,8 +288,6 @@ rm $flake3Dir/flake.nix

cat > $flake3Dir/flake.nix <<EOF
{
edition = 201909;
inputs = {
flake1 = {};
flake2 = {};
Expand Down Expand Up @@ -370,8 +356,6 @@ rm $flake3Dir/flake.nix

cat > $flake3Dir/flake.nix <<EOF
{
edition = 201909;
inputs = {
nonFlake = {
url = "$nonFlakeDir";
Expand Down Expand Up @@ -428,8 +412,6 @@ nix flake clone flake1 --dest $TEST_ROOT/flake1-v2
# More 'nix flake check' tests.
cat > $flake3Dir/flake.nix <<EOF
{
edition = 201909;
outputs = { flake1, self }: {
overlay = final: prev: {
};
Expand All @@ -441,8 +423,6 @@ nix flake check $flake3Dir

cat > $flake3Dir/flake.nix <<EOF
{
edition = 201909;
outputs = { flake1, self }: {
overlay = finalll: prev: {
};
Expand All @@ -454,8 +434,6 @@ EOF

cat > $flake3Dir/flake.nix <<EOF
{
edition = 201909;
outputs = { flake1, self }: {
nixosModules.foo = {
a.b.c = 123;
Expand All @@ -469,8 +447,6 @@ nix flake check $flake3Dir

cat > $flake3Dir/flake.nix <<EOF
{
edition = 201909;
outputs = { flake1, self }: {
nixosModules.foo = {
a.b.c = 123;
Expand All @@ -484,8 +460,6 @@ EOF

cat > $flake3Dir/flake.nix <<EOF
{
edition = 201909;
outputs = { flake1, self }: {
nixosModule = { config, pkgs, ... }: {
a.b.c = 123;
Expand All @@ -498,8 +472,6 @@ nix flake check $flake3Dir

cat > $flake3Dir/flake.nix <<EOF
{
edition = 201909;
outputs = { flake1, self }: {
nixosModule = { config, pkgs }: {
a.b.c = 123;
Expand All @@ -513,8 +485,6 @@ EOF
# Test 'follows' inputs.
cat > $flake3Dir/flake.nix <<EOF
{
edition = 201909;
inputs.foo = {
type = "indirect";
id = "flake1";
Expand All @@ -531,8 +501,6 @@ nix flake update $flake3Dir

cat > $flake3Dir/flake.nix <<EOF
{
edition = 201909;
inputs.bar.follows = "flake2/flake1";
outputs = { self, flake2, bar }: {
Expand All @@ -545,8 +513,6 @@ nix flake update $flake3Dir

cat > $flake3Dir/flake.nix <<EOF
{
edition = 201909;
inputs.bar.follows = "flake2";
outputs = { self, flake2, bar }: {
Expand All @@ -560,8 +526,6 @@ nix flake update $flake3Dir
# Test overriding inputs of inputs.
cat > $flake3Dir/flake.nix <<EOF
{
edition = 201909;
inputs.flake2.inputs.flake1 = {
type = "git";
url = file://$flake7Dir;
Expand All @@ -577,8 +541,6 @@ nix flake update $flake3Dir

cat > $flake3Dir/flake.nix <<EOF
{
edition = 201909;
inputs.flake2.inputs.flake1.follows = "foo";
inputs.foo.url = git+file://$flake7Dir;
Expand All @@ -596,8 +558,6 @@ hg init $flake5Dir

cat > $flake5Dir/flake.nix <<EOF
{
edition = 201909;
outputs = { self, flake1 }: {
defaultPackage.$system = flake1.defaultPackage.$system;
Expand Down Expand Up @@ -669,8 +629,6 @@ nix flake list-inputs $flake3Dir --json | jq .
# Test circular flake dependencies.
cat > $flakeA/flake.nix <<EOF
{
edition = 201909;
inputs.b.url = git+file://$flakeB;
inputs.b.inputs.a.follows = "/";
Expand All @@ -685,8 +643,6 @@ git -C $flakeA add flake.nix

cat > $flakeB/flake.nix <<EOF
{
edition = 201909;
inputs.a.url = git+file://$flakeA;
outputs = { self, nixpkgs, a }: {
Expand Down

1 comment on commit e5ea01c

@nixos-discourse
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/nix-2-8-0-released/18714/6

Please sign in to comment.