Nix builtins
Nix exposes a minimal set of unprefixed builtins to avoid a crowded namespace. These functions, and all other builtins, are also available under the builtins namespace.
Since the set builtins contains all the built-in functions and other values, it can be used with Nix operatorsᛦ like ? to provide graceful fallback settings for older versions of Nix.
Unprefixed
abort s- abort evaluation with messagesbaseNameOf s- basenameᛦ of stringsderivation attrs- Nix derivationsᛦdirOf s- dirnameᛦ of stringsfetchTarball url- fetchTarballᛦimport path- Nix import keywordᛦmap f list- applyfto each element oflistremoveAttrs set list- Remove the attributes with keys inlistfromsetthrow s- Throw an error messages. Usually works likeabort, but won’t breaknix-envtoString e- Convert the expressioneto, whereeis one of:- a string - no change
- a path - quotes the path
- a set containing a
__toString = self: ...attribute - an integer
- a list - joined with spaces
- a boolean -
""forfalse,"1"fortrue null-""
Prefixed
- Nix numeric builtinsᛦ
- Nix boolean builtinsᛦ
- Nix string builtinsᛦ
- Nix path builtinsᛦ
- Nix list builtinsᛦ
- Nix set builtinsᛦ
Functions
functionArgs f- Return a set whose keys are the formal parameters offand whose values are booleans indicating whether a default is set for each oneisFunction e-trueifeis a function, otherwisefalse
Fetching
Packaging
compareVersions s1 s2- Compare two version strings.-1ifs1 < s2,0ifs1 == s2,1ifs1 > s2filterSource e1 e2- filterSourceᛦhashFile type p- Return a base-16 representation of the cryptographic hash of the file at pathpunder algorithmtype, one ofmd5orsha1/256/512parseDrvName s- splitsinto{ name, version }splitVersion s- split a version string into its components
Values
currentSystem- platform identifier for the system on which the expression is being evaluatedgetEnv s- gets the environment variablestypeOf e- return a string representing the type ofeas in Nix valuesᛦ
Evaluation
deepSeq e1 e2- likeseq, bute1’s elements are evaluated recursively if it’s a list or setseq e1 e2- Evaluatee1, then evaluate and returne2; this ensures strict evaluation in the value ofe1trace e1 e2- evaluatee1, print its abstract syntax to stderr, then returne2tryEval e- return{ success ? false, value ? false }, withsucesssettrueandvalueset toeifeevaluates successfully