Lockless flakes are missing a bunch of metadata #71

Open
opened 2025-03-26 18:50:24 +00:00 by jade · 4 comments
Owner

This is pretty easy to fix, but it is deep in yakshave territory. I found it while writing a test.

Genuine flake:

$ nix repl .
nix-repl> self 
{
  _type = "flake";
  dirtyRev = "282cf36bc1a428589e0949528e707e8414809108-dirty";
  dirtyShortRev = "282cf36-dirty";
  inputs = { };
  lastModified = 1743011765;
  lastModifiedDate = "20250326175605";
  narHash = "sha256-4TzVdvUjOtd+HoNqrFisOeRvPZD+fNPYP3JoWpMN+gk=";
  outPath = "/nix/store/3frjdy8virv2pgca92kf7alqx3pqacxp-source";
  outputs = { ... };
  self = «repeated»;
  sourceInfo = { ... };
  submodules = false;
}

Ersatz flake:

$ nix repl -f . --arg src ./.
nix-repl> defaultNix.self
{
  dirtyRev = "282cf36bc1a428589e0949528e707e8414809108-dirty";
  dirtyShortRev = "282cf36-dirty";
  lastModified = 1743011765;
  lastModifiedDate = "20250326175605";
  narHash = "sha256-4TzVdvUjOtd+HoNqrFisOeRvPZD+fNPYP3JoWpMN+gk=";
  outPath = "/nix/store/3frjdy8virv2pgca92kf7alqx3pqacxp-source";
  revCount = 0;
  self = «repeated»;
  submodules = false;
}

Cause:

This stuff needs to be extracted to a function:

Lines 298 to 313 in 0c79eca
result =
outputs
# We add the sourceInfo attribute for its metadata, as they are
# relevant metadata for the flake. However, the outPath of the
# sourceInfo does not necessarily match the outPath of the flake,
# as the flake may be in a subdirectory of a source.
# This is shadowed in the next //
// sourceInfo
// {
# This shadows the sourceInfo.outPath
inherit outPath;
inherit inputs;
inherit outputs;
inherit sourceInfo;
_type = "flake";

This stuff needs to be updated to use it:

Lines 179 to 185 in 0c79eca
callLocklessFlake =
flakeSrc:
let
flake = import (flakeSrc + "/flake.nix");
outputs = flakeSrc // (flake.outputs ({ self = outputs; }));
in
outputs;

This is pretty easy to fix, but it is deep in yakshave territory. I found it while writing a test. Genuine flake: ``` $ nix repl . nix-repl> self { _type = "flake"; dirtyRev = "282cf36bc1a428589e0949528e707e8414809108-dirty"; dirtyShortRev = "282cf36-dirty"; inputs = { }; lastModified = 1743011765; lastModifiedDate = "20250326175605"; narHash = "sha256-4TzVdvUjOtd+HoNqrFisOeRvPZD+fNPYP3JoWpMN+gk="; outPath = "/nix/store/3frjdy8virv2pgca92kf7alqx3pqacxp-source"; outputs = { ... }; self = «repeated»; sourceInfo = { ... }; submodules = false; } ``` Ersatz flake: ``` $ nix repl -f . --arg src ./. nix-repl> defaultNix.self { dirtyRev = "282cf36bc1a428589e0949528e707e8414809108-dirty"; dirtyShortRev = "282cf36-dirty"; lastModified = 1743011765; lastModifiedDate = "20250326175605"; narHash = "sha256-4TzVdvUjOtd+HoNqrFisOeRvPZD+fNPYP3JoWpMN+gk="; outPath = "/nix/store/3frjdy8virv2pgca92kf7alqx3pqacxp-source"; revCount = 0; self = «repeated»; submodules = false; } ``` Cause: This stuff needs to be extracted to a function: https://git.lix.systems/lix-project/flake-compat/src/commit/0c79ecade7581467f276a225e4c54fd001f25aed/default.nix#L298-L313 This stuff needs to be updated to use it: https://git.lix.systems/lix-project/flake-compat/src/commit/0c79ecade7581467f276a225e4c54fd001f25aed/default.nix#L179-L185

