Skip to content

fix: quote attribute names in nixCode and stop tack dropping input attributes - #144

Merged
vic merged 1 commit into
mainfrom
fix/serializer-quoting
Oct 12, 2026
Merged

vic merged 1 commit into
mainfrom
fix/serializer-quoting

Conversation

@sini

@sini sini commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

Summary

  • nixCode quotes non-identifier attribute names. An input named "nixpkgs-25.05" used to render as nixpkgs-25.05.url = …, which broke the write-flake build (unexpected "05"). "1password" and keywords such as "if" broke the same way. Each segment now goes through lib.strings.escapeNixIdentifier. A collapsed path is escaped one segment at a time, so a."b.c".d keeps three segments. Bare identifiers render exactly as before. This fixes write-flake, write-inputs and write-unflake, which all render through nixCode.
  • nixCode renders null as null. It used to produce { foo = ; }.
  • tack no longer drops input attributes. tack v1.0.0 reads host and rev only from the url query, and reads host only on gitlab: urls (src/source/mod.rs parse_query_fields, src/source/gitlab.rs). Its follows table reaches a pin's direct inputs only (README "follows"; assets/pins.toml field list). The serializer now puts rev and the gitlab host into the synthesised url, e.g. github:a/b/main?rev=abc or gitlab:a/b?host=gitlab.example.org. It throws tack serialize: input '<name>' sets <attrs>, which pins.toml cannot represent for anything it cannot carry: host on a non-gitlab input, ref/rev/host beside url, narHash, lfs, shallow, path, id, top-level follows, and follows nested below a direct input.

Behaviour change: configs that set any of those attributes on a tack input used to lose them silently. write-tack now fails with the error above.

Validation

  • New unit tests in dev/modules/unit-tests/nixCode.nix cover dashed, dotted, numeric-leading and keyword names, a nested dotted path, and null. New cases in tackSerialize.nix cover rev, gitlab host, github host, rev beside url, and nested follows.
  • With the fix stashed, all 10 new cases fail and both bare/dashed controls pass. On the branch, nix build ./dev#checks.x86_64-linux.nix-unit passes 43/43.
  • New bootstrap test test-flake-quoted-name runs write-flake with input "nixpkgs-25.05", then runs nix-instantiate --parse on the output and greps for the quoted name. Unpatched, it fails at flake-formatted with unexpected "05". On the branch it passes.
  • These bootstrap tests pass on the branch: test-flake, test-inputs, test-unflake, test-tack, and test-write-lock-{flake,tack,unflake,npins,lon,niv}.
  • check-flake-file passes, so the dev flake.nix regenerates byte-identically. nix run ./dev#fmt -- --ci reports 0 changed.

…tributes

nixCode now quotes any attribute segment that is not a bare Nix identifier
(lib.strings.escapeNixIdentifier), so inputs such as "nixpkgs-25.05",
"1password" or "if" render as valid Nix in write-flake, write-inputs and
write-unflake. Collapsed paths escape per segment, and null renders as null.

The tack serializer carries rev and gitlab host in the synthesised url query,
which is where tack reads them, and throws a named error for any input
attribute pins.toml cannot represent (github host, ref/rev/host beside url,
narHash, lfs, shallow, path, id, top-level follows, follows below a direct
input) instead of dropping it.
@vic
vic enabled auto-merge (squash) October 12, 2026 20:08
collapse: name: value:
collapse: rawName: value:
let
name = lib.strings.escapeNixIdentifier rawName;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nice! thanks :)

@vic
vic disabled auto-merge October 12, 2026 20:12
@vic
vic merged commit a494f1c into main Oct 12, 2026
12 checks passed
@vic
vic deleted the fix/serializer-quoting branch October 12, 2026 20:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants