Skip to content

Instantly share code, notes, and snippets.

@andrew-d
Created February 8, 2018 22:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrew-d/d5cee00dd06b24097bdc12ae50520ce8 to your computer and use it in GitHub Desktop.
Save andrew-d/d5cee00dd06b24097bdc12ae50520ce8 to your computer and use it in GitHub Desktop.
NixOS on ODROID HC2
# nix-build '<nixpkgs/nixos>' -I nixos-config=sdcard-minimal.nix -A config.system.build.sdImage
{ config, lib, pkgs, fetchurl, ... }:
let
extlinux-conf-builder =
import <nixpkgs/nixos/modules/system/boot/loader/generic-extlinux-compatible/extlinux-conf-builder.nix> {
inherit pkgs;
};
platform = {
name = "odroid-hc2";
kernelMajor = "2.6"; # Using "2.6" enables 2.6 kernel syscalls in glibc.
kernelBaseConfig = "odroidxu4_defconfig";
kernelArch = "arm";
kernelDTB = true;
kernelAutoModules = true;
kernelPreferBuiltin = true;
kernelTarget = "zImage";
kernelExtraConfig = ''
# Hangs ODROID-XU4
ARM_BIG_LITTLE_CPUIDLE n
'';
gcc = {
arch = "armv7-a";
float = "hard";
# NOTE: need to do this because our build servers at Scaleway don't
# support vfpv4 or NEON
# Ideally we could set `fpu = "neon-vfpv4";`
fpu = "vfpv3";
};
uboot = pkgs.uboot-odroid;
# multi_v7_defconfig isn't quite what we want, but it doesn't seem possible
# to override the linux-headers package here :'(
kernelHeadersBaseConfig = "multi_v7_defconfig";
};
in
{
imports = [
<nixpkgs/nixos/modules/installer/cd-dvd/sd-image.nix>
<nixpkgs/nixos/modules/profiles/installation-device.nix>
<nixpkgs/nixos/modules/profiles/minimal.nix>
];
assertions = lib.singleton {
assertion = pkgs.stdenv.system == "armv7l-linux";
message = "image can be only built natively on ARMv7; it cannot be cross compiled";
};
boot.loader.grub.enable = false;
boot.loader.generic-extlinux-compatible.enable = true;
nixpkgs.config = {
platform = platform;
allowUnfree = true;
packageOverrides = pkgs:
let
upstreamLinux = pkgs.fetchurl {
url = "https://github.com/hardkernel/linux/archive/4.14.16-104.tar.gz";
sha256 = "1q62bw3pzz1z8jid2g5fd0y7356s0lzw50r0m2zly2qi5ia8rf9y";
};
in rec {
linux_4_14 = pkgs.linux_4_14.override {
version = "4.14.16";
extraMeta.branch = with lib; concatStrings (intersperse "." (take 2 (splitString "." version)));
src = upstreamLinux;
};
# TODO: would be nice if this worked...
#linuxHeaders_4_4 = pkgs.linuxHeaders_4_4.overrideAttrs (oldAttrs: rec {
# version = "4.4.16";
# name = "linux-headers-${version}";
# src = upstreamLinux;
# # Kinda hacky, but this fixes the install phase to print the right version.
# installPhase = ''
# ${oldAttrs.installPhase}
# echo "${version}-default" > $out/include/config/kernel.release
# '';
#});
#linuxHeaders = linuxHeaders_4_4;
uboot-odroid = pkgs.stdenv.mkDerivation rec {
version = "3.7";
name = "uboot-odroid-${version}";
src = pkgs.fetchurl {
url = "https://github.com/hardkernel/u-boot/archive/s905_6.0.1_v3.7.tar.gz";
sha256 = "1vrzdk7gi209wzx0frw706la7nqagchj2vdcc1q9jfb47byh1rry";
};
configurePhase = ''
make odroid-xu4_defconfig
'';
nativeBuildInputs = with pkgs; [ unzip ];
dontStrip = true;
};
};
};
boot.kernelPackages = pkgs.linuxPackages_4_14;
boot.kernelParams = ["console=ttyS0,115200n8" "console=ttymxc0,115200n8" "console=ttyAMA0,115200n8" "console=ttyO0,115200n8" "console=ttySAC2,115200n8" "console=tty0"];
# FIXME: this probably should be in installation-device.nix
users.extraUsers.root.initialHashedPassword = "";
sdImage = {
populateBootCommands = let
foo = 1;
in ''
# TODO: copy things to the SD card
${extlinux-conf-builder} -t 3 -c ${config.system.build.toplevel} -d ./boot
'';
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment