Initial commit

This commit is contained in:
2023-11-17 23:43:51 +00:00
commit 1936083fb3
7 changed files with 346 additions and 0 deletions

71
.github/workflows/BuildSDImage.yml vendored Normal file
View File

@@ -0,0 +1,71 @@
name: Build OS Image
on:
workflow_dispatch:
push:
branches: [ master ]
paths:
- '*'
- '.github/workflows/BuildSDImage.yml'
jobs:
build-default-image:
name: Build OS image
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2.3.4
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v4
with:
extra_nix_config: |
extra-platforms = aarch64-linux
- name: Run the Magic Nix Cache
uses: DeterminateSystems/magic-nix-cache-action@v2
- run: |
sudo apt -y install qemu-user-static
- name: Test binfmt
run: |
cat /proc/sys/fs/binfmt_misc/qemu-aarch64
/usr/bin/qemu-aarch64-static --version
- name: Build SD Image
run: |
nix build --show-trace --option system aarch64-linux --option sandbox false .#images.m1
ls -lah ./result/sd-image
- uses: actions/upload-artifact@v2
with:
name: sd-image-ARM64_img
path: ./result/sd-image/*.img*
- name: Download artifact # yes, this is really necessary
uses: actions/download-artifact@v2
with:
name: sd-image-ARM64_img
path: release-files
- name: Display structure of downloaded files
run: ls -lah
working-directory: release-files
- name: Release
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: Latest_ARM64
body: Auto-generated image build
prerelease: true
files: ./release-files/*
# - uses: "marvinpinto/action-automatic-releases@latest"
# with:
# repo_token: "${{ secrets.GITHUB_TOKEN }}"
# automatic_release_tag: "latest"
# prerelease: true
# title: "Image Build - ARM64"
# files: |
# ./result/sd-image/*.img*

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
result

22
README.md Normal file
View File

@@ -0,0 +1,22 @@
# NixOS on ODROID-M1
(based on https://github.com/povik/nixos-on-odroid-n2 and hellabyte's work here https://discourse.nixos.org/t/newbie-installs-nixos-on-an-arm-sbc-or-how-patience-is-a-virtue/35020)
These are configuration files which make it easier to set up and maintain a NixOS installation on an ODROID-M1 single-board computer.
The system is set up to be loaded through Petitboot.
Kernel is mainline.
Patches are welcome!
## Building an initial SD/MMC image
On an aarch64 system (or with aarch64 emulation):
`nix build .#images.m1`
On an aarch64 system:
`nix build --option system aarch64-linux --option sandbox false .#images.m1`

27
flake.lock generated Normal file
View File

@@ -0,0 +1,27 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1699963925,
"narHash": "sha256-LE7OV/SwkIBsCpAlIPiFhch/J+jBDGEZjNfdnzCnCrY=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "bf744fe90419885eefced41b3e5ae442d732712d",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs"
}
}
},
"root": "root",
"version": 7
}

87
flake.nix Normal file
View File

@@ -0,0 +1,87 @@
{
inputs = {
# nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.05";
# nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.11";
#nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05";
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
};
outputs = { nixpkgs, ... }: let
system = "x86_64-linux";
pkgs = import nixpkgs {
inherit system;
};
lib = nixpkgs.lib;
in rec {
devShell.${system} = pkgs.mkShell {
buildInputs = with pkgs; [
rsync
zstd
];
};
nixosConfigurations.m1 = lib.nixosSystem {
system = "aarch64-linux";
modules = [
({ pkgs, config, ... }: {
imports = [
./kboot-conf
# "${nixpkgs}/nixos/modules/installer/sd-card/sd-image-aarch64-installer.nix"
"${nixpkgs}/nixos/modules/installer/sd-card/sd-image-aarch64.nix"
];
sdImage = {
compressImage = false;
populateFirmwareCommands = let
configTxt = pkgs.writeText "README" ''
Nothing to see here. This empty partition is here because I don't know how to turn its creation off.
'';
in ''
cp ${configTxt} firmware/README
'';
populateRootCommands = ''
${config.boot.loader.kboot-conf.populateCmd} -c ${config.system.build.toplevel} -d ./files/kboot.conf
'';
};
#boot.loader.grub.enable = false;
boot.loader.kboot-conf.enable = true;
# Use kernel >6.6
boot.kernelPackages = pkgs.linuxPackages_latest;
# Stop ZFS breasking the build
boot.supportedFilesystems = lib.mkForce [ "btrfs" "cifs" "f2fs" "jfs" "ntfs" "reiserfs" "vfat" "xfs" ];
# I'm not completely sure if some of these could be omitted,
# but want to make sure disk access works
boot.initrd.availableKernelModules = [
"nvme"
"nvme-core"
"phy-rockchip-naneng-combphy"
"phy-rockchip-snps-pcie3"
];
# Petitboot uses this port and baud rate on the boards serial port,
# it's probably good to keep the options same for the running
# kernel for serial console access to work well
boot.kernelParams = [ "console=ttyS2,1500000" ];
hardware.deviceTree.name = "rockchip/rk3568-odroid-m1.dtb";
services.openssh = {
enable = true;
settings.PermitRootLogin = "yes";
};
users.extraUsers.root.initialPassword = lib.mkForce "test123";
})
];
};
images = {
m1 = nixosConfigurations.m1.config.system.build.sdImage;
};
};
}

60
kboot-conf/default.nix Normal file
View File

@@ -0,0 +1,60 @@
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.boot.loader.kboot-conf;
# The builder used to write during system activation
builder = pkgs.substituteAll {
src = ./generate-kboot-conf.sh;
isExecutable = true;
path = [pkgs.coreutils pkgs.gnused pkgs.gnugrep];
inherit (pkgs) bash;
};
# The builder exposed in populateCmd, which runs on the build architecture
populateBuilder = pkgs.buildPackages.substituteAll {
src = ./generate-kboot-conf.sh;
isExecutable = true;
path = with pkgs.buildPackages; [coreutils gnused gnugrep];
inherit (pkgs.buildPackages) bash;
};
in
{
options = {
boot.loader.kboot-conf = {
enable = mkOption {
default = false;
type = types.bool;
description = ''
Whether to create petitboot-compatible /kboot.conf
'';
};
configurationLimit = mkOption {
default = 10;
example = 5;
type = types.int;
description = ''
Maximum number of configurations in the generated kboot.conf.
'';
};
populateCmd = mkOption {
type = types.str;
readOnly = true;
description = ''
Contains the builder command used to populate an image,
honoring all options except the <literal>-c &lt;path-to-default-configuration&gt;</literal>
argument.
Useful to have for sdImage.populateRootCommands
'';
};
};
};
config = let
args = "-g ${toString cfg.configurationLimit} -n ${config.hardware.deviceTree.name}";
in mkIf cfg.enable {
system.build.installBootLoader = lib.mkForce "${builder} ${args} -c";
system.boot.loader.id = "kboot-conf";
boot.loader.kboot-conf.populateCmd = "${populateBuilder} ${args}";
};
}

View File

@@ -0,0 +1,77 @@
#! @bash@/bin/sh -e
shopt -s nullglob
export PATH=/empty
for i in @path@; do PATH=$PATH:$i/bin; done
usage() {
echo "usage: $0 -c <path-to-default-configuration> -n <dtbName> [-g <num-generations>] [-d <target>]" >&2
exit 1
}
target=/kboot.conf
default= # Default configuration
numGenerations=0 # Number of other generations to include in the menu
while getopts "t:c:d:g:n:" opt; do
case "$opt" in
c) default="$OPTARG" ;;
g) numGenerations="$OPTARG" ;;
d) target="$OPTARG" ;;
n) dtbName="$OPTARG" ;;
\?) usage ;;
esac
done
[ "$default" = "" -o "$dtbName" = "" ] && usage
tmp=$target.tmp
# Echo out an kboot.conf menu entry
addEntry() {
local path=$(readlink -f "$1")
local tag="$2" # Generation number or 'default'
if ! test -e $path/kernel -a -e $path/initrd; then
return
fi
timestampEpoch=$(stat -L -c '%Z' $path)
timestamp=$(date "+%Y-%m-%d %H:%M" -d @$timestampEpoch)
nixosLabel="$(cat $path/nixos-version)"
extraParams="$(cat $path/kernel-params)"
local kernel=$(readlink -f "$path/kernel")
local initrd=$(readlink -f "$path/initrd")
local dtbs=$(readlink -f "$path/dtbs")
local id="nixos-$tag--$nixosLabel"
if [ "$tag" = "default" ]; then
echo "default=$id"
fi
echo -n "$id='"
echo -n "$kernel initrd=$initrd dtb=$dtbs/$dtbName "
echo -n "systemConfig=$path init=$path/init $extraParams"
echo "'"
}
echo "# Hola!" > $tmp
addEntry $default default >> $tmp
if [ "$numGenerations" -gt 0 ]; then
# Add up to $numGenerations generations of the system profile to the menu,
# in reverse (most recent to least recent) order.
for generation in $(
(cd /nix/var/nix/profiles && ls -d system-*-link) \
| sed 's/system-\([0-9]\+\)-link/\1/' \
| sort -n -r \
| head -n $numGenerations); do
link=/nix/var/nix/profiles/system-$generation-link
addEntry $link $generation
done >> $tmp
fi
mv -f $tmp $target