glistix/nix

Library for interacting with Nix built-in types and functions.

Types

pub type TypeOf {
  IntType
  BoolType
  StringType
  PathType
  NullType
  SetType
  ListType
  LambdaType
  FloatType
}

Constructors

  • IntType
  • BoolType
  • StringType
  • PathType
  • NullType
  • SetType
  • ListType
  • LambdaType
  • FloatType

Functions

pub fn deep_eval(expression: a) -> a

Evaluates the expression strictly, recursively.

Nix is lazy by default, so most values aren’t actually computed until prompted to by evaluation. This function can be used to force a value (one of the parameters) to be recursively evaluated upon evaluation. That is, once this function is called, the given value and any values within it (such as list items or attribute set values) are also evaluated. This is used to ensure side-effects, such as printing (through trace) or panics, are applied even from within data structures.

Please note that misusing this function may result in performance losses, or even infinite recursion with infinite data structures.

Examples

{
  deep_eval([panic as "Bad")])
  "Unreachable here"

  10
}
// -> error: Bad
pub fn typeof(of subject: a) -> TypeOf

Gets the Nix type of a value.

Note that this function works with the value’s representation within Nix, and so the returned type shouldn’t be associated with a particular Gleam type, as Gleam types might be represented by different Nix types.

Search Document