diff --git a/hosts/harmonica-sd/configuration.nix b/hosts/harmonica-sd/configuration.nix new file mode 100644 index 0000000..dfe7fd2 --- /dev/null +++ b/hosts/harmonica-sd/configuration.nix @@ -0,0 +1,54 @@ +{ + lib, + inputs, + ... +}: { + imports = [ + ./sd-image.nix + "${inputs.nixpkgs}/nixos/modules/installer/sd-card/sd-image-aarch64.nix" + ./hardware-configuration.nix + ../../modules + inputs.agenix.nixosModules.default + inputs.home-manager.nixosModules.home-manager + inputs.vscode-server.nixosModules.default + ]; + + myModules = { + enableKDE = false; + enableFonts = false; + blockYoutube = false; + blockTwitter = false; + enableTailscale = true; + }; + + i18n.inputMethod.enable = lib.mkForce false; # no need for japanese input method + + system.stateVersion = "25.05"; + + networking.hostName = "harmonica"; + + networking = { + interfaces."wlan0".useDHCP = true; + wireless = { + enable = true; + interfaces = ["wlan0"]; + networks = { + "House_Bayram" = { + psk = "PASSWORD"; + }; + "it_hurts_when_IP" = { + psk = "PASSWORD"; + }; + }; + }; + }; + + # NTP time sync. + services.timesyncd.enable = true; + + security.sudo = { + enable = true; + wheelNeedsPassword = false; + }; + services.getty.autologinUser = "osbm"; +} diff --git a/hosts/harmonica-sd/hardware-configuration.nix b/hosts/harmonica-sd/hardware-configuration.nix new file mode 100644 index 0000000..6627bca --- /dev/null +++ b/hosts/harmonica-sd/hardware-configuration.nix @@ -0,0 +1,81 @@ +{ + pkgs, + lib, + ... +}: { + # Some packages (ahci fail... this bypasses that) https://discourse.nixos.org/t/does-pkgs-linuxpackages-rpi3-build-all-required-kernel-modules/42509 + nixpkgs.overlays = [ + (final: super: { + makeModulesClosure = x: + super.makeModulesClosure (x // {allowMissing = true;}); + }) + ]; + + zramSwap = { + enable = true; + algorithm = "zstd"; + }; + + sdImage = { + # bzip2 compression takes loads of time with emulation, skip it. Enable this if you're low on space. + compressImage = false; + imageName = "zero2.img"; + + extraFirmwareConfig = { + # Give up VRAM for more Free System Memory + # - Disable camera which automatically reserves 128MB VRAM + start_x = 0; + # - Reduce allocation of VRAM to 16MB minimum for non-rotated (32MB for rotated) + gpu_mem = 16; + + # Configure display to 800x600 so it fits on most screens + # * See: https://elinux.org/RPi_Configuration + hdmi_group = 2; + hdmi_mode = 8; + }; + }; + + hardware = { + enableRedistributableFirmware = lib.mkForce false; + firmware = [pkgs.raspberrypiWirelessFirmware]; # Keep this to make sure wifi works + i2c.enable = true; + deviceTree.filter = "bcm2837-rpi-zero*.dtb"; + deviceTree.overlays = [ + { + name = "enable-i2c"; + dtsText = '' + /dts-v1/; + /plugin/; + / { + compatible = "brcm,bcm2837"; + fragment@0 { + target = <&i2c1>; + __overlay__ { + status = "okay"; + }; + }; + }; + ''; + } + ]; + }; + + boot = { + kernelPackages = pkgs.linuxPackages_rpi02w; + + initrd.availableKernelModules = ["xhci_pci" "usbhid" "usb_storage"]; + loader = { + grub.enable = false; + generic-extlinux-compatible.enable = true; + }; + extraModprobeConfig = '' + options brcmfmac roamoff=1 feature_disable=0x82000 + ''; + + # Avoids warning: mdadm: Neither MAILADDR nor PROGRAM has been set. This will cause the `mdmon` service to crash. + # See: https://github.com/NixOS/nixpkgs/issues/254807 + swraid.enable = lib.mkForce false; + }; + + nixpkgs.hostPlatform = "aarch64-linux"; +} diff --git a/hosts/harmonica-sd/sd-image.nix b/hosts/harmonica-sd/sd-image.nix new file mode 100644 index 0000000..1893925 --- /dev/null +++ b/hosts/harmonica-sd/sd-image.nix @@ -0,0 +1,39 @@ +# This module extends the official sd-image.nix with the following: +# - ability to add options to the config.txt firmware +{ + config, + lib, + ... +}: { + 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 + '' + ); + }; +}