From b34e473865a8bcc936c6a98d727c9286a1c9da21 Mon Sep 17 00:00:00 2001 From: kalipso Date: Tue, 8 Nov 2022 19:16:43 +0100 Subject: [PATCH] [raspberry] add base image i currently try building it and then check if it works --- README.md | 16 ++++++++++++++++ machines/configuration.nix | 17 +++++++++++++++++ outputs.nix | 4 +++- 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 018a20e..71b8f30 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,22 @@ to build a configuration run the following command (replace `````` wit nix build .#nixosConfigurations..config.system.build.toplevel ``` +### building raspberry image + +for the raspberry it is possible to build the whole configuration as an sd-card image which then can be flashed directly. more information about building arm on nixos can be found [here](https://nixos.wiki/wiki/NixOS_on_ARM). + +to be able to build the image you need to enable qemu emulation on the machine you are building with. therefore it is necessary to add the following to your configuration.nix: + +``` nix +boot.binfmt.emulatedSystems = [ "aarch64-linux" ]; +``` + +then you can build the image with: + +``` shell +nix build .#nixosConfigurations.rpi1_base_image.config.system.build.sdImage +``` + ### run a configuration as vm to run a vm we have to build it first using the following command (replace `````` with the actual hostname): diff --git a/machines/configuration.nix b/machines/configuration.nix index b594e42..65b277e 100644 --- a/machines/configuration.nix +++ b/machines/configuration.nix @@ -36,4 +36,21 @@ in ./moderatio/configuration.nix ]; }; + + rpi1_base_image = nixosSystem { + system = "aarch64-linux"; + modules = [ + "${nixpkgs}/nixos/modules/installer/sd-card/sd-image-raspberrypi.nix" + ./modules/sshd.nix + { + nixpkgs.config.allowUnsupportedSystem = true; + nixpkgs.crossSystem.system = "aarch64-linux"; + + networking.hostName = "rp1_base_image"; + networking.networkmanager.enable = true; + + system.stateVersion = "22.05"; + } + ]; + }; } diff --git a/outputs.nix b/outputs.nix index 75d5c75..8e74c40 100644 --- a/outputs.nix +++ b/outputs.nix @@ -17,8 +17,10 @@ in (utils.lib.eachSystem (builtins.filter filter_system utils.lib.defaultSystems devShells.default = pkgs.callPackage ./shell.nix { inherit (sops-nix.packages."${pkgs.system}") sops-import-keys-hook ssh-to-pgp sops-init-gpg-key; }; - })) // { + })) // rec { nixosConfigurations = import ./machines/configuration.nix (inputs // { inherit inputs; }); + + images.rpi1_base_image = nixosConfigurations.rpi1_base_image.config.system.build.sdImage; }