Skip to content

Empty list containing only a comment in flake.nix causes parse error #6

@antifuchs

Description

@antifuchs

I've got a flake.nix containing something like the following example: https://gist.github.com/antifuchs/fbb9e26050e36926eccebf136720baf0:

    packages.x86_64-linux.hello = nixpkgs.legacyPackages.x86_64-linux.hello.overrideAttrs (o: {
      passthru.testing = [
        # comment that triggers the bug - remove this line to successfully run thaw
      ];
    });

With a comment like the above in place, thaw fails with a parse error:

:;    nix run github:snowfallorg/thaw
trace: warning: getExe: Package "bun-1.0.13" does not have the meta.mainProgram attribute. We'll assume that the main program has the same name for now, but this behavior is deprecated, because it leads to surprising errors when the assumption does not hold. If the package has a main program, please set `meta.mainProgram` in its definition to make this warning go away. Otherwise, if the package does not have a main program, or if you don't control its definition, use getExe' to specify the name to the program, such as lib.getExe' foo "bar".
[
  {
    kind: "OpenCurly",
    loc: {
      start: [Object ...],
      end: [Object ...]
    }
  }, {
    kind: "NewLine",
    loc: {
      start: [Object ...],
      end: [Object ...]
    }
  }, {
    kind: "Identifier",
    value: "passthru",
    loc: {
      start: [Object ...],
      end: [Object ...]
    }
  }, {
    kind: "Period",
    loc: {
      start: [Object ...],
      end: [Object ...]
    }
  }, {
    kind: "Identifier",
    value: "testing",
    loc: {
      start: [Object ...],
      end: [Object ...]
    }
  }, {
    kind: "Eq",
    loc: {
      start: [Object ...],
      end: [Object ...]
    }
  }, {
    kind: "OpenBracket",
    loc: {
      start: [Object ...],
      end: [Object ...]
    }
  }, {
    kind: "NewLine",
    loc: {
      start: [Object ...],
      end: [Object ...]
    }
  }, {
    kind: "Comment",
    value: " comment",
    multiline: false,
    loc: {
      start: [Object ...],
      end: [Object ...]
    }
  }, {
    kind: "NewLine",
    loc: {
      start: [Object ...],
      end: [Object ...]
    }
  }
]
-----
{
  kind: "CloseBracket",
  loc: {
    start: {
      line: 15,
      col: 7
    },
    end: {
      line: 15,
      col: 8
    }
  }
}
 ERROR  Thaw An unexpected error occurred.
849 |         break;
850 |       }
851 |       case s.Not:
852 |         return this.parseNot(t);
853 |       default:
854 |         throw console.log(this.tokens.slice(this.cursor - 10, this.cursor)), console.log("-----"), console.log(a), new Error(`Unexpected token: ${a.kind}`);
                                                                                                                       ^
error: Unexpected token: CloseBracket
      at parseSubExpr (/nix/store/d7zrr1q48qk17j8q3d0svigclidmncri-src/vendor/sleet.mjs:854:115)
      at parseExpr (/nix/store/d7zrr1q48qk17j8q3d0svigclidmncri-src/vendor/sleet.mjs:662:19)
      at parseList (/nix/store/d7zrr1q48qk17j8q3d0svigclidmncri-src/vendor/sleet.mjs:967:16)
      at parseSubExpr (/nix/store/d7zrr1q48qk17j8q3d0svigclidmncri-src/vendor/sleet.mjs:818:12)
      at parseExpr (/nix/store/d7zrr1q48qk17j8q3d0svigclidmncri-src/vendor/sleet.mjs:662:19)
      at parseAttr (/nix/store/d7zrr1q48qk17j8q3d0svigclidmncri-src/vendor/sleet.mjs:1044:14)
      at parseAttrs (/nix/store/d7zrr1q48qk17j8q3d0svigclidmncri-src/vendor/sleet.mjs:1001:16)
      at parseSubExpr (/nix/store/d7zrr1q48qk17j8q3d0svigclidmncri-src/vendor/sleet.mjs:823:24)
      at parseExpr (/nix/store/d7zrr1q48qk17j8q3d0svigclidmncri-src/vendor/sleet.mjs:662:19)
      at tryParseFunction (/nix/store/d7zrr1q48qk17j8q3d0svigclidmncri-src/vendor/sleet.mjs:1113:16)

Removing the line comment makes the run succeed, though. As all other nix tools work otherwise, I assume this piece of syntax is an oversight in the parser?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions