switch to nixos-hardware

This commit is contained in:
Peder Bergebakken Sundt 2023-06-25 03:38:08 +02:00
parent 805e48523d
commit c2ee77a6cb
7 changed files with 285 additions and 248 deletions

View File

@ -1,30 +0,0 @@
{ config, lib, pkgs, modulesPath, ... }:
with lib;
{
system.build.nvmeImage = import "${modulesPath}/../lib/make-disk-image.nix" {
inherit config lib pkgs;
diskSize = 8*1024; # megabytes
# TODO: zstd
format = "raw"; # one of qcow2, qcow2-compressed, vdi, vpc, raw.
installBootLoader = true;
partitionTableType = "efi";
configFile = pkgs.writeText "configuration.nix" ''
{
imports = [ <./machine-config.nix> ];
}
'';
};
boot.growPartition = true;
boot.initrd.kernelModules = [ "nvme" ];
/** /
boot.loader.grub.efiSupport = true;
boot.loader.grub.efiInstallAsRemovable = true;
boot.loader.grub.device = "nodev";
/**/
fileSystems."/boot" = { device = "/dev/nvme0n1p1"; fsType = "vfat"; };
fileSystems."/" = { device = "/dev/nvme0n1p2"; fsType = "ext4"; };
}

View File

@ -1,21 +0,0 @@
{ config, lib, pkgs, modulesPath, ... }:
{
imports = [ "${modulesPath}/profiles/base.nix" ];
boot.enableContainers = false;
console.keyMap = "no";
programs.command-not-found.enable = false;
i18n.supportedLocales = [ "en_US.UTF-8/UTF-8" ];
documentation.man.enable = false;
documentation.info.enable = false;
security.polkit.enable = lib.mkForce false;
security.audit.enable = false;
system.stateVersion = "22.11";
environment.systemPackages = with pkgs;[
neofetch
fd
ripgrep
];
}

61
efi-image.nix Normal file
View File

@ -0,0 +1,61 @@
{ config, pkgs, lib, inputs, modulesPath, ... }:
# prior art:
# https://github.com/NixOS/nixos-hardware/blob/master/starfive/visionfive/v2/sd-image.nix
# https://github.com/nix-community/nixos-generators/blob/master/formats/raw.nix
# https://github.com/nix-community/nixos-generators/blob/master/formats/raw-efi.nix
let
firmware = pkgs.callPackage "${inputs.nixos-hardware}/starfive/visionfive/v2/firmware.nix" { };
in {
options.efiImage = {
imageBaseName = lib.mkOption {
default = "nixos-efi-image";
description = lib.mdDoc "Prefix of the name of the generated image file.";
};
};
config = {
boot.loader.grub.device = config.fileSystems.${config.boot.loader.efi.efiSysMountPoint}.device; # hack for installBootLoader
fileSystems.${config.boot.loader.efi.efiSysMountPoint}.neededForBoot = true;
fileSystems."/".autoResize = true;
boot.growPartition = true;
#boot.loader.grub.device = "nodev";
#boot.loader.grub.efiSupport = true;
#boot.loader.grub.efiInstallAsRemovable = true;
system.build.efiImage = import "${modulesPath}/../lib/make-disk-image.nix" {
inherit config lib pkgs;
name = "${config.efiImage.imageBaseName}-${config.system.nixos.label}-${pkgs.stdenv.hostPlatform.system}-starfive-visionfive2.img";
#diskSize = 8*1024; # megabytes, defaults to "auto"
bootSize = "512M"; # nixos-install default
partitionTableType = "efi";
installBootLoader = true;
touchEFIVars = true;
#efiFirmware
#efiVariables
fsType = config.fileSystems."/".fsType;
# TODO: zstd
format = "raw"; # one of qcow2, qcow2-compressed, vdi, vpc, raw.
# TODO: make this thing able to rebuild
#configFile = pkgs.writeText "configuration.nix" ''
# {
# imports = [ <./machine-config.nix> ];
# }
#'';
};
assertions = [
{
assertion = config.boot.loader.systemd-boot.enable;
message = "Building EFI Image requires systemd-boot";
}
];
};
}

View File

