Robertof / nixos-docker-sd-image-builder

Build custom SD images of NixOS for your Raspberry Pi (or any other supported AArch64 device) in 5-20 minutes.
MIT License
197 stars 34 forks source link

Using nixops to update/manage the deployment #5

Open angerman opened 4 years ago

angerman commented 4 years ago

Hi there,

thanks for doing this! I've used it to great success, though my setup is a bit different and I'm wondering if there is interest in integrating this?

My diff so far wrt to nixos-docker-sd-image-builder isn't that large:

diff --git a/config/rpi4/default.nix b/config/rpi4/default.nix
index 57b7774..7f886ef 100644
--- a/config/rpi4/default.nix
+++ b/config/rpi4/default.nix
@@ -39,7 +39,7 @@
   # so we don't want to provide the installation configuration.nix.
   installer.cloneConfig = false;

-  fileSystems = lib.mkForce {
+  fileSystems = {
       # There is no U-Boot on the Pi 4, thus the firmware partition needs to be mounted as /boot.
       "/boot" = {
           device = "/dev/disk/by-label/FIRMWARE";
diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml
index 0485001..bb3887e 100644
--- a/docker/docker-compose.yml
+++ b/docker/docker-compose.yml
@@ -37,7 +37,7 @@ services:
                          -A config.system.build.sdImage \
                          --option system aarch64-linux \
                          --option sandbox false \
-                         -I nixos-config=/build/config/sd-image.nix \
+                         -I nixos-config=/build/$NIXOS_CONFIG \
                          nixpkgs/nixos/default.nix && \
                        chmod u+w result/sd-image/* && sudo cp result/sd-image/* /build"]
     volumes:
diff --git a/run.sh b/run.sh
index b19ae19..f20d854 100755
--- a/run.sh
+++ b/run.sh
@@ -9,6 +9,9 @@ fi

 echo "detecting architecture..."

+if [ -z "$NIXOS_CONFIG" ]; then
+  export NIXOS_CONFIG=config/sd-image.nix
+fi
 # Image base to use. The trick to allow this to work painlessly on both x86 and AArch64 is just
 # a magic trick which involves prepending `arm64v8/` when building natively.
 export IMAGE_BASE=

It basically drops the mkForce, which makes changing (or even adding additional mount points) pretty hard, and making the nixos-config a bit more configurable.

I then have additional configuration for each platform in boards, and then custom configurations for each deployment in an ops folder, and some nixops wrapper to deploy/update them.

If there is interest, I'd be happy to clean this up some more and open a PR.

One thing I couldn't figure out (lack of docker/docker-compose knowledge basically) is how to launch a docker container that would run an nixOS aarch64 instance one could use as a remote builder (after all one wouldn't want to build on the tiny SCBs directly due to performance, sd card wear, ...) and launching an AWS might not be possible (or feasible due to latency slow up/down link).

Robertof commented 4 years ago

Hey there,

wow, that's incredible work you did there! I am absolutely super-interested in this. If it's not too much of an hassle I'd really appreciate a PR.

Also, it would be amazing if you could share more insights about your NixOps setup as I was planning to play with it too!

Regarding your last idea that sounds super-cool! I think something like this might warrant a second repo/docker-compose setup as this one is specifically designed to be a "one off". I'll look into it, thanks again!