nixos-riscv/flake.nix

186 lines
7.4 KiB
Nix
Raw Permalink Normal View History

2023-06-24 14:56:10 +02:00
{
description = "My visionfive 2 setup";
2024-02-20 08:50:31 +01:00
#inputs.nixpkgs.url = "github:NickCao/nixpkgs/riscv"; # https://github.com/NickCao/nixpkgs/tree/riscv
#inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
2023-06-25 03:38:08 +02:00
inputs.nixos-hardware.url = "github:nixos/nixos-hardware";
2024-02-20 08:50:31 +01:00
#inputs.nickcao-rv64.url = "github:NickCao/nixos-riscv"; # https://github.com/NickCao/nixos-riscv
2023-06-25 03:38:08 +02:00
#inputs.nickcao-rv64.inputs.nixpkgs.follows = "nixpkgs";
2024-02-20 08:50:31 +01:00
#inputs.zhao-rv64.url = "github:zhaofengli/nixos-riscv64"; # https://github.com/zhaofengli/nixos-riscv64
2023-06-24 14:56:10 +02:00
2023-06-25 03:38:08 +02:00
outputs = {
self,
nixpkgs,
nixos-hardware,
...} @ inputs:
2023-06-24 14:56:10 +02:00
let
2023-07-07 01:47:40 +02:00
forSystems = systems: f: nixpkgs.lib.genAttrs systems (system: f rec {
inherit system;
pkgs = nixpkgs.legacyPackages.${system};
lib = nixpkgs.legacyPackages.${system}.lib;
});
#forAllSystems = forSystems nixpkgs.lib.systems.flakeExposed;
forAllSystems = forSystems [
2023-06-25 03:38:08 +02:00
"x86_64-linux"
"aarch64-linux"
"riscv64-linux"
];
2023-06-24 14:56:10 +02:00
in {
2023-06-25 03:38:08 +02:00
inherit inputs;
2023-06-24 14:56:10 +02:00
2023-06-25 03:38:08 +02:00
nixosModules = rec {
2024-02-20 08:50:31 +01:00
# helper, ensures cross
2023-07-07 01:47:40 +02:00
rv64-maybe-cross = { config, lib, ... }: lib.mkIf (config.nixpkgs.system != "riscv64-linux") {
2023-06-25 03:38:08 +02:00
# (system != "riscv64-linux") => do cross
nixpkgs.crossSystem.config = "riscv64-unknown-linux-gnu";
nixpkgs.crossSystem.system = "riscv64-linux";
};
2023-07-07 01:47:40 +02:00
2024-02-20 08:50:31 +01:00
# hardware, pick one
2023-06-25 03:38:08 +02:00
vf2-r12a = { lib, ...}: {
2023-07-07 01:47:40 +02:00
imports = [ rv64-maybe-cross ];
2023-06-25 03:38:08 +02:00
hardware.deviceTree.name = "starfive/jh7110-starfive-visionfive-2-v1.2a.dtb";
};
vf2-r12a-8gb = {
imports = [ vf2-r12a ];
hardware.deviceTree.overlays = [{
name = "8GB-patch";
2024-02-20 08:50:31 +01:00
dtsFile = "${nixos-hardware}/starfive/visionfive/v2/8gb-patch.dts";
2023-06-25 03:38:08 +02:00
}];
};
vf2-r13b = { lib, ...}: {
2023-07-07 01:47:40 +02:00
imports = [ rv64-maybe-cross ];
2023-06-25 03:38:08 +02:00
hardware.deviceTree.name = "starfive/jh7110-starfive-visionfive-2-v1.3b.dtb"; # default
};
vf2-r13b-8gb = {
imports = [ vf2-r13b ];
hardware.deviceTree.overlays = [{
name = "8GB-patch";
2024-02-20 08:50:31 +01:00
dtsFile = "${nixos-hardware}/starfive/visionfive/v2/8gb-patch.dts";
2023-06-25 03:38:08 +02:00
}];
};
2024-02-20 08:50:31 +01:00
# install method, pick one
2023-06-25 03:38:08 +02:00
vf2-qemu = { lib, ...}: {
2023-06-25 05:43:17 +02:00
imports = [ "${nixos-hardware}/starfive/visionfive/v2" ./qemu-vm.nix ];
2023-06-25 03:38:08 +02:00
};
vf2-sd-installer = {
imports = [ "${nixos-hardware}/starfive/visionfive/v2/sd-image-installer.nix" ];
sdImage.compressImage = false;
};
vf2-sd-image = {
imports = [ "${nixos-hardware}/starfive/visionfive/v2/sd-image.nix" ];
sdImage.compressImage = false;
};
2023-06-25 05:43:17 +02:00
vf2-nvme = { pkgs, ... }: let
firmware = pkgs.callPackage "${inputs.nixos-hardware}/starfive/visionfive/v2/firmware.nix" { };
in {
2023-06-25 03:38:08 +02:00
imports = [ "${nixos-hardware}/starfive/visionfive/v2" ];
2023-06-25 05:43:17 +02:00
fileSystems."/".device = "/dev/disk/by-label/NIXOS_ROOT";
fileSystems."/".fsType = "ext4";
fileSystems."/boot/spl".device = "/dev/disk/by-label/UBOOT_SPL";
fileSystems."/boot/spl".fsType = "vfat";
fileSystems."/boot/spl".options = [ "nofail" "noauto" ]; # not critical
fileSystems."/boot/firmware".device = "/dev/disk/by-label/UBOOT_FIRMWARE";
fileSystems."/boot/firmware".fsType = "vfat";
fileSystems."/boot/firmware".options = [ "nofail" "noauto" ]; # not critical
2023-06-25 03:38:08 +02:00
boot.initrd.kernelModules = [ "nvme" ];
2023-06-25 05:43:17 +02:00
#boot.loader.systemd-boot.enable = true;
#boot.loader.efi.efiSysMountPoint = "/boot";
#boot.loader.efi.canTouchEfiVariables = true;
2023-06-25 03:38:08 +02:00
environment.systemPackages = [
pkgs.efibootmgr
pkgs.efivar
2023-06-25 05:43:17 +02:00
firmware.updater-flash
(pkgs.writeShellApplication {
name = "visionfive2-firmware-update-ssd";
runtimeInputs = [ pkgs.mtdutils ];
text = ''
flashcp -v ${firmware.spl}/share/starfive-visionfive2/spl.bin /dev/nvme0n1p1
flashcp -v ${firmware.uboot-fit-image}/share/starfive-visionfive2/visionfive2_fw_payload.img /dev/nvme0n1p2
'';
})
2023-06-25 03:38:08 +02:00
];
};
vf2-nvme-image = {
2023-06-25 05:43:17 +02:00
_module.args = { inherit inputs; };
2023-06-25 03:38:08 +02:00
imports = [ vf2-nvme ./efi-image.nix ];
};
# components
2024-02-20 08:50:31 +01:00
dhcp = {
networking.interfaces.end0.useDHCP = true;
networking.interfaces.end1.useDHCP = true;
};
minimal = { lib, ...}: let inherit (lib) mkDefault mkForce; in {
2023-07-07 01:47:40 +02:00
#boot.enableContainers = mkDefault false;
documentation.enable = mkDefault false;
documentation.doc.enable = mkDefault false;
documentation.info.enable = mkDefault false;
documentation.man.enable = mkDefault false;
documentation.nixos.enable = mkDefault false;
#environment.noXlibs = mkDefault true;
2024-02-20 08:50:31 +01:00
networking.firewall.enable = mkDefault false;
2023-06-25 03:38:08 +02:00
programs.command-not-found.enable = false;
2023-07-07 01:47:40 +02:00
security.audit.enable = mkDefault false;
2024-02-20 08:50:31 +01:00
security.polkit.enable = mkForce false;
2023-07-07 01:47:40 +02:00
services.logrotate.enable = mkDefault false;
services.udisks2.enable = mkDefault false;
#xdg.autostart.enable = mkDefault false;
#xdg.icons.enable = mkDefault false;
#xdg.mime.enable = mkDefault false;
#xdg.sounds.enable = mkDefault false;
2023-06-25 03:38:08 +02:00
};
# hosts
demo = { pkgs, ... }: {
imports = [ minimal dhcp "${nixpkgs}/nixos/modules/profiles/base.nix" ];
networking.hostName = "demo";
2024-02-20 08:50:31 +01:00
environment.systemPackages = with pkgs;[ neofetch htop fd ripgrep ];
system.stateVersion = "23.11";
2023-06-25 03:38:08 +02:00
};
asgaut = { pkgs, ... }: {
2024-02-20 08:50:31 +01:00
imports = [ minimal dhcp ];
2023-06-25 03:38:08 +02:00
networking.hostName = "asgaut";
2024-02-20 08:50:31 +01:00
networking.domain = "pbsds.net";
networking.search = [ "pbsds.net" ];
console.keyMap = "no";
services.xserver.layout = "no";
services.xserver.xkbVariant = "";
time.timeZone = "Europe/Oslo";
i18n.defaultLocale = "en_US.utf8";
i18n.extraLocaleSettings.LC_TIME = "nb_NO.utf8";
2023-06-25 03:38:08 +02:00
environment.systemPackages = with pkgs;[ neofetch htop fd ripgrep ];
2024-02-20 08:50:31 +01:00
system.stateVersion = "23.11";
2023-06-25 03:38:08 +02:00
};
2023-06-24 14:56:10 +02:00
};
2023-07-07 01:47:40 +02:00
packages = forAllSystems ({ system, ... }: let
m = self.nixosModules;
mkNixos = modules: nixpkgs.lib.nixosSystem { inherit system modules; };
mkAll = hostname: modules: with m; {
"${hostname}-sd-installer" = (mkNixos (modules ++ [ vf2-sd-installer ])).config.system.build.sdImage;
"${hostname}-sd-image" = (mkNixos (modules ++ [ vf2-sd-image ])).config.system.build.sdImage;
"${hostname}-nvme-image" = (mkNixos (modules ++ [ vf2-nvme-image ])).config.system.build.efiImage;
"${hostname}-qemu" = (mkNixos (modules ++ [ vf2-qemu ])).config.system.build.vm;
};
in (mkAll "demo-r12a" [ m.demo m.vf2-r12a ])
// (mkAll "demo-r12a-8gb" [ m.demo m.vf2-r12a-8gb ])
// (mkAll "demo-r13b" [ m.demo m.vf2-r13b ])
// (mkAll "demo-r13b-8gb" [ m.demo m.vf2-r13b-8gb ])
// (mkAll "asgaut" [ m.asgaut m.vf2-r12a-8gb ])
// {
default = self.packages.${system}.demo-r12a-qemu;
});
2023-06-25 03:38:08 +02:00
2023-07-07 01:47:40 +02:00
nixosConfigurations = let
m = self.nixosModules;
mkSystem = modules: nixpkgs.lib.nixosSystem { system = "x86_64-linux"; inherit modules; };
in {
asgaut = mkSystem (with m; [ asgaut vf2-r12a-8gb vf2-nvme ]);
};
2023-06-24 14:56:10 +02:00
};
}