Home Explore Blog Models CI



nix

1st chunk of `doc/manual/source/language/types.md`
4e6ce8985f6db30d51fa8197a9695d6747166a69495b65bf0000000100000b2d
# Data Types

Every value in the Nix language has one of the following types:

* [Integer](#type-int)
* [Float](#type-float)
* [Boolean](#type-bool)
* [String](#type-string)
* [Path](#type-path)
* [Null](#type-null)
* [Attribute set](#type-attrs)
* [List](#type-list)
* [Function](#type-function)
* [External](#type-external)

## Primitives

### Integer {#type-int}

An _integer_ in the Nix language is a signed 64-bit integer.

Non-negative integers can be expressed as [integer literals](syntax.md#number-literal).
Negative integers are created with the [arithmetic negation operator](./operators.md#arithmetic).
The function [`builtins.isInt`](builtins.md#builtins-isInt) can be used to determine if a value is an integer.

### Float {#type-float}

A _float_ in the Nix language is a 64-bit [IEEE 754](https://en.wikipedia.org/wiki/IEEE_754) floating-point number.

Most non-negative floats can be expressed as [float literals](syntax.md#number-literal).
Negative floats are created with the [arithmetic negation operator](./operators.md#arithmetic).
The function [`builtins.isFloat`](builtins.md#builtins-isFloat) can be used to determine if a value is a float.

### Boolean {#type-bool}

A _boolean_ in the Nix language is one of _true_ or _false_.

<!-- TODO: mention the top-level environment -->

These values are available as attributes of [`builtins`](builtins.md#builtins-builtins) as [`builtins.true`](builtins.md#builtins-true) and [`builtins.false`](builtins.md#builtins-false).
The function [`builtins.isBool`](builtins.md#builtins-isBool) can be used to determine if a value is a boolean.

### String {#type-string}

A _string_ in the Nix language is an immutable, finite-length sequence of bytes, along with a [string context](string-context.md).
Nix does not assume or support working natively with character encodings.

String values without string context can be expressed as [string literals](string-literals.md).
The function [`builtins.isString`](builtins.md#builtins-isString) can be used to determine if a value is a string.

### Path {#type-path}

A _path_ in the Nix language is an immutable, finite-length sequence of bytes starting with `/`, representing a POSIX-style, canonical file system path.
Path values are distinct from string values, even if they contain the same sequence of bytes.
Operations that produce paths will simplify the result as the standard C function [`realpath`] would, except that there is no symbolic link resolution.


Paths are suitable for referring to local files, and are often preferable over strings.
- Path values do not contain trailing or duplicate slashes, `.`, or `..`.
- Relative path literals are automatically resolved relative to their [base directory].
- Tooling can recognize path literals and provide additional features, such as autocompletion, refactoring automation and jump-to-file.

Title: Nix Language Data Types and Primitives
Summary
This document outlines the fundamental data types in the Nix language, which include Integer, Float, Boolean, String, Path, Null, Attribute Set, List, Function, and External. It then delves into the 'Primitive' types, describing each in detail: Integers are signed 64-bit numbers; Floats are 64-bit IEEE 754 floating-point numbers; Booleans are `true` or `false` values; Strings are immutable sequences of bytes with a string context, not assuming character encodings; and Paths are immutable, canonical POSIX-style file system paths, distinct from strings, suitable for referring to local files due to their canonicalization and tooling benefits.