Blog
Newest Info

nix-select

a pure and lazy query language in nix

Lassulus Core Developer
17 Feb 2025 · 2 min

Find it at: https://git.clan.lol/clan/select

Do you find accessing values from lists cumbersome? Is builtins.elemAt bringing you down? What about filtering nested dictionaries for specific keys?

For this reason, we hacked together an unmatched selection experience. It is written in pure Nix, without dependencies, to make your life 100% more “selectful.”

To use nix-select with the clan CLI, just run clan select.

Prominent features include:

  • Globs: *
  • {a,b} (set-based selection)
  • .0 (index-based access)

Example using the Clan CLI:

clan select 'nixosConfigurations.*.config.clan.core.vars.generators.*.files.*.{path,secret}'

This will print all variables defined in your Clan.

Here’s the equivalent non-selectful expression:

builtins.mapAttrs (
  _: v0:
  builtins.mapAttrs (
    _: v1:
    (builtins.mapAttrs (
      _: v3:
      builtins.intersectAttrs {
        path = { };
        secret = { };
      } v3
    ) v1.files)
  ) v0.config.clan.core.vars.generators
) nixosConfigurations

clan select also uses a transparent caching technique, so running the same command again will be significantly faster.

There are many more operators and constructs supported in nix-select, all of which are documented in the README.


Usage Without Clan

You can also import our 100% pure Nix library and use it directly in your project today!

To use it inside any nix repl:

nix-repl> select = (builtins.getFlake "github:clan-lol/select").lib.select

With this, the select function can be used by simply passing it a query string and an attribute set or list:

nix-repl> select "*.config.networking.hostName" nixosConfigurations

The query language is intentionally designed to be compatible with the Nix grammar, so it might be possible to extend the Nix expression language to improve ease of use.


This project was developed during Thaigersprint 2025.

Get started with our framework

With Clan you can create customized installation images, and skip time consuming manual installation steps