From f2a22e7a8bba4da2c79bb48f37f7c5d1747152e5 Mon Sep 17 00:00:00 2001 From: osbm Date: Mon, 13 Jan 2025 16:21:17 +0300 Subject: [PATCH] sd-image add --- hosts/harmonica/sd-image.nix | 40 ++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 hosts/harmonica/sd-image.nix diff --git a/hosts/harmonica/sd-image.nix b/hosts/harmonica/sd-image.nix new file mode 100644 index 0000000..91fe156 --- /dev/null +++ b/hosts/harmonica/sd-image.nix @@ -0,0 +1,40 @@ +# This module extends the official sd-image.nix with the following: +# - ability to add options to the config.txt firmware +{ + config, + lib, + pkgs, + ... +}: { + options.sdImage = with lib; { + extraFirmwareConfig = mkOption { + type = types.attrs; + default = {}; + description = lib.mdDoc '' + Extra configuration to be added to config.txt. + ''; + }; + }; + + config = { + sdImage.populateFirmwareCommands = + lib.mkIf ((lib.length (lib.attrValues config.sdImage.extraFirmwareConfig)) > 0) + ( + let + # Convert the set into a string of lines of "key=value" pairs. + keyValueMap = name: value: name + "=" + toString value; + keyValueList = lib.mapAttrsToList keyValueMap config.sdImage.extraFirmwareConfig; + extraFirmwareConfigString = lib.concatStringsSep "\n" keyValueList; + in + lib.mkAfter + '' + config=firmware/config.txt + # The initial file has just been created without write permissions. Add them to be able to append the file. + chmod u+w $config + echo "\n# Extra configuration" >> $config + echo "${extraFirmwareConfigString}" >> $config + chmod u-w $config + '' + ); + }; +} \ No newline at end of file