diff --git a/base.nix b/base.nix index 7ca7c8d..0645f16 100644 --- a/base.nix +++ b/base.nix @@ -1,10 +1,5 @@ { config, pkgs, lib, ... }: { - # Use the kernel from ./kernel.nix - boot.kernelPackages = let - linux_VisionFive = pkgs.callPackage ./kernel.nix { }; - in lib.mkForce (pkgs.recurseIntoAttrs (pkgs.linuxPackagesFor linux_VisionFive)); - # Remove ZFS boot.supportedFilesystems = lib.mkForce [ "btrfs" "reiserfs" "vfat" "f2fs" "xfs" "ntfs" "cifs" "ext4" "vfat" ]; diff --git a/flake.lock b/flake.lock index 76ca4e7..1640872 100644 --- a/flake.lock +++ b/flake.lock @@ -54,16 +54,16 @@ }, "nixpkgs": { "locked": { - "lastModified": 1652789813, - "narHash": "sha256-90QPw85Vl9+YWQpM/zRjb0/OYI+IODimC4LZufpCIh4=", - "owner": "Madouura", + "lastModified": 1657311595, + "narHash": "sha256-P/uhx5z7pW8OlpJzeShM7iBw7obrgv8CNLRP3G2xcG0=", + "owner": "matthewcroughan", "repo": "nixpkgs", - "rev": "aff8bd5ce0a12ee22402cd9bc6b3c437f0845345", + "rev": "6fd612ce3a656b1bcf5a1222c63294dcfcbb5361", "type": "github" }, "original": { - "owner": "Madouura", - "ref": "dev/linux-riscv", + "owner": "matthewcroughan", + "ref": "mc/visionfive-nix", "repo": "nixpkgs", "type": "github" } @@ -74,7 +74,24 @@ "jh7100_recovery_binary": "jh7100_recovery_binary", "jh7100_secondBoot": "jh7100_secondBoot", "jh71xx-tools": "jh71xx-tools", - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs", + "vendor-kernel": "vendor-kernel" + } + }, + "vendor-kernel": { + "flake": false, + "locked": { + "lastModified": 1657015117, + "narHash": "sha256-WkJBcyAj1sDMZ8s/JqSAOV+CvXHwGYQrs9cLnOv0BkQ=", + "owner": "starfive-tech", + "repo": "linux", + "rev": "943858df470556d0b7f3b31fcc10931603f0f3cc", + "type": "github" + }, + "original": { + "owner": "starfive-tech", + "repo": "linux", + "type": "github" } } }, diff --git a/flake.nix b/flake.nix index 3fdb61d..66100b3 100644 --- a/flake.nix +++ b/flake.nix @@ -1,6 +1,10 @@ { inputs = { nixpkgs.url = "github:matthewcroughan/nixpkgs/mc/visionfive-nix"; + vendor-kernel = { + url = "github:starfive-tech/linux"; + flake = false; + }; jh7100_ddrinit = { url = "https://github.com/starfive-tech/JH7100_ddrinit/releases/download/ddrinit-2133-211102/ddrinit-2133-211102.bin.out"; flake = false; @@ -18,17 +22,21 @@ flake = false; }; }; - outputs = { self, nixpkgs, jh71xx-tools, jh7100_recovery_binary, jh7100_secondBoot, jh7100_ddrinit }: + outputs = { self, nixpkgs, jh71xx-tools, jh7100_recovery_binary, jh7100_secondBoot, jh7100_ddrinit, vendor-kernel }: let system = "x86_64-linux"; - pkgs = import nixpkgs { inherit system; }; + pkgs = import nixpkgs { inherit system; overlays = [ self.overlay ]; }; modules = [ + { nixpkgs.overlays = [ self.overlay ]; } "${nixpkgs}/nixos/modules/installer/sd-card/sd-image-riscv64-visionfive-installer.nix" ./base.nix ./configuration.nix ]; in { + overlay = final: prev: { + linuxPackages_visionfive = final.linuxPackagesFor ((final.callPackage ./kernel.nix { inherit vendor-kernel; }).override { patches = []; }); + }; apps.${system} = { flashBootloader = let diff --git a/kernel.nix b/kernel.nix index 4f519cb..1063444 100644 --- a/kernel.nix +++ b/kernel.nix @@ -1,26 +1,33 @@ { lib , fetchFromGitHub , buildLinux +, vendor-kernel , ... } @ args: let - modDirVersion = "5.18.5"; + kernelVersion = rec { + # Fully constructed string, example: "5.10.0-rc5". + string = "${version + "." + patchlevel + "." + sublevel + (lib.optionalString (extraversion != "") extraversion)}"; + file = "${vendor-kernel}/Makefile"; + version = toString (builtins.match ".+VERSION = ([0-9]+).+" (builtins.readFile file)); + patchlevel = toString (builtins.match ".+PATCHLEVEL = ([0-9]+).+" (builtins.readFile file)); + sublevel = toString (builtins.match ".+SUBLEVEL = ([0-9]+).+" (builtins.readFile file)); + # rc, next, etc. + extraversion = toString (builtins.match ".+EXTRAVERSION = ([a-z0-9-]+).+" (builtins.readFile file)); + }; + modDirVersion = "${kernelVersion.string}"; in buildLinux (args // { inherit modDirVersion; version = "${modDirVersion}-visionfive"; - src = fetchFromGitHub { - owner = "starfive-tech"; - repo = "linux"; - rev = "8fb50a9b3e5d401d4ec169c858e8b7ba0a542955"; - sha256 = "sha256-kjOoNJhmmQdpmtx0m1ZovH3mj2x4NB6iInEknxZq8Dw="; - }; + src = vendor-kernel; kernelPatches = []; defconfig = "starfive_jh7100_fedora_defconfig"; structuredExtraConfig = with lib.kernel; { + KEXEC = yes; SERIAL_8250_DW = yes; PINCTRL_STARFIVE = yes; @@ -34,7 +41,6 @@ in buildLinux (args // { }; extraMeta = { - branch = "visionfive-5.18.y"; description = "Linux kernel for StarFive's JH7100 RISC-V SoC (VisionFive)"; platforms = [ "riscv64-linux" ]; hydraPlatforms = [ "riscv64-linux" ];