forked from zhaofengli/colmena
1.5 kB · 49 lines
Markdown
at cli

Ad Hoc Evaluation #

Sometimes you may want to extract values from your Hive configuration for consumption in another program (e.g., OctoDNS). To do that, create a .nix file with a lambda:

{ nodes, pkgs, lib, ... }:
# Feels like a NixOS module - But you can return any JSON-serializable value
lib.attrsets.mapAttrs (k: v: v.config.deployment.targetHost) nodes

Then you can obtain a JSON output with:

$ colmena eval target-hosts.nix
{"alpha":"fd12:3456::1","beta":"fd12:3456::2"}

On a flake hive, the file is evaluated as text under pure evaluation, which means relative paths in it resolve against the working directory and cannot be read, and error positions refer to the expression, unless --impure is passed.

You can also specify an expression directly on the command line:

$ colmena eval -E '{ nodes, pkgs, lib, ... }: ...'

Instantiation #

You may directly instantiate an expression that evaluates to a derivation:

$ colmena eval --instantiate -E '{ nodes, ... }: nodes.alpha.config.boot.kernelPackages.kernel'
/nix/store/7ggmhnwvywrqcd1z2sdpan8afz55sw7z-linux-5.14.14.drv

Interactive REPL #

To explore the configurations interactively, start a REPL session with colmena repl:

$ colmena repl
[INFO ] Using flake: git+file:///home/user/cluster
Welcome to Nix 2.10.3. Type :? for help.

Loading installable ''...
Added 3 variables.
nix-repl> nodes.alpha.config.deployment.targetHost
"fd12:3456::1"