File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change
1
+ # example.nix
2
+ # This is a simple example Nix file demonstrating basic Nix concepts
3
+
4
+ # Define some variables
5
+ let
6
+ # Basic variable assignment
7
+ greeting = "Hello, Nix!" ;
8
+
9
+ # List of numbers
10
+ numbers = [ 1 2 3 4 5 ] ;
11
+
12
+ # Attribute set (similar to a dictionary/object)
13
+ config = {
14
+ name = "example" ;
15
+ version = "1.0.0" ;
16
+ dependencies = [ "nix" "nixpkgs" ] ;
17
+ } ;
18
+
19
+ # Function definition
20
+ add = a : b : a + b ;
21
+ in
22
+ # The main expression that gets evaluated
23
+ {
24
+ # Basic string
25
+ message = greeting ;
26
+
27
+ # Using the function
28
+ sum = add 5 3 ;
29
+
30
+ # List operations
31
+ firstNumber = builtins . head numbers ;
32
+ allNumbers = numbers ;
33
+
34
+ # Accessing attribute set
35
+ projectName = config . name ;
36
+ projectVersion = config . version ;
37
+
38
+ # Using built-in functions
39
+ currentTime = builtins . currentTime ;
40
+
41
+ # Conditional expression
42
+ isEven = if builtins . mod 4 2 == 0 then true else false ;
43
+
44
+ # List transformation using builtins.map
45
+ doubledNumbers = builtins . map ( x : x * 2 ) numbers ;
46
+ }
You can’t perform that action at this time.
0 commit comments