summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMinijackson <minijackson@riseup.net>2019-10-03 17:56:17 +0200
committerMinijackson <minijackson@riseup.net>2019-10-06 19:52:48 +0200
commitc31fb8b184df21662f6cae2dfe3e07167a32a799 (patch)
treebd18f03128154cd684f9d7b3b913febe3f37d83b
parent2124eec70492bb70f07fec8870039c9e5da7723b (diff)
downloadnixos-embedded-slides-c31fb8b184df21662f6cae2dfe3e07167a32a799.tar.gz
nixos-embedded-slides-c31fb8b184df21662f6cae2dfe3e07167a32a799.zip
nixos conf examples, how to override them and embedded usecase
-rw-r--r--.gitignore3
-rw-r--r--res/cross-build-1.nix44
-rw-r--r--res/cross-build-2.nix46
-rw-r--r--slides.md132
4 files changed, 225 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index 429e1c9..ec9d5bb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,5 @@
1*.sty 1*.sty
2/slides.pdf 2/slides.pdf
3
4result
5result-*
diff --git a/res/cross-build-1.nix b/res/cross-build-1.nix
new file mode 100644
index 0000000..0598129
--- /dev/null
+++ b/res/cross-build-1.nix
@@ -0,0 +1,44 @@
1{ nixpkgs ? import <unstable>, ... }:
2
3let
4 pkgs = nixpkgs {
5 config = { };
6 # https://github.com/NixOS/nixpkgs/blob/master/lib/systems/examples.nix
7 crossSystem = {
8 config = "armv7l-unknown-linux-gnueabihf";
9 };
10 #overlays = [ (import ./overlay.nix) ];
11 };
12
13 config = { ... }:
14 {
15 environment.noXlibs = true;
16 documentation.enable = false;
17
18 # btrfs-progs fails to build
19 services.udisks2.enable = false;
20
21 fonts.fontconfig.enable = false;
22
23 nixpkgs.overlays = with pkgs.lib; singleton (const (super: {
24 polkit = super.polkit.override { withGnome = false; };
25
26 # pkcs11 needs opensc which depends on libXt? which fails to build and is X library
27 rng-tools = super.rng-tools.override { withPkcs11 = false; };
28
29 nix = super.nix.override { withAWS = false; };
30 }));
31
32 fileSystems."/".fsType = "tmpfs";
33
34 boot = {
35 loader.grub.enable = false;
36 enableContainers = false;
37 hardwareScan = false;
38 };
39
40 powerManagement.enable = false;
41 };
42
43in
44 pkgs.nixos config
diff --git a/res/cross-build-2.nix b/res/cross-build-2.nix
new file mode 100644
index 0000000..7225964
--- /dev/null
+++ b/res/cross-build-2.nix
@@ -0,0 +1,46 @@
1# This one is much better than the first
2#
3# TODO: get `nix build -f cross-build-2.nix vm` to work
4
5{ nixos ? import <unstable/nixos>, ... }:
6
7let
8 # https://github.com/NixOS/nixpkgs/blob/master/lib/systems/examples.nix
9 target = "armv7l-unknown-linux-gnueabihf";
10
11 configuration = { lib, ... }:
12 {
13 nixpkgs.crossSystem = lib.systems.elaborate { config = target; };
14 nixpkgs.overlays = with lib; singleton (const (super: {
15 polkit = super.polkit.override { withGnome = false; };
16
17 # pkcs11 needs opensc which depends on libXt? which fails to build and is X library
18 rng-tools = super.rng-tools.override { withPkcs11 = false; };
19
20 nix = super.nix.override { withAWS = false; };
21
22 gobject-introspection = super.callPackage /tmp/gobject-introspection.nix { inherit (darwin) cctools; };
23 }));
24
25
26 environment.noXlibs = true;
27 documentation.enable = false;
28
29 # btrfs-progs fails to build
30 services.udisks2.enable = false;
31
32 fonts.fontconfig.enable = false;
33
34 fileSystems."/".fsType = "tmpfs";
35
36 boot = {
37 loader.grub.enable = false;
38 enableContainers = false;
39 hardwareScan = false;
40 };
41
42 powerManagement.enable = false;
43 };
44
45in
46 nixos { inherit configuration; }
diff --git a/slides.md b/slides.md
index f190e85..9d8774b 100644
--- a/slides.md
+++ b/slides.md
@@ -517,6 +517,10 @@ echo 'Hello, World!'
517 517
518::: 518:::
519 519
520## Overlays
521
522TODO
523
520## Using different versions of the same package---Generic 524## Using different versions of the same package---Generic
521 525
522```bash 526```bash
@@ -770,6 +774,114 @@ Introducing: the module system!
770 774
771::: 775:::
772 776
777## More examples
778
779```nix
780{ ... }:
781{
782 systemd.services.myService = {
783 description = "My really awesome service";
784 wantedBy = [ "multi-user.target" ];
785 after = [ "network.target" ];
786 serviceConfig = {
787 ExecStart = "${myPackage}/bin/myExec";
788 DynamicUser = true;
789 };
790 };
791}
792```
793
794::: notes
795
796- In the previous example, the openssh module created a systemd service for us.
797 Now we create or own systemd service.
798- In fact the openssh module will (in part) "modify" the systemd module.
799- And in turn, the systemd module will "modify" the module that sets up `/etc`.
800- There is no defined "order" / "hierarchy" of modules, the laziness of the Nix
801 language permits that (this can theoretically lead to infinite loops).
802- So really, the Nix language does this in reverse (activation script -> `/etc`
803 -> systemd -> openssh -> maybe higher level concepts)
804
805
806:::
807
808## Moaaar examples
809
810```nix
811{ ... }:
812{
813 containers = {
814 myContainer = {
815 config = { ... }: { services.postgresql.enable = true; };
816 };
817 myOtherContainer = {
818 config = { ... }: { services.nginx.enable = true; };
819 forwardPorts = [
820 { containerPort = 80; hostPort = 8080; protocol = "tcp"; }
821 ];
822 };
823 };
824}
825```
826
827## Composition
828
829```nix
830{ ... }:
831{
832 imports = [
833 ./hardware-configuration.nix
834 ./usecases/ssh-server.nix
835 ./usecases/web-interface.nix
836 ];
837}
838```
839
840## "Overridability"---Provided
841
842```nix
843{ ... }:
844{
845 hardware.bluetooth = {
846 enable = true;
847 package = myBluezFork;
848 };
849}
850```
851
852## "Overridability"---Forced
853
854```nix
855{ lib, ... }:
856{
857 services.unbound.enable = true;
858 # These tricks are done by "professionals".
859 # Don't try this at home
860 systemd.services.unbound.serviceConfig.ProtectSystem =
861 lib.mkForce false;
862}
863```
864
865## "Overridability"---Commando mode
866
867```nix
868{ ... }:
869{
870 nixpkgs.overlays = [ (self: super: {
871 bluez = myBluezFork;
872 } ) ];
873}
874```
875
876Otherwise, you can just copy and edit the official module file.
877
878::: notes
879
880- Changing things in overlays also changes packages dependencies, which in the
881 case of Bluez, there are quite a lot.
882
883:::
884
773## Assertions 885## Assertions
774 886
775``` 887```
@@ -780,6 +892,26 @@ Failed assertions:
780 892
781# The embedded world 893# The embedded world
782 894
895## Proper project structure
896
897<https://github.com/illegalprime/nixos-on-arm>
898
899```nix
900{ ... }:
901{
902 imports = [
903 <machine>
904 <image>
905 ];
906}
907```
908
909```
910$ nix build -f default.nix \
911 -I machine=./machines/MY_BOARD \
912 -I image=./images/MY_CONFIGURATION
913```
914
783## TODO 915## TODO
784 916
785- [x] Use good Markdown / Beamer template 917- [x] Use good Markdown / Beamer template