diff --git a/hardkernel/odroid-m1/README.md b/hardkernel/odroid-m1/README.md new file mode 100644 index 0000000..e841cfe --- /dev/null +++ b/hardkernel/odroid-m1/README.md @@ -0,0 +1,208 @@ +# ODroid M1 + +Hardware support for the Hardkernel ODroid M1: https://www.hardkernel.com/shop/odroid-m1-with-8gbyte-ram/ + +## Initial Installation + +This is for creating the initial image used to install to the SD Card or NVM Drive. + +Example `flake.nix`: + +```nix +{ + description = "SD Card Image Generator for ODroid M1"; + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + nixos-hardware.url = "github:nixos/nixos-hardware/master"; + }; + outputs = { self, nixpkgs, nixos-hardware }: rec { + nixosConfigurations.m1 = nixpkgs.lib.nixosSystem { + modules = [ + "${nixpkgs}/nixos/modules/installer/sd-card/sd-image-aarch64.nix" + nixos-hardware.nixosModules.hardkernel-odroid-m1 + ./sdimageconfiguration.nix + { + nixpkgs.config.allowUnsupportedSystem = true; + nixpkgs.hostPlatform.system = "aarch64-linux"; + nixpkgs.buildPlatform.system = "x86_64-linux"; # If you build on x86 otherwise change this. + } + ]; + }; + images.m1 = nixosConfigurations.m1.config.system.build.sdImage; + }; +} +``` + +For building the initial sd card image, you can use this example (tweaked for your preferences) `sdimageconfiguration.nix`: + +```nix +{ config, pkgs, lib, ... }: + +{ + system.stateVersion = lib.mkDefault "25.11"; + nixpkgs.hostPlatform.system = "aarch64-linux"; + + sdImage = { + # Skip compression, we'll want the img uncompressed for flashing anyway + compressImage = false; + # The system will not boot if this is missing + populateRootCommands = '' + ${config.boot.loader.petitboot.populateCmd} -c ${config.system.build.toplevel} -d ./files/kboot.conf + ''; + }; + + services.openssh = { + enable = true; + settings = { + # Highly recommended: Set Password Authentication to false if you have authorized keys you can use. This is an insecure default + PasswordAuthentication = true; + PermitRootLogin = "no"; + AllowUsers = [ "odroid" ]; + }; + }; + + # You will almost certainly want Git to pull in your configuration repository + environment.systemPackages = [ + pkgs.git + ]; + + users.users.odroid = { + isNormalUser = true; + description = "Default User"; + extraGroups = [ "networkmanager" "wheel" ]; + packages = []; + # Highly recommended: Change this default password using `sudo passwd` after logging in + initialPassword = lib.mkForce "odroid"; + # You can find this from https://github.com/username.keys for example + openssh.authorizedKeys.keys = []; + }; +} +``` + +Put both of these files into a Git repo, and build with: + +```sh +nix build .#images.m1 +``` + +## Ongoing updates + +To your NixOS server flake, you'll want to ensure that the host is set to aarch64-linux. + +An example flake: + +```nix +{ + description = "My NixOS configuration flake"; + + inputs = { + # Nixpkgs - Stable 25.11 release + nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11"; + # Home Manager - Stable 25.11 release + home-manager.url = "github:nix-community/home-manager/release-25.11"; + home-manager.inputs.nixpkgs.follows = "nixpkgs"; + # NixOS Hardware + nixos-hardware.url = "github:nixos/nixos-hardware/master"; + }; + + outputs = { + self, + nixpkgs, + home-manager, + nixos-hardware, + ... + }@inputs: + + let + mkSystem = hostname: systemArchitecture: # hostname: is a positional argument + nixpkgs.lib.nixosSystem { + system = systemArchitecture; + + specialArgs = { inherit inputs; }; + + modules = [ + ./hosts/${hostname}/configuration.nix + + home-manager.nixosModules.home-manager + { + home-manager.useGlobalPkgs = true; + home-manager.useUserPackages = true; + home-manager.backupFileExtension = "backup"; + } + ]; + }; + + hosts = [ + { hostname = "other-example"; systemArchitecture = "x86_64-linux"; } + { hostname = "odroid-m1-example"; systemArchitecture = "aarch64-linux"; } + ]; + in + { + # This is what creates the NixOS configurations for each host + nixosConfigurations = builtins.listToAttrs ( + # Iterator - nixConfigurations. = + map (host: { + name = host.hostname; + value = mkSystem host.hostname host.systemArchitecture; + }) + # Array to iterate over + hosts + ); + }; +} +``` + +And the related `configuration.nix`: + +```nix +{ config, pkgs, inputs, ... }: + +{ + imports = + [ + inputs.nixos-hardware.nixosModules.hardkernel-odroid-m1 + ./hardware-configuration.nix + ../../modules/nix + ../../users + ]; + + networking.hostName = "odroid-m1-example"; # Define your hostname. +} +``` + +And `hardware-configuration.nix`: + +```nix +# Do not modify this file! It was generated by ‘nixos-generate-config’ +# and may be overwritten by future invocations. Please make changes +# to /etc/nixos/configuration.nix instead. +{ config, lib, pkgs, modulesPath, ... }: + +{ + imports = + [ (modulesPath + "/installer/scan/not-detected.nix") + ]; + + boot.initrd.availableKernelModules = [ "nvme" ]; + boot.initrd.kernelModules = [ ]; + boot.kernelModules = [ ]; + boot.extraModulePackages = [ ]; + + fileSystems."/" = + { device = "/dev/disk/by-uuid/44444444-4444-4444-8888-888888888888"; + fsType = "ext4"; + }; + + swapDevices = [ ]; + + nixpkgs.hostPlatform = lib.mkDefault "aarch64-linux"; +} +``` + +You can generate these default files (with a few warnings) by running the following command on the odroid after initial boot: + +```sh +nixos-generate-config +``` + +It will save a configuration.nix and hardware-configuration.nix to `/etc/nixos`. Critically, you will need to add `inputs.nixos-hardware.nixosModules.hardkernel-odroid-m1` to the imports in `configuration.nix` for it to work.