Last active
February 3, 2026 20:21
-
-
Save dacr/53e919e1f401cf1a1f5794a5f15bf9af to your computer and use it in GitHub Desktop.
nix data types / published by https://github.com/dacr/code-examples-manager #7e8ab042-cffa-4d78-bf37-21fc5bc024d6/69805f76f01f4ebfb7f733a08d132a13b84125c7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## summary : nix data types | |
| ## keywords : nix, data-types | |
| ## publish : gist | |
| ## authors : David Crosson | |
| ## license : Apache License Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0.txt) | |
| ## id : 7e8ab042-cffa-4d78-bf37-21fc5bc024d6 | |
| ## created-on : 2025-02-01T10:49:21+01:00 | |
| ## managed-by : https://github.com/dacr/code-examples-manager | |
| ## run-with : nix eval --file $file | |
| #### run-with : nix-instantiate --eval $file | |
| let | |
| a_int = 2; | |
| a_float = 40.0; | |
| a_null = null; | |
| a_bool = true; | |
| a_string = "truc"; | |
| a_multiline_string = '' | |
| truc1 | |
| truc2 | |
| ''; | |
| a_list = [ 42 "something" false ]; | |
| an_attribute_set = { | |
| a = "blah"; | |
| b = 42; | |
| c = true; | |
| d = { d0 = 0; d1 = 1; d2 = 2; }; | |
| }; | |
| a_recursive_attribute_set = rec { | |
| one = 1; | |
| two = one + 1; | |
| three = two + 1; | |
| }; | |
| a_lambda = x: y: x+y; # currying | |
| an_other_lambda = {x, y?0}: x+y; # With a default value for an attribute | |
| an_other_lambda_again = {x, y?0,...}: x+y; # We don't care of any extra attribute | |
| in { | |
| computed = | |
| a_int + | |
| a_float + | |
| an_attribute_set.d.d0 + | |
| (a_lambda 1 2) + | |
| (an_other_lambda {x=1;}) + | |
| (an_other_lambda_again {x=1;gloups=42;}) + | |
| ( (x: x * 2) 10) + # direct lambda call | |
| ( (attrset: attrset.v * 10) {v = 5;}) + # lambda with parameter taken into account as an attribute set | |
| ( ( {x, y}: x + y) {x=1; y=2;} ) # destructuring | |
| ; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment