{ description = "My visionfive 2 setup"; #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"; inputs.nixos-hardware.url = "github:nixos/nixos-hardware"; #inputs.nickcao-rv64.url = "github:NickCao/nixos-riscv"; # https://github.com/NickCao/nixos-riscv #inputs.nickcao-rv64.inputs.nixpkgs.follows = "nixpkgs"; #inputs.zhao-rv64.url = "github:zhaofengli/nixos-riscv64"; # https://github.com/zhaofengli/nixos-riscv64 outputs = { self, nixpkgs, nixos-hardware, ...} @ inputs: let 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 [ "x86_64-linux" "aarch64-linux" "riscv64-linux" ]; in { inherit inputs; nixosModules = rec { # helper, ensures cross rv64-maybe-cross = { config, lib, ... }: lib.mkIf (config.nixpkgs.system != "riscv64-linux") { # (system != "riscv64-linux") => do cross nixpkgs.crossSystem.config = "riscv64-unknown-linux-gnu"; nixpkgs.crossSystem.system = "riscv64-linux"; }; # hardware, pick one vf2-r12a = { lib, ...}: { imports = [ rv64-maybe-cross ]; hardware.deviceTree.name = "starfive/jh7110-starfive-visionfive-2-v1.2a.dtb"; }; vf2-r12a-8gb = { imports = [ vf2-r12a ]; hardware.deviceTree.overlays = [{ name = "8GB-patch"; dtsFile = "${nixos-hardware}/starfive/visionfive/v2/8gb-patch.dts"; }]; }; vf2-r13b = { lib, ...}: { imports = [ rv64-maybe-cross ]; hardware.deviceTree.name = "starfive/jh7110-starfive-visionfive-2-v1.3b.dtb"; # default }; vf2-r13b-8gb = { imports = [ vf2-r13b ]; hardware.deviceTree.overlays = [{ name = "8GB-patch"; dtsFile = "${nixos-hardware}/starfive/visionfive/v2/8gb-patch.dts"; }]; }; # install method, pick one vf2-qemu = { lib, ...}: { imports = [ "${nixos-hardware}/starfive/visionfive/v2" ./qemu-vm.nix ]; }; 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; }; vf2-nvme = { pkgs, ... }: let firmware = pkgs.callPackage "${inputs.nixos-hardware}/starfive/visionfive/v2/firmware.nix" { }; in { imports = [ "${nixos-hardware}/starfive/visionfive/v2" ]; 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 boot.initrd.kernelModules = [ "nvme" ]; #boot.loader.systemd-boot.enable = true; #boot.loader.efi.efiSysMountPoint = "/boot"; #boot.loader.efi.canTouchEfiVariables = true; environment.systemPackages = [ pkgs.efibootmgr pkgs.efivar 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 ''; }) ]; }; vf2-nvme-image = { _module.args = { inherit inputs; }; imports = [ vf2-nvme ./efi-image.nix ]; }; # components dhcp = { networking.interfaces.end0.useDHCP = true; networking.interfaces.end1.useDHCP = true; }; minimal = { lib, ...}: let inherit (lib) mkDefault mkForce; in { #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; networking.firewall.enable = mkDefault false; programs.command-not-found.enable = false; security.audit.enable = mkDefault false; security.polkit.enable = mkForce false; 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; }; # hosts demo = { pkgs, ... }: { imports = [ minimal dhcp "${nixpkgs}/nixos/modules/profiles/base.nix" ]; networking.hostName = "demo"; environment.systemPackages = with pkgs;[ neofetch htop fd ripgrep ]; system.stateVersion = "23.11"; }; asgaut = { pkgs, ... }: { imports = [ minimal dhcp ]; networking.hostName = "asgaut"; 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"; environment.systemPackages = with pkgs;[ neofetch htop fd ripgrep ]; system.stateVersion = "23.11"; }; }; 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; }); 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 ]); }; }; }