nixos-riscv/flake.nix

172 lines
7.1 KiB
Nix

{
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.05";
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,
#nickcao-rv64,
...} @ inputs:
let
#systems = nixpkgs.lib.systems.flakeExposed;
systems = [
"x86_64-linux"
"aarch64-linux"
"riscv64-linux"
];
forAllSystems = f: nixpkgs.lib.genAttrs systems (system: f rec {
inherit system;
pkgs = nixpkgs.legacyPackages.${system};
inherit (pkgs) liv;
mkNixos = modules: nixpkgs.lib.nixosSystem { inherit system modules; };
vf2-firmware = pkgs.callPackage "${nixos-hardware}/starfive/visionfive/v2/firmware.nix" { };
});
#overlays = nixpkgs.lib.mapAttrsToList (name: val: val) self.overlays;
in {
inherit inputs;
#hydraJobs = {}
#overlays = {
# nickcao = nickcao-rv64.overlay;
# #default = (final: prev: {});
#};
nixosModules = rec {
# hardware
rv64 = { 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";
};
vf2-r12a = { lib, ...}: {
imports = [ rv64 ];
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/visionfive-2-v1.2a-8GB.dts";
}];
};
vf2-r13b = { lib, ...}: {
imports = [ rv64 ];
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/visionfive-2-v1.3b-8GB.dts";
}];
};
# install method
vf2-qemu = { lib, ...}: {
imports = [ "${nixos-hardware}/starfive/visionfive/v2" ./qemu.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 = { vf2-firmware, pkgs, ... }: {
imports = [ "${nixos-hardware}/starfive/visionfive/v2" ];
#fileSystems."/boot" = { device = "/dev/nvme0n1p1"; fsType = "vfat"; };
#fileSystems."/" = { device = "/dev/nvme0n1p2"; fsType = "ext4"; };
boot.initrd.kernelModules = [ "nvme" ];
boot.loader.systemd-boot.enable = true;
boot.loader.efi.canTouchEfiVariables = true;
boot.loader.efi.efiSysMountPoint = "/boot";
environment.systemPackages = [
pkgs.efibootmgr
pkgs.efivar
vf2-firmware.updater-flash
];
};
vf2-nvme-image = {
_module.args = { inherit inputs; }; # TODO: needed?
imports = [ vf2-nvme ./efi-image.nix ];
};
# components
minimal = { lib, ...}: {
boot.enableContainers = false;
programs.command-not-found.enable = false;
documentation.man.enable = false;
documentation.info.enable = false;
security.polkit.enable = lib.mkForce false;
security.audit.enable = false;
networking.firewall.enable = lib.mkDefault false;
};
dhcp = {
networking.interfaces.end0.useDHCP = true;
networking.interfaces.end1.useDHCP = true;
networking.domain = "pbsds.net";
networking.search = [ "pbsds.net" ];
};
locale-no_nb = {
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";
};
# hosts
demo = { pkgs, ... }: {
imports = [ minimal dhcp "${nixpkgs}/nixos/modules/profiles/base.nix" ];
networking.hostName = "demo";
system.stateVersion = "23.05";
};
asgaut = { pkgs, ... }: {
imports = [ minimal dhcp locale-no_nb ];
networking.hostName = "asgaut";
environment.systemPackages = with pkgs;[ neofetch htop fd ripgrep ];
system.stateVersion = "23.05";
};
gunder = { pkgs, ... }: {
imports = [ minimal dhcp locale-no_nb ];
networking.hostName = "gunder";
environment.systemPackages = with pkgs;[ neofetch htop fd ripgrep ];
system.stateVersion = "23.05";
};
};
packages = forAllSystems ({ system, mkNixos, ... }: with self.nixosModules; rec {
#default = asgaut-sd-installer;
demo-sd-installer = (mkNixos [ demo vf2-r12a-8gb vf2-sd-installer ]).config.system.build.sdImage;
demo-sd-image = (mkNixos [ demo vf2-r12a-8gb vf2-sd-image ]).config.system.build.sdImage;
demo-nvme-image = (mkNixos [ demo vf2-r12a-8gb vf2-nvme-image ]).config.system.build.efiImage;
demo-qemu = (mkNixos [ demo rv64 vf2-qemu ]).config.system.build.vm;
asgaut-sd-installer = (mkNixos [ asgaut vf2-r12a-8gb vf2-sd-installer ]).config.system.build.sdImage;
asgaut-sd-image = (mkNixos [ asgaut vf2-r12a-8gb vf2-sd-image ]).config.system.build.sdImage;
asgaut-nvme-image = (mkNixos [ asgaut vf2-r12a-8gb vf2-nvme-image ]).config.system.build.efiImage;
asgaut-qemu = (mkNixos [ asgaut rv64 vf2-qemu ]).config.system.build.vm;
gunder-sd-installer = (mkNixos [ gunder vf2-r12a-8gb vf2-sd-installer ]).config.system.build.sdImage;
gunder-sd-image = (mkNixos [ gunder vf2-r12a-8gb vf2-sd-image ]).config.system.build.sdImage;
gunder-nvme-image = (mkNixos [ gunder vf2-r12a-8gb vf2-nvme-image ]).config.system.build.efiImage;
gunder-qemu = (mkNixos [ gunder rv64 vf2-qemu ]).config.system.build.vm;
});
nixosConfigurations.demo = nixpkgs.lib.nixosSystem { system = "x86_64-linux"; modules = with self.nixosModules; [ demo vf2-nvme ]; };
nixosConfigurations.asgaut = nixpkgs.lib.nixosSystem { system = "x86_64-linux"; modules = with self.nixosModules; [ asgaut vf2-nvme ]; };
nixosConfigurations.gunder = nixpkgs.lib.nixosSystem { system = "x86_64-linux"; modules = with self.nixosModules; [ gunder vf2-nvme ]; };
};
}