Style

From indexable-inc/index-bak · View interactive version

Style is an AI agent skill from the GitHub repository indexable-inc/index-bak. Nix code style, general and mechanical: a design and idiom checklist for new code, plus the rules enforced by astlog and lint (no with/rec/mkForce, derivation hygiene, typed options, fetchers, licenses). Use when writing or reviewing Nix, or fixing a lint failure.

How to use this skill

Skill file

Adding a new Nix thing

Craft-standard governs ownership, DRY, layering, consumers, and not being

defensive. The Nix-specific checks on top:

elemAt) usually means a missing map, genList, or higher-level combinator.

reader should have no complaints on first read.

needs in the design without writing dead code.

Nix style (astlog enforced)

Run the repo's pinned lint before committing: nix run .#lint in index and

just lint in ix. It runs

alejandra, Statix, Deadnix, and the repo's astlog rules (astlog-rules/nix.astlog for Nix and

astlog-rules/rust.astlog for the corpus/search Rust crates, both gated with

astlog scan). The lint app is the mechanical source of truth. A legitimate exception to an astlog rule is suppressed in

place with an # astlog-ignore: <rule> comment on the finding's line or the

line above it, with a comment naming the reason. The common hard rules are:

Scope / access

lib.foo directly.

lib; once at the top of a let) and use lib.foo` everywhere.

finalAttrs: for mkDerivation self-reference.

compose mkDefault / mkOptionDefault / mkBefore / mkAfter.

one parent.

Eval and source paths

refs. No builtins.getFlake (toString ./...).

path is reproducible across clones.

or ix.paths.root. Select the file or subtree with path concatenation before

interpolation so derivations do not depend on the whole repository.

Migration / deprecated APIs

pkgs.replaceVars / replaceVarsWith.

vendorHash), no npmDepsSha256 (use npmDepsHash). pnpmDepsHash is the

current name on the pnpm side and is not flagged.

crane.buildPackage.

lib/per-system.nix.

Idioms (mechanical)

builtins.fromJSON (builtins.readFile path).

pkgs.writeText "name" (builtins.toJSON value).

reserve lib.optionals cond xs (plural) for actual lists.

value = f n; }) keys)`.

lib.mapAttrs (_: _: v) X when both arguments are discarded.

helpers are refactor leftovers.

pname + version. (Use pname + version instead of a single dashed

name so updaters and meta rendering can parse the version.)

legacyPackages.${system}.

Derivations / mkDerivation

buildPhase / installPhase — do not restate the stdenv defaults.

are lists of strings; never one string with spaces.

Types and options

options. Use a typed submodule with freeformType = (pkgs.formats.<x> {}).type,

or an explicit oneOf / attrsOf <type>.

defaults that branch on sibling cfg belong in config = ... with mkDefault.

Hashes / licenses / fetchers

hash slot (hash = "sha256-...="), never a legacy sha256 = ... attr. The

fetcher sha256 ban and the removed cargoSha256 / vendorSha256 /

npmDepsSha256 builder attrs are one rule (prefer-sri-hash, error). The

only exception is a hex digest that must round-trip verbatim (e.g. a

Cargo.lock checksum fed back into .cargo-checksum.json, which cargo verifies

as hex): keep it on sha256 and add a # astlog-ignore: prefer-sri-hash

comment naming the reason.

string. The bare gpl2 / gpl3 / lgpl2 / lgpl3 / agpl3 aliases are

banned by lint — pick the explicit *Only / *Plus flavor

(agpl3Plus, not gpl3Plus, when the upstream is AGPL).

Errors and warnings

lib.assertMsg for invariants. throw "" is the same shape as a bare

assert and is rejected.

code.

Build / configuration outputs

modules output.

fragments.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.