@ -1,116 +1,41 @@
{ {
"nodes": { "nodes": {
"meta-sifive": { "nixos-hardware": {
"flake": false,
"locked": { "locked": {
"lastModified": 1674637034, "lastModified": 1686838567,
"narHash": "sha256-63ND5ppiTZq6R0S5DQXzKwTdP+ksRN2xUBSnOuSZIVc=", "narHash": "sha256-aqKCUD126dRlVSKV6vWuDCitfjFrZlkwNuvj5LtjRRU=",
"owner": "sifive", "owner": "nixos",
"repo": "meta-sifive", "repo": "nixos-hardware",
"rev": "0cf45af2861140a11a3655b6c1185a1b781420a0", "rev": "429f232fe1dc398c5afea19a51aad6931ee0fb89",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "sifive", "owner": "nixos",
"ref": "master", "repo": "nixos-hardware",
"repo": "meta-sifive",
"type": "github"
}
},
"nickcao-rv64": {
"inputs": {
"meta-sifive": "meta-sifive",
"nixpkgs": [
"nixpkgs"
],
"starfive-tools": "starfive-tools",
"u-boot-starfive": "u-boot-starfive",
"uboot-vf2-src": "uboot-vf2-src"
},
"locked": {
"lastModified": 1678100894,
"narHash": "sha256-P4zsTLZeD+jZW7wdTa+gIEqaOKV5atcpiaRMMSPVyWw=",
"owner": "NickCao",
"repo": "nixos-riscv",
"rev": "a95622d7c532f0bd6271bbc937d8c55faf1f4801",
"type": "github"
},
"original": {
"owner": "NickCao",
"repo": "nixos-riscv",
"type": "github" "type": "github"
} }
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1678101150, "lastModified": 1687502512,
"narHash": "sha256-Y0EAwuMqucZrH7FwkAeDAXSOIEFlQGVoQSk3+Nj07Ls=", "narHash": "sha256-dBL/01TayOSZYxtY4cMXuNCBk8UMLoqRZA+94xiFpJA=",
"owner": "NickCao", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "d23ade162e3a0fd23479a7073eeac9da5f1a40db", "rev": "3ae20aa58a6c0d1ca95c9b11f59a2d12eebc511f",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "NickCao", "owner": "NixOS",
"ref": "riscv", "ref": "nixos-unstable",
"repo": "nixpkgs", "repo": "nixpkgs",
"type": "github" "type": "github"
} }
}, },
"root": { "root": {
"inputs": { "inputs": {
"nickcao-rv64": "nickcao-rv64", "nixos-hardware": "nixos-hardware",
"nixpkgs": "nixpkgs" "nixpkgs": "nixpkgs"
} }
},
"starfive-tools": {
"flake": false,
"locked": {
"lastModified": 1674126575,
"narHash": "sha256-dKRHFWLJrXIEpsuXOO3zpiIplPFG5ghVLYR8GvBat8M=",
"owner": "NickCao",
"repo": "starfive-tools",
"rev": "7038f61fcd684fc60d2abc4fd95909782480c66b",
"type": "github"
},
"original": {
"owner": "NickCao",
"repo": "starfive-tools",
"type": "github"
}
},
"u-boot-starfive": {
"flake": false,
"locked": {
"lastModified": 1651224393,
"narHash": "sha256-48ah4mcEqrK9iRAz/QGCZUcz34xAuZyJuPanQ8IssMU=",
"owner": "NickCao",
"repo": "u-boot-starfive",
"rev": "ac75aa54020412a83b61dad46c5ea15e7f9f525c",
"type": "github"
},
"original": {
"owner": "NickCao",
"repo": "u-boot-starfive",
"type": "github"
}
},
"uboot-vf2-src": {
"flake": false,
"locked": {
"lastModified": 1678096112,
"narHash": "sha256-w6dPaok72sW7Q4ChSWDqds+djWWwigirz9f+s623r/g=",
"owner": "NickCao",
"repo": "u-boot-starfive",
"rev": "64fc719a5db536abaec42564689d96bcfdf0dfba",
"type": "github"
},
"original": {
"owner": "NickCao",
"ref": "visionfive2",
"repo": "u-boot-starfive",
"type": "github"
}
} }
}, },
"root": "root", "root": "root",

236
flake.nix
View File

