[Init] - adding version control for docs and tutorial follow up

This commit is contained in:
adnanioricce 2024-08-14 14:02:08 -03:00
commit be389d2723
68 changed files with 328 additions and 0 deletions

2
adhoc-env.bash Normal file

@ -0,0 +1,2 @@
#!/usr/bin/env nix-shell
#! nix-shell -p git neovim nodejs

@ -0,0 +1,13 @@
let
attrset = { x = 1; };
in
attrset.x
# nested attributes
#let
# attrset2 = { a = { b = { c = 1; }; }; };
#in
#attrset2.a.b.c
# nested expression with dot notation
#{ a.b.c = 1; }

@ -0,0 +1,14 @@
{
string = "hello";
integer = 1;
float = 3.141;
bool = true;
null = null;
list = [ 1 "two" false ];
attribute-set = {
a = "hello";
b = 2;
c = 2.718;
d = false;
}; # comments are supported
}

@ -0,0 +1,12 @@
rec {
one = 1;
two = one + 1;
three = two + 1;
}
# failing counter-example
#{
# one = 1;
# two = one + 1;
# three = two + 1;
#}

@ -0,0 +1,3 @@
let
pkgs = import <nixpkgs> {};
in "${pkgs.nix}"

5
nix-language/Dockerfile Normal file

@ -0,0 +1,5 @@
FROM nixos/nix
RUN nix-channel --updates
# RUN nix-build -A pythonFull '<nixpkgs>'

@ -0,0 +1,2 @@
# other name is "angle bracket syntax"
<nixpkgs>

@ -0,0 +1 @@
<nixpkgs/lib>

@ -0,0 +1 @@
/absolute/path

@ -0,0 +1 @@
./.

@ -0,0 +1 @@
../.

@ -0,0 +1 @@
relative/path

@ -0,0 +1 @@
./relative

@ -0,0 +1 @@
x: x + 1

@ -0,0 +1 @@
1 + 2

@ -0,0 +1 @@
builtins.toString

@ -0,0 +1 @@
import ./addOneAndTwo.nix

@ -0,0 +1 @@
import ./addOne.nix 1

@ -0,0 +1,8 @@
# The nixpkgs repository contains an attribute set called lib,
# which provides a large number of useful functions.
# They are implemented in the Nix language
# , as opposed to builtins, which are part of the language itself.
let
pkgs = import <nixpkgs> {};
in
pkgs.lib.strings.toUpper "lookup paths considered harmful"

@ -0,0 +1,5 @@
let
f = { a, b, ... }: a + b;
in
f { a = 1; b = 2; c = 3; }

@ -0,0 +1 @@
{a, b, ...}: a + b

@ -0,0 +1,4 @@
let
f = {a, b}: a + b;
in
f { a = 1; b = 2; c = 3; }

@ -0,0 +1 @@
{a, b}: a + b

@ -0,0 +1,4 @@
let
f = {a ? 0, b ? 0}: a + b;
in
f { } # empty attribute set

@ -0,0 +1,4 @@
let
f = {a, b ? 0}: a + b;
in
f { a = 1; }

@ -0,0 +1,4 @@
let
f = {a, b}: a + b;
in
f { a = 1; b = 2; }

@ -0,0 +1,5 @@
# args@{a,b,...}: a + b + args.c
let
f = {a, b, ...}@args: a + b + args.c;
in
f { a = 1; b = 2; c = 3; }

@ -0,0 +1 @@
{a,b,...}@args: a + b + args.c

@ -0,0 +1,5 @@
let
f = x: x.a;
v = { a = 1; };
in
f v

@ -0,0 +1,4 @@
let
f = x: x.a;
in
f {a = 1; }

@ -0,0 +1 @@
(x: x + 1) 1

@ -0,0 +1,6 @@
let
f = x: x + 1;
a = 1;
in
# placing f and a on the list
[ f a ]

@ -0,0 +1,7 @@
let
f = x: x + 1;
a = 1;
in
# applies f to a
[ (f a) ]

@ -0,0 +1,4 @@
let
f = x: y: x + y;
in
f 1

@ -0,0 +1,4 @@
let
f = x: y: x + y;
in
f 1 2

@ -0,0 +1 @@
x: y: x + y

@ -0,0 +1 @@
x: y: x + y

@ -0,0 +1 @@
{ a, b }: a + b

@ -0,0 +1 @@
{ a, b, ...}: a + b

@ -0,0 +1 @@
{ a, b ? 0 }: a + b

@ -0,0 +1 @@
x: x + 1

@ -0,0 +1 @@
x: y: x + y

@ -0,0 +1,3 @@
args@{ a,b,... }: a + b + args.c
# or
#{ a,b,...}@args: a + b + args.c

@ -0,0 +1,3 @@
let
f = x: x + 1;
in f

@ -0,0 +1 @@
x; x + 1

@ -0,0 +1 @@
123

@ -0,0 +1 @@
builtins.fetchurl "https://github.com/NixOS/nix/archive/7c3ab5751568a0bc63430b33a5169c5e4784a0ff.tar.gz"

