Skip to content
Snippets Groups Projects
Commit 37e58a0c authored by Valentin's avatar Valentin
Browse files

NixOS: add part about Nix

parent b1503ff3
No related branches found
No related tags found
No related merge requests found
spotlight_courses/HS24_NixOS/img/nix-repl-pkgs.png

39.3 KiB

No preview for this file type
......@@ -44,8 +44,8 @@
== Today's topics
- What sets *`NixOS`* apart from other distros?
- benefits of *`nix`* and *`NixOS`*
- Understand *why* nix is cool and why it might be for you
- benefits of *`Nix`* and *`NixOS`*
- Understand *why* Nix is cool and why it might be for you
- configuring *`NixOS`*
- *toolbox* of commands / websites
- some *interesting projects* for NixOS
......@@ -77,7 +77,43 @@
- Distribute your builds accross an unlimited number of machines, without any hassle
= A Nix crash course
== The Nix language basics
#columns(2, [
- A piece of nix code is a _Nix expression_
- Evaluating that expression gives a _value_
- The content of a _Nix file_ is a _Nix expression_
```nix
> 1 + 1
2
> "This is Nix!"
"This is Nix!"
```
#colbreak()
*Names and values:*
- Assign names to values
```nix
> a = 1
> a
a
> b = true
> b
true
```
])
=== Attribute sets:
- collection of name-value pairs
```nix
> {a = 1; b = "2"; c = 3.0;}
{
a = 1;
b = "2";
c = 3;
}```
== A simple bash script
#columns(2, [
......@@ -330,6 +366,38 @@ in
};
}
```
=== Put it into a system's packages!
#text(size:10pt, [
#columns(2, [
```nix
let
nixpkgs = fetchTarball "https://github.com/NixOS/nixpkgs/archive/nixos-24.05.tar.gz";
pkgs = import nixpkgs {};
what-is-my-ip = import ./what-is-my-ip.nix {inherit pkgs;};
nixos = import "${nixpkgs}/nixos" {
configuration = {
users.users.alice = {
isNormalUser = true;
# enable sudo
extraGroups = ["wheel"];
packages = [
what-is-my-ip
];
initialPassword = "tux";
};
system.stateVersion = "24.05";
};
};
in
nixos.vm
```
#text(size: 15pt,[
- Build the vm
- (using nix-build what-is-my-ip-vm.nix)
- have what-is-my-ip installed!
])])
])
// https://fzakaria.com/2024/07/05/learn-nix-the-fun-way.html
= NixOS
......@@ -756,12 +824,59 @@ config.vim = {
#link("https://github.com/NotAShelf/nvf")
])
])
== Docker!
#columns(2,
[
#text(
size: 13pt,
[```nix
{ pkgs ? import <nixpkgs> {system = "x86_64-linux;" }}: let
what-is-my-ip = import ./what-is-my-ip.nix {inherit pkgs;};
in
pkgs.dockerTools.buildImage {
name = "what-is-my-ip-docker";
config = {
Cmd = [ "${what-is-my-ip}/bin/what-is-my-ip" ];
};
}
```])])
- Works, but is it really better than using docker normally?
=== Easy layered Docker iamges
#columns(2,
[
#text(
size: 13pt,
[```nix
{ pkgs ? import <nixpkgs> {system = "x86_64-linux;" }}: let
what-is-my-ip = import ./what-is-my-ip.nix {inherit pkgs;};
in
pkgs.dockerTools.buildLayeredImage {
name = "what-is-my-ip-docker";
config = {
Cmd = [ "${what-is-my-ip}/bin/what-is-my-ip" ];
};
}
```])
#colbreak()
- puts each dependency into a seperate layer
- updating a single package/dependency?
- only update that layer, and upload the part of the image which actually changed
- easy version controlling with git
])
= Toolbox
== CLI
=== `nix repl`
- search for packages
#figure(
caption: "extra nix features in my config"
)[
#image("img/nix-repl-pkgs.png", width: 70%)
]
=== `nix repl`
- inspect configuration
......@@ -783,13 +898,6 @@ config.vim = {
= packaging
== pitfalls
- Let me just copy the hash of another package until it fetches
$==>$ nothing happens, no error???
- why? identity of derivation: hash
= stylix
== Styling
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment