Skip to content

Commit

Permalink
sd-image-unmatched: init
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaofengli committed Jan 18, 2022
1 parent 54f0f4a commit c7e83e3
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 0 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,17 @@ BOOT MODE SEL
```
</details>

### Installing NixOS onto the SD Card

**Note: To use the pre-built SD image, you must have installed U-Boot onto the on-board SPI flash.**

You can obtain a pre-built SD image (`nixos-sd-image-unmatched.zst`) [here](https://github.com/zhaofengli/nixos-riscv64/releases), or build `riscv64.sd-image-unmatched`.
Decompress the image, then burn it into an SD card.

The image has [the binary cache](https://app.cachix.org/cache/unmatched) preconfigured, and you can reconfigure the SD image by running `sudo nixos-rebuild switch`,
Alternatively, you can also install NixOS manually onto the NVMe drive using the SD image.
If you choose to go the manual route, include `nixos/unmatched.nix` from this repo in your configuration.

## References

- https://github.com/carlosedp/riscv-bringup/tree/master/unmatched
Expand Down
2 changes: 2 additions & 0 deletions pkgs/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ final: prev: rec {
sd-image-qemu-sway = final.callPackage ./sd-image-qemu-sway { };

# HiFive Unmatched
sd-image-unmatched = final.callPackage ./sd-image-unmatched { };

linux_unmatched = final.callPackage ./linux-unmatched { };
linuxPackages_unmatched = final.linuxPackagesFor linux_unmatched;
uboot-unmatched = final.callPackage ./uboot-unmatched { };
Expand Down
10 changes: 10 additions & 0 deletions pkgs/sd-image-unmatched/configuation.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{ config, pkgs, modulesPath, ... }:
{
imports = [
(import <nixos-riscv64/pkgs/sd-image-unmatched/sd-image-riscv64-unmatched.nix>)
(import <nixos-riscv64/nixos/unmatched.nix>)
];

nix.binaryCaches = [ "https://unmatched.cachix.org" ];
nix.binaryCachePublicKeys = [ "unmatched.cachix.org-1:F8TWIP/hA2808FDABsayBCFjrmrz296+5CQaysosTTc=" ];
}
36 changes: 36 additions & 0 deletions pkgs/sd-image-unmatched/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{ lib, nixos, nix-gitignore, runCommandLocal, ubootQemuRiscv64Smode
, nixos-riscv64 ? nix-gitignore.gitignoreSource [] ../.. }:

let
riscv64Channel = runCommandLocal "nixos-riscv64" {} ''
mkdir -p $out
cp -prd ${nixos-riscv64} $out/nixos-riscv64
'';

config = { lib, pkgs, modulesPath, config, ... }: {
imports = [
./sd-image-riscv64-unmatched.nix
../../nixos/unmatched.nix
];

sdImage.imageName = "nixos-sd-image-unmatched";

boot.postBootCommands = lib.mkAfter ''
# Copy nixos-riscv64 channel
if ! [ -e /var/lib/nixos/did-nixos-riscv64-channel-init ]; then
echo "unpacking the nixos-riscv64 channel..."
mkdir -p /nix/var/nix/profiles/per-user/root
${config.nix.package.out}/bin/nix-env -p /nix/var/nix/profiles/per-user/root/channels \
-i ${riscv64Channel} --quiet --option build-use-substitutes false
mkdir -m 0755 -p /var/lib/nixos
touch /var/lib/nixos/did-nixos-riscv64-channel-init
fi
# To facilitate nixos-rebuild
if [[ ! -e /etc/nixos/configuration.nix ]]; then
cp ${./configuation.nix} /etc/nixos/configuration.nix
fi
'';
};
eval = nixos config;
in eval.config.system.build.sdImage
25 changes: 25 additions & 0 deletions pkgs/sd-image-unmatched/sd-image-riscv64-unmatched.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{ config, lib, pkgs, modulesPath, ... }:

{
imports = [
(modulesPath + "/profiles/base.nix")
(modulesPath + "/profiles/installation-device.nix")
(modulesPath + "/installer/sd-card/sd-image.nix")
];

boot.loader.grub.enable = false;
boot.loader.generic-extlinux-compatible.enable = true;

boot.consoleLogLevel = lib.mkDefault 7;
boot.kernelParams = ["console=tty0" "console=ttyS0,115200n8"];

installer.cloneConfig = false;

sdImage = {
populateFirmwareCommands = "";
populateRootCommands = ''
mkdir -p ./files/boot
${config.boot.loader.generic-extlinux-compatible.populateCmd} -c ${config.system.build.toplevel} -d ./files/boot
'';
};
}

0 comments on commit c7e83e3

Please sign in to comment.