@ -0,0 +1 @@
builtins.fetchTarball "https://github.com/NixOS/nix/archive/7c3ab5751568a0bc63430b33a5169c5e4784a0ff.tar.gz"

@ -0,0 +1,4 @@
#For directories the same thing happens:
#The entire directory (including nested files and directories) is copied to the Nix store
#,and the evaluated string becomes the Nix store path of the directory.
"${./data}"

@ -0,0 +1,5 @@
''
multi
line
string
''

@ -0,0 +1,5 @@
''
one
two
three
''

@ -0,0 +1,30 @@
#inherit is shorthand for assigning the value of a name from an existing scope
#to the same name in a nested scope.
#It is for convenience to avoid repeating the same name multiple times.
let
x = 1;
y = 2;
in
{
inherit x y;
}
# the fragment ```inherit x y;``` is equivalent to:
# ``` x = x;y = y;
# It is also possible to inherit names from a specific attribute set with parentheses (inherit (...) ...).
#let
# a = { x = 1; y = 2; };
#in
#{
# inherit (a) x y;
#}
# The fragment
#inherit (a) x y;
# is equivalent to
#x = a.x; y = a.y;
# inherit also work inside ``let`` expressions.
#let
# inherit ({ x = 1; y = 2; }) x y;
#in [ x y ]

2
nix-language/README.md Normal file

@ -0,0 +1,2 @@
# Nix Language Learn
This folder has some files copied from the [nix tutorial](https://nix.dev/tutorials/nix-language.html). For more, search the [nix manual](https://nix.dev/manual/nix/2.18/language/index.html)

@ -0,0 +1,9 @@
{ config, pkgs, ... }: {
imports = [ ./hardware-configuration.nix ];
environment.systemPackages = with pkgs; [ git ];
# ...
}

@ -0,0 +1,18 @@
{ lib, stdenv, fetchurl }:
stdenv.mkDerivation rec {
pname = "hello";
version = "2.12";
src = fetchurl {
url = "mirror://gnu/${pname}/${pname}-${version}.tar.gz";
sha256 = "1ayhp9v4m4rdhjmnl2bq3cibrbqqkgjbl3s7yk2nhlh8vj3ay16g";
};
meta = with lib; {
license = licenses.gpl3Plus;
};
}

@ -0,0 +1,10 @@
{ pkgs ? import <nixpkgs> {} }:
let
message = "hello world";
in
pkgs.mkShellNoCC {
packages = with pkgs; [ cowsay ];
shellHook = ''
cowsay ${message}
'';
}

1
nix-language/abc.nix Normal file

@ -0,0 +1 @@
{ a.b.c = 1; }

1
nix-language/default.nix Normal file

@ -0,0 +1 @@
1 + 2

4
nix-language/letin.nix Normal file

@ -0,0 +1,4 @@
let
a = 1;
in
a + a

26
nix-language/letin_ab.nix Normal file

@ -0,0 +1,26 @@
let
b = a + 1;
a = 1;
in
a + b
# Alternatives:
# with rec
#rec {
# b = a + 1;
# c = a + b;
# a = 1;
#}
# lists
#rec {
# b = a + 1;
# c = a + b;
# a = 1;
#}
# failing counter-exmaple
#{
# a = let x = 1; in x;
# b = x;
#}

@ -0,0 +1,10 @@
# White space is used to delimit lexical tokens, where required. It is otherwise insignificant.
# Line breaks, indentation, and additional spaces are for readers' convenience.
# the following are equivalent
#let
# x = 1;
# y = 2;
# in x + y
let a=1;b=2;in a+b

@ -0,0 +1 @@
1 + 2

@ -0,0 +1,5 @@
# the $out is a shell script variable
let
out = "Nix";
in
"echo ${out} > $out"

@ -0,0 +1,4 @@
let
x = 1;
in
"${x} + ${x} = ${x + x}"

@ -0,0 +1,4 @@
let
name = "Nix";
in
"hello ${name}"

@ -0,0 +1,4 @@
let
a = "no";
in
"${a + " ${a + " ${a}"}"}"

32
nix-language/with.nix Normal file

@ -0,0 +1,32 @@
let
a = {
x = 1;
y = 2;
z = 3;
};
in
with a; [ x y z ]
# The following is equivalent to the previous expression
# let
# a = {
# x = 1;
# y = 2;
# z = 3;
# };
# in
# [ a.x a.y a.z ]
# Failing counter exmaple
#let
# a = {
# x = 1;
# y = 2;
# z = 3;
# };
#in
#{
# b = with a; [ x y z ];
# c = x;
#}

6
nixpkgs-releases.sh Executable file

@ -0,0 +1,6 @@
#!/usr/bin/env nix-shell
#! nix-shell -i bash --pure
#! nix-shell -p bash cacert curl jq python3Packages.xmljson
#! nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs/archive/2a601aafdc5605a5133a2ca506a34a3a73377247.tar.gz
curl https://github.com/NixOS/nixpkgs/releases.atom | xml2json | jq .