Rechercher

PythonReactSEOPDF
GitHub Skill

code-style

Write Nix code following repository conventions

DaRacci☆ 17 Étoiles du dépôt0 Forks du dépôt

Installation

Suivez les instructions du dépôt pour votre agent. Consultez les fichiers et dépendances avant l’installation.

Voir la source ↗Guides

Instructions

Code Style

Critical Requirement

MUST run nix fmt <paths...> after making any changes to ensure consistent formatting.

Indentation

  • Use 2 spaces for indentation
  • No tabs allowed

Naming Conventions

Context Convention Example
Files and directories kebab-case my-module.nix, home-manager/
Nix attributes camelCase myOption, enableFeature
Option paths camelCase services.myService.enable

Comments

  • Minimal comments preferred
  • Code should be self-explanatory
  • Use comments to explain why, not what
# Good: explains why
# Workaround for upstream bug #1234
extraConfig = "...";

# Bad: describes what (obvious from code)
# Set extraConfig to the value
extraConfig = "...";

Imports

  • Prefer relative imports: ./modules/foo.nix
  • Group imports at the top of the file
  • Use list format for multiple imports:
{
  imports = [
    ./hardware.nix
    ./services.nix
    ./networking.nix
  ];
}

Structured Data

When generating JSON, YAML, or other structured formats, define as Nix attribute sets and convert:

# Good: define as Nix, convert to JSON
environment.etc."config.json".text = builtins.toJSON {
  setting = "value";
  nested = { key = 123; };
};

# Avoid: inline JSON strings
environment.etc."config.json".text = ''
  {"setting": "value", "nested": {"key": 123}}
'';

Common Patterns

Module Structure
{
  config,
  lib,
  pkgs,
  ...
}:
let
  inherit (lib) mkEnableOption mkOption mkIf types;
  cfg = config.services.myService;
in
{
  options.services.myService = {
    enable = mkEnableOption "my service";
  };

  config = mkIf cfg.enable {
    # configuration here
  };
}
Let Bindings
let
  inherit (lib) mkIf mkEnableOption;
  cfg = config.myModule;
in
{
  # use cfg, mkIf, etc.
}

Exemples

Consultez les exemples du dépôt source.

Voir la source ↗

Historique source

Date d’indexation
2026-01-20
Mise à jour de l’index
2026-01-26
Branch
main

Les dates concernent ce répertoire. Consultez le dépôt pour l’historique du code.

GitHub ↗

chat Comments (0)

chat_bubble_outline

No comments yet. Be the first to share your thoughts!