presentations_compsoc/src/slides/skynet/3_nix.md

166 lines
4.5 KiB
Markdown
Raw Normal View History

2023-10-14 17:20:33 +01:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2023-10-08 13:29:27 +01:00
title = "Skynet: Nix"
date = 2023-10-08
2023-10-08 13:38:26 +01:00
slides = true
2023-10-14 17:20:33 +01:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2023-10-08 13:29:27 +01:00
# *nix, Nix and Nixos
2023-10-14 17:20:33 +01:00
-------------------------------------------------------------------------
2023-10-08 13:29:27 +01:00
## *nix
2023-10-14 17:20:33 +01:00
-------------------------------------------------------------------------
2023-10-08 13:29:27 +01:00
Skynet runs on a flavor of Linux called NixOS
2023-10-14 17:20:33 +01:00
-------------------------------------------------------------------------
2023-10-08 13:29:27 +01:00
Normal linux commands apply (basic primer)
2023-10-14 17:20:33 +01:00
-------------------------------------------------------------------------
2023-10-08 13:29:27 +01:00
``cd`` - change directory
2023-10-14 17:20:33 +01:00
-------------------------------------------------------------------------
2023-10-08 13:29:27 +01:00
``mkdir`` - make directory
2023-10-14 17:20:33 +01:00
-------------------------------------------------------------------------
2023-10-08 13:29:27 +01:00
``ls`` - list directory
2023-10-14 17:20:33 +01:00
-------------------------------------------------------------------------
2023-10-08 13:29:27 +01:00
``touch {filename}`` - create file named {filename}
2023-10-14 17:20:33 +01:00
-------------------------------------------------------------------------
2023-10-08 13:29:27 +01:00
``nano {filename}`` - edit {filename}
2023-10-14 17:20:33 +01:00
-------------------------------------------------------------------------
2023-10-08 13:29:27 +01:00
``history`` - view history of previous commands
2023-10-14 17:20:33 +01:00
-------------------------------------------------------------------------
2023-10-08 13:29:27 +01:00
``grep "{query}" {filename/path}`` - find {query} in a file
2023-10-14 17:20:33 +01:00
-------------------------------------------------------------------------
2023-10-08 13:29:27 +01:00
2023-10-14 17:20:33 +01:00
There is also piping where:
The output of one command is piped into another command
2023-10-08 13:29:27 +01:00
2023-10-14 17:20:33 +01:00
-------------------------------------------------------------------------
2023-10-08 13:29:27 +01:00
Often called [Unix philosophy][1]
2023-10-14 17:20:33 +01:00
-------------------------------------------------------------------------
2023-10-08 13:29:27 +01:00
Can make really powerful programs from smaller simple programs.
2023-10-14 17:20:33 +01:00
-------------------------------------------------------------------------
2023-10-08 13:29:27 +01:00
``history | grep "nano"`` - search the history for any mention of ``nano``
2023-10-14 17:20:33 +01:00
-------------------------------------------------------------------------
2023-10-08 13:29:27 +01:00
## Nix
2023-10-14 17:20:33 +01:00
-------------------------------------------------------------------------
2023-10-08 13:29:27 +01:00
Nix is a (lazy) functional language
2023-10-14 17:20:33 +01:00
-------------------------------------------------------------------------
2023-10-08 13:29:27 +01:00
```nix
a = 1 # int
b = 1.001 # float
c = /path/to/thing # path
d = "42" # string
e = true # boolean
```
2023-10-14 17:20:33 +01:00
-------------------------------------------------------------------------
2023-10-08 13:29:27 +01:00
```nix
double = x: x*2
mul = a: b: a*b
double 2
mul 2 3
```
2023-10-14 17:20:33 +01:00
-------------------------------------------------------------------------
2023-10-08 13:29:27 +01:00
```nix
s = { foo = "bar"; biz = "baz"; }
s.foo # bar
s.biz # baz
```
2023-10-14 17:20:33 +01:00
-------------------------------------------------------------------------
2023-10-08 13:29:27 +01:00
Info:
1. [Offical guide][2]
2. [Nix Pills][3]
2023-10-14 17:20:33 +01:00
-------------------------------------------------------------------------
2023-10-08 13:29:27 +01:00
## NixOS
2023-10-14 17:20:33 +01:00
-------------------------------------------------------------------------
2023-10-08 13:29:27 +01:00
Some crazy person saw Nix and thought "I want to make an OS with that"
2023-10-14 17:20:33 +01:00
-------------------------------------------------------------------------
2023-10-08 13:29:27 +01:00
In essence a giant function is created with an OS as the output
2023-10-14 17:20:33 +01:00
-------------------------------------------------------------------------
2023-10-08 13:29:27 +01:00
This does have quite a few advantages
2023-10-14 17:20:33 +01:00
-------------------------------------------------------------------------
2023-10-08 13:29:27 +01:00
* Config as Code
* Deterministic
* Reproducible
2023-10-14 17:20:33 +01:00
-------------------------------------------------------------------------
2023-10-08 13:29:27 +01:00
2023-10-14 17:20:33 +01:00
Skynet 2.0 had its config spread across different servers.
Making it hard to get a good overview
2023-10-08 13:29:27 +01:00
2023-10-14 17:20:33 +01:00
-------------------------------------------------------------------------
2023-10-08 13:29:27 +01:00
Skynet 3.0 is fully source controlled on [gitlab.skynet.ie][4]
2023-10-14 17:20:33 +01:00
-------------------------------------------------------------------------
2023-10-08 13:29:27 +01:00
Deterministic and Reproducible go hand in hand.
2023-10-14 17:20:33 +01:00
-------------------------------------------------------------------------
2023-10-08 13:29:27 +01:00
Deterministic means that for the same inputs you get the same output.
2023-10-14 17:20:33 +01:00
-------------------------------------------------------------------------
2023-10-08 13:29:27 +01:00
2023-10-14 17:20:33 +01:00
Reproducible is that you are able to create the same output from
the source code.
2023-10-08 13:29:27 +01:00
2023-10-14 17:20:33 +01:00
-------------------------------------------------------------------------
2023-10-08 13:29:27 +01:00
We use Flakes, which adds a lockfile, reduces hassle for the dev.
2023-10-14 17:20:33 +01:00
-------------------------------------------------------------------------
2023-10-08 13:29:27 +01:00
Questions?
2023-10-14 17:20:33 +01:00
-------------------------------------------------------------------------
2023-10-08 13:29:27 +01:00
[1]: https://en.wikipedia.org/wiki/Unix_philosophy
[2]: https://nix.dev/tutorials/first-steps/
[3]: https://nixos.org/guides/nix-pills/#
[4]: https://gitlab.skynet.ie/compsoc1/skynet/nixos