Skip to content

Commit eaf8214

Browse files
committed
create an example nix file to help understand how nix works
0 parents  commit eaf8214

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

something.nix

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
}

0 commit comments

Comments
 (0)