mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-23 09:41:36 +00:00
[nix/en] Updates for Nix 2.2.0
- nix-repl now deprecated, Nix 2 has `nix repl` - nix language now has floats, and type-preserving arithmetic - add note about immutable sets' attributes being un-redefinable - descendant sets can now have attributes added to them - fix editing loose ene in the Impurity section
This commit is contained in:
parent
4e8e92eb0e
commit
efcd37612d
@ -4,6 +4,7 @@ filename: learn.nix
|
|||||||
contributors:
|
contributors:
|
||||||
- ["Chris Martin", "http://chris-martin.org/"]
|
- ["Chris Martin", "http://chris-martin.org/"]
|
||||||
- ["Rommel Martinez", "https://ebzzry.io"]
|
- ["Rommel Martinez", "https://ebzzry.io"]
|
||||||
|
- ["Javier Candeira", "https://candeira.com/"]
|
||||||
---
|
---
|
||||||
|
|
||||||
Nix is a simple functional language developed for the
|
Nix is a simple functional language developed for the
|
||||||
@ -12,7 +13,7 @@ Nix is a simple functional language developed for the
|
|||||||
|
|
||||||
You can evaluate Nix expressions using
|
You can evaluate Nix expressions using
|
||||||
[nix-instantiate](https://nixos.org/nix/manual/#sec-nix-instantiate)
|
[nix-instantiate](https://nixos.org/nix/manual/#sec-nix-instantiate)
|
||||||
or [`nix-repl`](https://github.com/edolstra/nix-repl).
|
or [`nix repl`](https://nixos.org/nix/manual/#ssec-relnotes-2.0).
|
||||||
|
|
||||||
```
|
```
|
||||||
with builtins; [
|
with builtins; [
|
||||||
@ -39,18 +40,26 @@ with builtins; [
|
|||||||
#=> "a"
|
#=> "a"
|
||||||
|
|
||||||
|
|
||||||
# Integers
|
# Integers and Floats
|
||||||
#=========================================
|
#=========================================
|
||||||
|
|
||||||
# Integers are the only numeric type.
|
# There are two numeric types: integers and floats
|
||||||
|
|
||||||
1 0 42 (-3) # Some integers
|
1 0 42 (-3) # Some integers
|
||||||
|
|
||||||
|
123.43 .27e13 # A couple of floats
|
||||||
|
|
||||||
|
# Operations will preserve numeric type
|
||||||
|
|
||||||
(4 + 6 + 12 - 2) # Addition
|
(4 + 6 + 12 - 2) # Addition
|
||||||
#=> 20
|
#=> 20
|
||||||
|
(4 - 2.5)
|
||||||
|
#=> 1.5
|
||||||
|
|
||||||
(7 / 2) # Division
|
(7 / 2) # Division
|
||||||
#=> 3
|
#=> 3
|
||||||
|
(7 / 2.0)
|
||||||
|
#=> 3.5
|
||||||
|
|
||||||
|
|
||||||
# Strings
|
# Strings
|
||||||
@ -238,13 +247,20 @@ with builtins; [
|
|||||||
}.a.c
|
}.a.c
|
||||||
#=> { d = 2; e = 3; }
|
#=> { d = 2; e = 3; }
|
||||||
|
|
||||||
# An attribute's descendants cannot be assigned in this
|
# Sets are immutable, so you can't redefine an attribute:
|
||||||
# way if the attribute itself has been directly assigned.
|
{
|
||||||
|
a = { b = 1; };
|
||||||
|
a.b = 2;
|
||||||
|
}
|
||||||
|
#=> attribute 'a.b' at (string):3:5 already defined at (string):2:11
|
||||||
|
|
||||||
|
# However, an attribute's set members can also be defined piecewise
|
||||||
|
# way even if the attribute itself has been directly assigned.
|
||||||
{
|
{
|
||||||
a = { b = 1; };
|
a = { b = 1; };
|
||||||
a.c = 2;
|
a.c = 2;
|
||||||
}
|
}
|
||||||
#=> error: attribute ‘a’ already defined
|
#=> { a = { b = 1; c = 2; }; }
|
||||||
|
|
||||||
|
|
||||||
# With
|
# With
|
||||||
@ -321,8 +337,8 @@ with builtins; [
|
|||||||
#=========================================
|
#=========================================
|
||||||
|
|
||||||
# Because repeatability of builds is critical to the Nix package
|
# Because repeatability of builds is critical to the Nix package
|
||||||
# manager, in which, functional purity is emphasized in the Nix
|
# manager, functional purity is emphasized in the Nix language
|
||||||
# language. But there are a few impurities.
|
# used to describe Nix packages. But there are a few impurities.
|
||||||
|
|
||||||
# You can refer to environment variables.
|
# You can refer to environment variables.
|
||||||
(getEnv "HOME")
|
(getEnv "HOME")
|
||||||
|
Loading…
Reference in New Issue
Block a user