nix-editor icon indicating copy to clipboard operation
nix-editor copied to clipboard

Create new attributes inside lambda

Open tomberek opened this issue 3 years ago • 5 comments

Situation:

{
  outputs = {...}: {
     a = {};
  };
}

Running nix-editor test.nix outputs.a -v 1 produces:

{
  outputs = {...}: {
     a = 1;
  };
}

as expected. But nix-editor test.nix outputs.a.b -v 1 produces:

{
  outputs = {...}: {
     a = {};
  };
  outputs.a.b = 1;
}

where the attrset was not placed into the function call, but on the outside.

tomberek avatar May 26 '22 15:05 tomberek

Should be fixed in 6f33bad9d0c9383bed39115c339b44e098d4e22f and 7b0af65075f002782b50bda3516c6266641cb6b4, although indentation is still hackish

vlinkz avatar Jun 04 '22 19:06 vlinkz

This still seems to be an issue. Querying for values inside the lambda works as expected, but the traversal for writing doesn't seem to use the same logic.

$ cat test.nix
{
  outputs = inputs: inputs.d {
    a.b = {};
  };
}
$ nix-editor test.nix outputs.a
{ b = { }; }

$ nix-editor test.nix outputs.a.b -v 1
{
  outputs = inputs: inputs.d {
    a.b = {};
  };
  outputs.a.b = 1;
}

$ nix-editor test.nix outputs.a.c -v 1
{
  outputs = inputs: inputs.d {
    a.b = {};
  };
  outputs.a.c = 1;
}

tomberek avatar Mar 04 '23 18:03 tomberek

Latest changes (ab2a7e94ca176589c1e8236ce31cd89044e4818f):

nix-editor test.nix outputs.a.b -v '{v=1;}'
{
  outputs = inputs: inputs.d {
    a.b = {};
  };
  outputs.a.b = {v=1;};
}

and

nix-editor test.nix outputs.a.b -v 'true'
{
  outputs = inputs: inputs.d {
    a.b = {};
    a.b = true;
  };
}

tomberek avatar Apr 10 '23 16:04 tomberek

Hm yeah, that seems to have to do with the way attribute sets are handled differently than values

vlinkz avatar Apr 10 '23 16:04 vlinkz

work-around with an empty flake

nix-editor test.nix outputs.a.b -v 'rec {c=1;}'
{
  outputs = inputs: inputs.d {
    a.b = rec {c=1;};
  };
}

This seems to bypass the "{" detection logic.

tomberek avatar Jul 21 '23 01:07 tomberek