terlar/nix-config/flake-parts

Claude Code and agent skill by terlar/nix-config

Trust tier 3
  • community
  • ext:[{"type":"hook","description":"Pre/post lifecycle hooks"}]
Source check pending

Checking that the SKILL.md file is still in the repository.

Use when working with flake-parts or dev-flake — structuring flakes, defining perSystem outputs, writing reusable flake modules, using withSystem or moduleWithSystem, exporting flakeModules, setting up dev environments with dev-flake, or debugging flake-parts evaluation.

Install

npx vskill@latest install terlar/nix-config/flake-parts

Semi-extensibleMentions customization, but needs skill-specific knowledge. Read the extensible skills standard

SKILL.md

Basic structure

nix
{
inputs = {
nixpkgs.url = "https://channels.nixos.org/nixos-unstable/nixexprs.tar.zst";
flake-parts.url = "github:hercules-ci/flake-parts";
};
outputs = inputs: inputs.flake-parts.lib.mkFlake { inherit inputs; } {
systems = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" ];
perSystem = { pkgs, ... }: {
packages.default = pkgs.hello;
devShells.default = pkgs.mkShell { packages = [ pkgs.hello ]; };
};
flake = {
# System-independent outputs (nixosConfigurations, lib, etc.)
};
};
}

Always pass the outputs function argument as inputs (not self.inputs) to avoid infinite recursion.

Key options

OptionPurpose
systemsList of systems to iterate over in perSystem
perSystemModule evaluated once per system; receives pkgs, system, config, etc.
flakeSystem-independent flake outputs merged directly
importsImport flake-parts modules
debugExpose full module config in flake outputs for inspection

perSystem module args

ArgValue
systemCurrent system string (e.g., "x86_64-linux")
pkgsnixpkgs.legacyPackages.${system} (configurable)
configThe current perSystem module's config
inputs'All inputs with outputs pre-selected for system
self'This flake's own outputs pre-selected for system

Override pkgs for the whole perSystem scope (e.g. to allow unfree):

nix
perSystem = { system, ... }: {
_module.args.pkgs = import inputs.nixpkgs {
inherit system;
config.allowUnfree = true;
};
};

withSystem — access per-system config from top level

Use withSystem to reference per-system packages from top-level module scope (e.g. when building nixosConfigurations):

