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 messages
baseNameOf s
- basenameᛦ of strings
derivation attrs
- Nix derivationsᛦdirOf s
- dirnameᛦ of strings
fetchTarball url
- fetchTarballᛦimport path
- Nix import keywordᛦmap f list
- applyf
to each element oflist
removeAttrs set list
- Remove the attributes with keys inlist
fromset
throw s
- Throw an error messages
. Usually works likeabort
, but won’t breaknix-env
toString e
- Convert the expressione
to, wheree
is 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 off
and whose values are booleans indicating whether a default is set for each oneisFunction e
-true
ife
is a function, otherwisefalse
Fetching
Packaging
compareVersions s1 s2
- Compare two version strings.-1
ifs1 < s2
,0
ifs1 == s2
,1
ifs1 > s2
filterSource e1 e2
- filterSourceᛦhashFile type p
- Return a base-16 representation of the cryptographic hash of the file at pathp
under algorithmtype
, one ofmd5
orsha1/256/512
parseDrvName s
- splits
into{ 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 variables
typeOf e
- return a string representing the type ofe
as 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 ofe1
trace e1 e2
- evaluatee1
, print its abstract syntax to stderr, then returne2
tryEval e
- return{ success ? false, value ? false }
, withsucess
settrue
andvalue
set toe
ife
evaluates successfully