@ -1,99 +1,171 @@
{ {
description = "My visionfive 2 setup"; description = "My visionfive 2 setup";
inputs = { #inputs.nixpkgs.url = "github:NickCao/nixpkgs/riscv"; # https://github.com/NickCao/nixpkgs/tree/riscv
nixpkgs.url = "github:NickCao/nixpkgs/riscv"; # https://github.com/NickCao/nixpkgs/tree/riscv #inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.05";
#nixpkgs.url = "github:nixos/nixpkgs/nixos-22.11"; # https://github.com/nixos/nixpkgs/tree/nixos-22.11 inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
#unstable.url = "github:nixos/nixpkgs/nixpkgs-unstable"; # https://github.com/nixos/nixpkgs/tree/nixpkgs-unstable inputs.nixos-hardware.url = "github:nixos/nixos-hardware";
nickcao-rv64.url = "github:NickCao/nixos-riscv"; # https://github.com/NickCao/nixos-riscv
nickcao-rv64.inputs.nixpkgs.follows = "nixpkgs";
#nickcao-rv64.url = "path:../nickcao-nixos-riscv"; # broken: https://github.com/NixOS/nix/issues/3978
#zhao-rv64.url = "github:zhaofengli/nixos-riscv64"; # https://github.com/zhaofengli/nixos-riscv64
};
outputs = { self, nixpkgs, nickcao-rv64, ...}@inputs: #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 let
nixlib = nixpkgs.lib; #systems = nixpkgs.lib.systems.flakeExposed;
overlays = nixlib.mapAttrsToList (name: val: val) self.overlays; systems = [
hostname = hostname: { "x86_64-linux"
networking.hostName = hostname; "aarch64-linux"
networking.domain = "pbsds.net"; "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 { in {
inherit inputs;
#hydraJobs = {} #hydraJobs = {}
overlays = { #overlays = {
nickcao = nickcao-rv64.overlay; # nickcao = nickcao-rv64.overlay;
#default = (final: prev: {}); # #default = (final: prev: {});
}; #};
nixosModules.generic-boot = { nixosModules = rec {
boot.loader.grub.enable = false; # hardware
boot.loader.generic-extlinux-compatible.enable = true; rv64 = { config, lib, ... }: lib.mkIf (config.nixpkgs.system != "riscv64-linux") {
}; # (system != "riscv64-linux") => do cross
nixosModules.rv64 = {
system = "riscv64-unknown-linux-gnu";
#nixpkgs.overlays = [ self.overlays.nickcao ];
};
nixosModules.rv64-cross = {
nixpkgs.localSystem.config = "x86_64-unknown-linux-gnu";
nixpkgs.crossSystem.config = "riscv64-unknown-linux-gnu"; nixpkgs.crossSystem.config = "riscv64-unknown-linux-gnu";
#nixpkgs.overlays = [ self.overlays.nickcao ]; nixpkgs.crossSystem.system = "riscv64-linux";
}; };
nixosModules.nvme-image = { config, lib, pkgs, modulesPath , ... }: { vf2-r12a = { lib, ...}: {
system.build.nvmeImage = import "${modulesPath}/../lib/make-disk-image.nix" { imports = [ rv64 ];
inherit config lib pkgs; hardware.deviceTree.name = "starfive/jh7110-starfive-visionfive-2-v1.2a.dtb";
diskSize = 8*1024; # megabytes
# TODO: zstd
format = "raw"; # one of qcow2, qcow2-compressed, vdi, vpc, raw.
installBootLoader = true;
partitionTableType = "efi";
# TODO: make this thing able to rebuild
configFile = pkgs.writeText "configuration.nix" ''
{
imports = [ <./machine-config.nix> ];
}
'';
}; };
boot.growPartition = true; vf2-r12a-8gb = {
boot.initrd.kernelModules = [ "nvme" ]; imports = [ vf2-r12a ];
/** / hardware.deviceTree.overlays = [{
boot.loader.grub.efiSupport = true; name = "8GB-patch";
boot.loader.grub.efiInstallAsRemovable = true; dtsFile = "${nixos-hardware}/starfive/visionfive/v2/visionfive-2-v1.2a-8GB.dts";
boot.loader.grub.device = "nodev"; }];
/**/
fileSystems."/boot" = { device = "/dev/nvme0n1p1"; fsType = "vfat"; };
fileSystems."/" = { device = "/dev/nvme0n1p2"; fsType = "ext4"; };
}; };
nixosModules.sd-image = { config, lib, pkgs, modulesPath, ... }: { vf2-r13b = { lib, ...}: {
imports = [ "${modulesPath}/installer/sd-card/sd-image.nix" ]; imports = [ rv64 ];
sdImage.populateFirmwareCommands = ""; hardware.deviceTree.name = "starfive/jh7110-starfive-visionfive-2-v1.3b.dtb"; # default
sdImage.populateRootCommands = ''
mkdir -p ./files/boot
${config.boot.loader.generic-extlinux-compatible.populateCmd} -c ${config.system.build.toplevel} -d ./files/boot
'';
}; };
nixosModules.nickcao-common = "${nickcao-rv64.outPath}/common.nix"; # is equal to: generic-boot + sd-image + rv64-cross vf2-r13b-8gb = {
nixosModules.nickcao-unmatched = "${nickcao-rv64.outPath}/unmatched.nix"; imports = [ vf2-r13b ];
nixosModules.nickcao-visionfive = "${nickcao-rv64.outPath}/visionfive.nix"; hardware.deviceTree.overlays = [{
nixosModules.nickcao-visionfive2 = "${nickcao-rv64.outPath}/visionfive2.nix"; name = "8GB-patch";
nixosModules.nickcao-qemu = "${nickcao-rv64.outPath}/qemu.nix"; dtsFile = "${nixos-hardware}/starfive/visionfive/v2/visionfive-2-v1.3b-8GB.dts";
nixosModules.base = { }];
nixpkgs.overlays = overlays;
imports = [ ./configuration.nix ];
}; };
# TODO: gunder # install method
# nixos-rebuild --flake .#NAME vf2-qemu = { lib, ...}: {
nixosConfigurations.qemu = nickcao-rv64.nixosConfigurations.qemu.extendModules { modules = with self.nixosModules; [ base ]; }; imports = [ "${nixos-hardware}/starfive/visionfive/v2" ./qemu.nix ];
nixosConfigurations.asgaut = nixpkgs.lib.nixosSystem { modules = with self.nixosModules; [ base (hostname "asgaut") nickcao-visionfive2 ]; }; };
nixosConfigurations.asgaut-nvme = nixpkgs.lib.nixosSystem { modules = with self.nixosModules; [ base (hostname "asgaut") nickcao-visionfive2 generic-boot rv64-cross nvme-image ]; }; vf2-sd-installer = {
nixosConfigurations.asgaut-sd = nixpkgs.lib.nixosSystem { modules = with self.nixosModules; [ base (hostname "asgaut") nickcao-visionfive2 generic-boot rv64-cross sd-image ]; }; imports = [ "${nixos-hardware}/starfive/visionfive/v2/sd-image-installer.nix" ];
nixosConfigurations.asgaut-sd2 = nixpkgs.lib.nixosSystem { modules = with self.nixosModules; [ base (hostname "asgaut") nickcao-visionfive2 nickcao-common ]; }; sdImage.compressImage = false;
# nix build .#images.NAME . };
images.asgaut-nvme = self.nixosConfigurations.asgaut-nvme.config.system.build.nvmeImage; vf2-sd-image = {
images.asgaut-sd = self.nixosConfigurations.asgaut-sd .config.system.build.sdImage; imports = [ "${nixos-hardware}/starfive/visionfive/v2/sd-image.nix" ];
images.asgaut-sd2 = self.nixosConfigurations.asgaut-sd2 .config.system.build.sdImage; sdImage.compressImage = false;
# nix build .#riscv64-linux.NAME-sd-image };
#packages.riscv64-linux.asgaut-sd-image = self.nixosConfigurations.gunder.config.system.build.sdImage; 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 ]; };
}; };
} }

View File

@ -1,21 +0,0 @@
{ config, pkgs, lib, modulesPath, ... }: {
nixpkgs = {
localSystem.config = "x86_64-unknown-linux-gnu";
crossSystem.config = "riscv64-unknown-linux-gnu";
};
boot.loader = {
grub.enable = false;
generic-extlinux-compatible.enable = true;
};
sdImage = {
populateFirmwareCommands = "";
populateRootCommands = ''
mkdir -p ./files/boot
${config.boot.loader.generic-extlinux-compatible.populateCmd} -c ${config.system.build.toplevel} -d ./files/boot
'';
};
}

51
qemu.nix Normal file
View File

@ -0,0 +1,51 @@
# based on https://github.com/NickCao/nixos-riscv/blob/master/qemu.nix
{ config, pkgs, lib, ...}:
{
boot.loader.generic-extlinux-compatible.enable = false;
#boot.kernelPackages = pkgs.linuxPackages_latest;
boot.kernelParams = [ "console=ttyS0" "earlycon" ];
boot.initrd.availableKernelModules = [ "pci_host_generic" "virtio_pci" "9p" "9pnet_virtio" ];
fileSystems."/" = {
device = "none";
fsType = "tmpfs";
options = [ "defaults" "mode=755" ];
};
fileSystems."/nix/store" = {
device = "nix-store";
fsType = "9p";
options = [ "ro" "trans=virtio" "version=9p2000.L" "msize=1M" ];
};
systemd.services."autotty@hvc0".enable = false;
systemd.services.mount-pstore.enable = false;
services.getty.autologinUser = "root";
networking.firewall.enable = false;
#virtualisation.docker.enable = true;
system.build.vm =
let
qemu-path = "${pkgs.pkgsBuildBuild.qemu}/bin/qemu-system-${pkgs.targetPlatform.qemuArch}";
closure = config.system.build.toplevel;
qemu-args = [
"-M" "virt"
"-smp" "2" # cpus
"-m" "2G" # mem
"-kernel" "${closure}/kernel"
"-initrd" "${closure}/initrd"
"-append" "$(cat ${closure}/kernel-params) init=${closure}/init"
"-device" "virtio-rng-pci"
"-netdev" "user,id=end0"
"-device" "virtio-net-pci,netdev=end0"
"-netdev" "user,id=end1"
"-device" "virtio-net-pci,netdev=end1"
"-fsdev" "local,security_model=passthrough,id=nix-store,path=/nix/store,readonly=on"
"-device" "virtio-9p-pci,id=nix-store,fsdev=nix-store,mount_tag=nix-store"
"-nographic"
];
in pkgs.writeShellScriptBin "run-vm" ''
exec ${qemu-path} ${lib.escapeShellArgs qemu-args}
'';
}