nix
{ inputs, withSystem, ... }: {
flake.nixosConfigurations.my-host = withSystem "x86_64-linux" (
{ pkgs, self', ... }:
inputs.nixpkgs.lib.nixosSystem {
modules = [ ./configuration.nix { nixpkgs.pkgs = pkgs; } ];
}
);
}

moduleWithSystem — inject perSystem args into NixOS modules

Wrap a NixOS module to receive per-system args. The target system is inferred from the module's own pkgs or system arg:

nix
{ moduleWithSystem, ... }: {
flake.nixosModules.my-module = moduleWithSystem (
{ pkgs, self' }:
{ config, lib, ... }: {
environment.systemPackages = [ self'.packages.my-tool ];
}
);
}

Exporting flake-parts modules

Expose reusable flake-parts modules under flake.flakeModules:

nix
{ flake-parts-lib, lib, ... }: {
imports = [ inputs.flake-parts.flakeModules.flakeModules ];
flake.flakeModules.default = { ... }: {
options.perSystem = flake-parts-lib.mkPerSystemOption {
_file = ./flake-module.nix; # always set for error attribution
options.myOutput = lib.mkOption {
type = lib.types.lazyAttrsOf lib.types.package;
default = {};
};
};
};
}

Dogfooding pattern — use your own module and export it:

nix
let myModule = ./flake-module.nix;
in {
imports = [ myModule ];
flake.flakeModules.default = myModule;
}

Consumers import it as:

nix
imports = [ inputs.my-lib.flakeModules.default ];

Convention: local module files are named flake-module.nix. Always set _file on inner mkPerSystemOption calls for accurate error attribution.

Importing flake-parts modules

nix
imports = [
inputs.some-flake.flakeModules.default
./flake-module.nix
];

Debugging

Enable debug = true to expose all intermediate module config for inspection:

nix
inputs.flake-parts.lib.mkFlake { inherit inputs; } {
debug = true;
# ...
}

Then inspect any output path:

bash
nix eval .#debug # full debug attrset
nix eval .#debug.allSystems # per-system configs
nix eval .#debug.allSystems.x86_64-linux.config.packages

dev-flake

dev-flake (github:terlar/dev-flake) is a flake-parts module that bundles devshell, git-hooks-nix (pre-commit), and treefmt-nix behind a thin dev.* option surface. All features default to enabled.

What it wires up automatically
  • devShells.default — named devshell with pre-commit installed on entry;

treefmt and pre-commit available as shell commands

  • checks.pre-commit — all configured pre-commit hooks as a flake check
  • checks.treefmt — treefmt check (only when pre-commit is disabled, to avoid

double-checking; otherwise treefmt runs through pre-commit)

  • Default hooks enabled: deadnix, statix
Top-level dev.* options
OptionDefaultDescription
dev.name"project"Project name, used as devshell prompt
dev.rootSrcself.outPathProject root for pre-commit; set to parent self in sub-flakes
dev.devshell.enabletrueEnable devshell
dev.devshell.addCommandstrueAdd treefmt and pre-commit to shell menu
dev.pre-commit.enabletrueEnable pre-commit
dev.treefmt.enabletrueEnable treefmt
Root-flake usage
nix
{
inputs = {
flake-parts.url = "github:hercules-ci/flake-parts";
dev-flake = {
url = "github:terlar/dev-flake";
inputs.flake-parts.follows = "flake-parts";
};
nixpkgs.url = "https://channels.nixos.org/nixos-unstable/nixexprs.tar.zst";
};
outputs = inputs:
inputs.flake-parts.lib.mkFlake { inherit inputs; } {
systems = [ "aarch64-darwin" "aarch64-linux" "x86_64-darwin" "x86_64-linux" ];
imports = [ inputs.dev-flake.flakeModule ];
dev.name = "my-project";
perSystem = { config, pkgs, ... }: {
# formatter is not set automatically — wire it up explicitly
formatter = config.treefmt.programs.nixfmt.package;
treefmt.programs.nixfmt = {
enable = true;
package = pkgs.nixfmt-rfc-style;
};
};
};
}
Sub-flake usage (recommended)

Isolate dev dependencies in ./dev/ so they don't pollute the main flake's closure. Use flake-parts partitions in the root flake to wire it in.

`./dev/flake.nix` — inputs only, no outputs:

nix
{
description = "Dependencies for development purposes";
inputs.dev-flake.url = "github:terlar/dev-flake";
outputs = _: { };
}

`./dev/flake-module.nix`:

nix
{ inputs, ... }: {
imports = [ inputs.dev-flake.flakeModule ];
dev.name = "my-project";
# dev.rootSrc = inputs.self.outPath; # set if self points to ./dev, not root
perSystem = { config, pkgs, ... }: {
formatter = config.treefmt.programs.nixfmt.package;
treefmt.programs.nixfmt = {
enable = true;
package = pkgs.nixfmt-rfc-style;
};
};
}

Root `flake.nix` — wire in via partitions:

nix
imports = [ inputs.flake-parts.flakeModules.partitions ];
partitionedAttrs = {
checks = "dev";
devShells = "dev";
};
partitions.dev = {
extraInputsFlake = ./dev;
module.imports = [ ./dev/flake-module.nix ];
};
Extending defaults

All underlying options from devshell, git-hooks-nix, and treefmt-nix remain fully accessible:

nix
perSystem = { ... }: {
pre-commit.settings.hooks.conform.enable = true;
treefmt.programs.mdsh.enable = true;
};

Security

  • Security scanPassed, 100 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
104
Repository forks
5
7-day trend score
23

Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.

Extension points

  • hookPre/post lifecycle hooks

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/terlar/nix-config/flake-parts/badge)](https://verified-skill.com/skills/terlar/nix-config/flake-parts)

Something wrong with this skill or its page? Tell us.