[Init] - adding version control for docs and tutorial follow up
This commit is contained in:
commit
be389d2723
2
adhoc-env.bash
Normal file
2
adhoc-env.bash
Normal file
@ -0,0 +1,2 @@
|
||||
#!/usr/bin/env nix-shell
|
||||
#! nix-shell -p git neovim nodejs
|
13
nix-language/AttributeSets/attributeAccess.nix
Normal file
13
nix-language/AttributeSets/attributeAccess.nix
Normal file
@ -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; }
|
14
nix-language/AttributeSets/attributeSet.nix
Normal file
14
nix-language/AttributeSets/attributeSet.nix
Normal file
@ -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
|
||||
}
|
12
nix-language/AttributeSets/recursiveAttribute.nix
Normal file
12
nix-language/AttributeSets/recursiveAttribute.nix
Normal file
@ -0,0 +1,12 @@
|
||||
rec {
|
||||
one = 1;
|
||||
two = one + 1;
|
||||
three = two + 1;
|
||||
}
|
||||
|
||||
# failing counter-example
|
||||
#{
|
||||
# one = 1;
|
||||
# two = one + 1;
|
||||
# three = two + 1;
|
||||
#}
|
3
nix-language/Derivations/default.nix
Normal file
3
nix-language/Derivations/default.nix
Normal file
@ -0,0 +1,3 @@
|
||||
let
|
||||
pkgs = import <nixpkgs> {};
|
||||
in "${pkgs.nix}"
|
5
nix-language/Dockerfile
Normal file
5
nix-language/Dockerfile
Normal file
@ -0,0 +1,5 @@
|
||||
FROM nixos/nix
|
||||
|
||||
RUN nix-channel --updates
|
||||
|
||||
# RUN nix-build -A pythonFull '<nixpkgs>'
|
2
nix-language/FileSystemPaths/LookupPaths/default.nix
Normal file
2
nix-language/FileSystemPaths/LookupPaths/default.nix
Normal file
@ -0,0 +1,2 @@
|
||||
# other name is "angle bracket syntax"
|
||||
<nixpkgs>
|
1
nix-language/FileSystemPaths/LookupPaths/lib.nix
Normal file
1
nix-language/FileSystemPaths/LookupPaths/lib.nix
Normal file
@ -0,0 +1 @@
|
||||
<nixpkgs/lib>
|
1
nix-language/FileSystemPaths/absolute.nix
Normal file
1
nix-language/FileSystemPaths/absolute.nix
Normal file
@ -0,0 +1 @@
|
||||
/absolute/path
|
1
nix-language/FileSystemPaths/currentDir.nix
Normal file
1
nix-language/FileSystemPaths/currentDir.nix
Normal file
@ -0,0 +1 @@
|
||||
./.
|
1
nix-language/FileSystemPaths/parentDir.nix
Normal file
1
nix-language/FileSystemPaths/parentDir.nix
Normal file
@ -0,0 +1 @@
|
||||
../.
|
1
nix-language/FileSystemPaths/relative.2.nix
Normal file
1
nix-language/FileSystemPaths/relative.2.nix
Normal file
@ -0,0 +1 @@
|
||||
relative/path
|
1
nix-language/FileSystemPaths/relative.nix
Normal file
1
nix-language/FileSystemPaths/relative.nix
Normal file
@ -0,0 +1 @@
|
||||
./relative
|
1
nix-language/FunctionLibraries/addOne.nix
Normal file
1
nix-language/FunctionLibraries/addOne.nix
Normal file
@ -0,0 +1 @@
|
||||
x: x + 1
|
1
nix-language/FunctionLibraries/addOneAndTwo.nix
Normal file
1
nix-language/FunctionLibraries/addOneAndTwo.nix
Normal file
@ -0,0 +1 @@
|
||||
1 + 2
|
1
nix-language/FunctionLibraries/builtins.nix
Normal file
1
nix-language/FunctionLibraries/builtins.nix
Normal file
@ -0,0 +1 @@
|
||||
builtins.toString
|
1
nix-language/FunctionLibraries/import.nix
Normal file
1
nix-language/FunctionLibraries/import.nix
Normal file
@ -0,0 +1 @@
|
||||
import ./addOneAndTwo.nix
|
1
nix-language/FunctionLibraries/importImmediately.nix
Normal file
1
nix-language/FunctionLibraries/importImmediately.nix
Normal file
@ -0,0 +1 @@
|
||||
import ./addOne.nix 1
|
8
nix-language/FunctionLibraries/pkgs.lib.nix
Normal file
8
nix-language/FunctionLibraries/pkgs.lib.nix
Normal file
@ -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; }
|
1
nix-language/Functions/AttributeSetArgument/default.nix
Normal file
1
nix-language/Functions/AttributeSetArgument/default.nix
Normal file
@ -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; }
|
4
nix-language/Functions/AttributeSetArgument/example.nix
Normal file
4
nix-language/Functions/AttributeSetArgument/example.nix
Normal file
@ -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
|
4
nix-language/Functions/CallingFunctions/functionCall.nix
Normal file
4
nix-language/Functions/CallingFunctions/functionCall.nix
Normal file
@ -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
|
1
nix-language/Functions/MultipleArgs/default.nix
Normal file
1
nix-language/Functions/MultipleArgs/default.nix
Normal file
@ -0,0 +1 @@
|
||||
x: y: x + y
|
1
nix-language/Functions/MultipleArgs/twoArgFunction.nix
Normal file
1
nix-language/Functions/MultipleArgs/twoArgFunction.nix
Normal file
@ -0,0 +1 @@
|
||||
x: y: x + y
|
1
nix-language/Functions/attributeSetArg.nix
Normal file
1
nix-language/Functions/attributeSetArg.nix
Normal file
@ -0,0 +1 @@
|
||||
{ a, b }: a + b
|
@ -0,0 +1 @@
|
||||
{ a, b, ...}: a + b
|
1
nix-language/Functions/attributeSetArg.withDefault.nix
Normal file
1
nix-language/Functions/attributeSetArg.withDefault.nix
Normal file
@ -0,0 +1 @@
|
||||
{ a, b ? 0 }: a + b
|
1
nix-language/Functions/default.nix
Normal file
1
nix-language/Functions/default.nix
Normal file
@ -0,0 +1 @@
|
||||
x: x + 1
|
1
nix-language/Functions/multipleArgs.nesting.nix
Normal file
1
nix-language/Functions/multipleArgs.nesting.nix
Normal file
@ -0,0 +1 @@
|
||||
x: y: x + y
|
3
nix-language/Functions/nameAttributeSetArg.nix
Normal file
3
nix-language/Functions/nameAttributeSetArg.nix
Normal file
@ -0,0 +1,3 @@
|
||||
args@{ a,b,... }: a + b + args.c
|
||||
# or
|
||||
#{ a,b,...}@args: a + b + args.c
|
3
nix-language/Functions/namedFunction.nix
Normal file
3
nix-language/Functions/namedFunction.nix
Normal file
@ -0,0 +1,3 @@
|
||||
let
|
||||
f = x: x + 1;
|
||||
in f
|
1
nix-language/Functions/singleArgument.nix
Normal file
1
nix-language/Functions/singleArgument.nix
Normal file
@ -0,0 +1 @@
|
||||
x; x + 1
|
1
nix-language/Impurities/data
Normal file
1
nix-language/Impurities/data
Normal file
@ -0,0 +1 @@
|
||||
123
|
1
nix-language/Impurities/fetchers.nix
Normal file
1
nix-language/Impurities/fetchers.nix
Normal file
@ -0,0 +1 @@
|
||||
builtins.fetchurl "https://github.com/NixOS/nix/archive/7c3ab5751568a0bc63430b33a5169c5e4784a0ff.tar.gz"
|
1
nix-language/Impurities/fetchers.tarball.nix
Normal file
1
nix-language/Impurities/fetchers.tarball.nix
Normal file
@ -0,0 +1 @@
|
||||
builtins.fetchTarball "https://github.com/NixOS/nix/archive/7c3ab5751568a0bc63430b33a5169c5e4784a0ff.tar.gz"
|
4
nix-language/Impurities/paths.nix
Normal file
4
nix-language/Impurities/paths.nix
Normal file
@ -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}"
|
5
nix-language/IndentedStrings/default.nix
Normal file
5
nix-language/IndentedStrings/default.nix
Normal file
@ -0,0 +1,5 @@
|
||||
''
|
||||
multi
|
||||
line
|
||||
string
|
||||
''
|
5
nix-language/IndentedStrings/defaultWithSpaces.nix
Normal file
5
nix-language/IndentedStrings/defaultWithSpaces.nix
Normal file
@ -0,0 +1,5 @@
|
||||
''
|
||||
one
|
||||
two
|
||||
three
|
||||
''
|
30
nix-language/Inheritance/inheritance.nix
Normal file
30
nix-language/Inheritance/inheritance.nix
Normal file
@ -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
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)
|
9
nix-language/WorkedExamples/nixosConfig.nix
Normal file
9
nix-language/WorkedExamples/nixosConfig.nix
Normal file
@ -0,0 +1,9 @@
|
||||
{ config, pkgs, ... }: {
|
||||
|
||||
imports = [ ./hardware-configuration.nix ];
|
||||
|
||||
environment.systemPackages = with pkgs; [ git ];
|
||||
|
||||
# ...
|
||||
|
||||
}
|
18
nix-language/WorkedExamples/package.nix
Normal file
18
nix-language/WorkedExamples/package.nix
Normal file
@ -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;
|
||||
};
|
||||
|
||||
}
|
10
nix-language/WorkedExamples/shellEnv.nix
Normal file
10
nix-language/WorkedExamples/shellEnv.nix
Normal file
@ -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
1
nix-language/abc.nix
Normal file
@ -0,0 +1 @@
|
||||
{ a.b.c = 1; }
|
1
nix-language/default.nix
Normal file
1
nix-language/default.nix
Normal file
@ -0,0 +1 @@
|
||||
1 + 2
|
4
nix-language/letin.nix
Normal file
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
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;
|
||||
#}
|
10
nix-language/notesOnWhitespace.nix
Normal file
10
nix-language/notesOnWhitespace.nix
Normal file
@ -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
|
1
nix-language/oneAndTwo.nix
Normal file
1
nix-language/oneAndTwo.nix
Normal file
@ -0,0 +1 @@
|
||||
1 + 2
|
5
nix-language/stringInterpolation/confusionWithShell.nix
Normal file
5
nix-language/stringInterpolation/confusionWithShell.nix
Normal file
@ -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}"
|
4
nix-language/stringInterpolation/stringInterpolation.nix
Normal file
4
nix-language/stringInterpolation/stringInterpolation.nix
Normal file
@ -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
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
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 .
|
Loading…
Reference in New Issue
Block a user