From 6cbbb9581032bd0923773c2279d3ec4a1685c36e Mon Sep 17 00:00:00 2001 From: Bart van der Braak Date: Sat, 26 Oct 2024 17:05:52 +0200 Subject: [PATCH] Add out-of-tree kernel module for Motorcomm yt6801 Network Interface Card (NIC) driver (#7) * Add initial test to run with the new driver install * Fix unpacking by using git source * Change buildinputs and patch commands * Working example of extra yt6801 module * Add fixes * Consolidate changes --- tongfang/nixos/hardware-configuration.nix | 8 ++++- tongfang/nixos/yt6801/default.nix | 43 +++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 tongfang/nixos/yt6801/default.nix diff --git a/tongfang/nixos/hardware-configuration.nix b/tongfang/nixos/hardware-configuration.nix index f10dad2..e84723d 100644 --- a/tongfang/nixos/hardware-configuration.nix +++ b/tongfang/nixos/hardware-configuration.nix @@ -3,6 +3,12 @@ # to /etc/nixos/configuration.nix instead. { config, lib, pkgs, modulesPath, ... }: +let + yt6801 = import ./yt6801/default.nix { + inherit (pkgs) lib stdenv fetchFromGitHub nukeReferences bc; + kernel = pkgs.linuxPackages.kernel; + }; +in { imports = [ (modulesPath + "/installer/scan/not-detected.nix") @@ -11,7 +17,7 @@ boot.initrd.availableKernelModules = [ "nvme" "xhci_pci" "thunderbolt" "usb_storage" "sd_mod" "sdhci_pci" ]; boot.initrd.kernelModules = [ ]; boot.kernelModules = [ "kvm-amd" ]; - boot.extraModulePackages = [ ]; + boot.extraModulePackages = [ yt6801 ]; fileSystems."/" = { device = "/dev/disk/by-uuid/c7cf28c3-5744-45cc-8a81-456d24e44b7a"; diff --git a/tongfang/nixos/yt6801/default.nix b/tongfang/nixos/yt6801/default.nix new file mode 100644 index 0000000..aaad340 --- /dev/null +++ b/tongfang/nixos/yt6801/default.nix @@ -0,0 +1,43 @@ +{ lib, stdenv, fetchFromGitHub, nukeReferences, bc, kernel }: + +stdenv.mkDerivation rec { + pname = "yt6801"; + version = "1.0.29"; + name = "${pname}-${version}-${kernel.version}"; + + src = fetchFromGitHub { + owner = "bartvdbraak"; + repo = pname; + rev = version; + sha256 = "sha256-VEBwcbJcLffIIAP+NIhjiuMkfR+PKybBDnIbxY6zBMA="; + }; + + patchPhase = '' + substituteInPlace ./src/Makefile \ + --replace-fail 'KSRC_BASE = /lib/modules/$(shell uname -r)' "KSRC_BASE = ${KERNELDIR}" + ''; + + hardeningDisable = [ "pic" "format" ]; + KERNELDIR = "${kernel.dev}/lib/modules/${kernel.modDirVersion}"; + nativeBuildInputs = [ bc ] ++ kernel.moduleBuildDependencies; + + preBuild = "cd src"; + buildFlags = [ "modules" ]; + + makeFlags = [ + "ARCH=${stdenv.hostPlatform.linuxArch}" + ] ++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ + "CROSS_COMPILE=${stdenv.cc.targetPrefix}" + ]; + + installFlags = [ "INSTALL_MOD_PATH=${placeholder "out"}" ]; + enableParallelBuilding = true; + + meta = with lib; { + description = "Motorcomm yt6801 Network Interface Card (NIC) driver"; + homepage = "https://www.motor-comm.com/product/ethernet-control-chip"; + license = licenses.gpl2Only; + platforms = platforms.linux; + maintainers = with maintainers; [ bartvdbraak ]; + }; +}