Came across this since it causes lix to fail to build when using the lix-module (lix uses the lastModifiedDate to create its version when it is not an official release):

$ nix build -f systems.nix libra.config.system.build.toplevel
warning: Git tree '/home/jalil/.config/nixos' is dirty
error:
       … while calling the 'head' builtin
         at /nix/store/1dwky0bis4bkl3qngsc6pmq902swa9b6-source/lib/attrsets.nix:1534:13:
         1533|           if length values == 1 || pred here (elemAt values 1) (head values) then
         1534|             head values
             |             ^
         1535|           else

       … while evaluating the attribute 'value'
         at /nix/store/1dwky0bis4bkl3qngsc6pmq902swa9b6-source/lib/modules.nix:991:7:
          990|     // {
          991|       value = addErrorContext "while evaluating the option `${showOption loc}':" value;
             |       ^
          992|       inherit (res.defsFinal') highestPrio;

       (stack trace truncated; use '--show-trace' to show the full trace)

       error: attribute 'lastModifiedDate' missing
       at /nix/store/jncdi7vrfpl3grs9i5fdp4pzym7zgw37-source/flake.nix:14:43:
           13|       versionSuffix = nixpkgs.lib.optionalString (!lixVersionJson.official_release)
           14|         "-pre${builtins.substring 0 8 lix.lastModifiedDate}-${lix.shortRev or lix.dirtyShortRev}";
             |                                           ^
           15|     in
Came across this since it causes `lix` to fail to build when using the `lix-module` (`lix` uses the `lastModifiedDate` to create its version when it is not an official release): ```console $ nix build -f systems.nix libra.config.system.build.toplevel warning: Git tree '/home/jalil/.config/nixos' is dirty error: … while calling the 'head' builtin at /nix/store/1dwky0bis4bkl3qngsc6pmq902swa9b6-source/lib/attrsets.nix:1534:13: 1533| if length values == 1 || pred here (elemAt values 1) (head values) then 1534| head values | ^ 1535| else … while evaluating the attribute 'value' at /nix/store/1dwky0bis4bkl3qngsc6pmq902swa9b6-source/lib/modules.nix:991:7: 990| // { 991| value = addErrorContext "while evaluating the option `${showOption loc}':" value; | ^ 992| inherit (res.defsFinal') highestPrio; (stack trace truncated; use '--show-trace' to show the full trace) error: attribute 'lastModifiedDate' missing at /nix/store/jncdi7vrfpl3grs9i5fdp4pzym7zgw37-source/flake.nix:14:43: 13| versionSuffix = nixpkgs.lib.optionalString (!lixVersionJson.official_release) 14| "-pre${builtins.substring 0 8 lix.lastModifiedDate}-${lix.shortRev or lix.dirtyShortRev}"; | ^ 15| in ```
Author
Owner

erm. why don't you have a lock file? this bug is about when you have a flake with no inputs at all and it's busted.

i do believe there's a bug you're seeing there but I'm not sure it's the same bug!

erm. why don't you have a lock file? this bug is about when you have a flake with no inputs at all and it's busted. i do believe there's a bug you're seeing there but I'm not sure it's the same bug!

Fun! Because the flake.lock is there (using checks to run treefmt works fine)

Fun! Because the `flake.lock` is there (using `checks` to run `treefmt` works fine)
Author
Owner

I don't think this is the same bug then; please consider writing a reproducer and filing a separate bug; or feel free to try out fixing it and writing a test. We can try to do our best to help out with any difficulties in doing it.

I don't think this is the same bug then; please consider writing a reproducer and filing a separate bug; or feel free to try out fixing it and writing a test. We can try to do our best to help out with any difficulties in doing it.
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: lix-project/flake-compat#71
No description provided.