如何在 NixOS 中构建 px4_drv 内核模块?
How to build px4_drv kernel module in NixOS?
我正在按照以下说明操作:https://github.com/nns779/px4_drv
make
目录下fwtool
建立it930x-firmware.bin
driver
下的 make
构建 px4_drv
内核模块。
我写了这两个 nix expr:
$ cat ./it930x.nix
{ stdenv, fetchFromGitHub, fetchzip }:
stdenv.mkDerivation rec {
pname = "it930x-firmware";
version = "1";
src = fetchFromGitHub {
owner = "nns779";
repo = "px4_drv";
rev = "90e0a4b30b812e7e5fff4483144f165de8914157";
sha256 = "1s9y5szv9i8dj6pnbkph48nikzf1bhkj592pczbq7hy31xr60hmw";
};
plexSrc = fetchzip {
url = "http://plex-net.co.jp/plex/pxw3u4/pxw3u4_BDA_ver1x64.zip";
sha256 = "1ky28m8hv86vivk2clps5qpmlrmlvfya8qcfmcvpd3n2kisbqsrl";
};
sourceRoot = "fwtool/";
postUnpack = ''
cp "$plexSrc/pxw3u4_BDA_ver1x64/PXW3U4.sys" .
'';
installPhase = ''
mkdir -p $out/lib/firmware/
./fwtool PXW3U4.sys $out/lib/firmware/it930x-firmware.bin
'';
meta = with stdenv.lib; {
description = "it930x-firmware for px4_drv";
homepage = https://github.com/nns779/px4_drv;
license = licenses.gpl2;
};
}
$ cat ./px4_drv.nix
{ stdenv, fetchFromGitHub, kernel, it930x-firmware }:
stdenv.mkDerivation rec {
pname = "px4_drv";
version = "1";
src = fetchFromGitHub {
owner = "nns779";
repo = "px4_drv";
rev = "90e0a4b30b812e7e5fff4483144f165de8914157";
sha256 = "1s9y5szv9i8dj6pnbkph48nikzf1bhkj592pczbq7hy31xr60hmw";
};
sourceRoot = "driver/";
hardeningDisable = [ "pic" ];
KERNELDIR = "${kernel.dev}/lib/modules/${kernel.modDirVersion}/build";
INSTALL_MOD_PATH = "${out}";
NIX_CFLAGS = ["-Wno-error=cpp"];
nativeBuildInputs = [ it930x-firmware ] ++ kernel.moduleBuildDependencies;
buildFlags = [ "module" ];
installTargets = [ "module-install" ];
meta = with stdenv.lib; {
description = "Kernel module px4_drv";
homepage = https://github.com/nns779/px4_drv;
license = licenses.gpl2;
platforms = platforms.linux;
};
}
(原两码借用b43-firmware
和wireguard
。)
并通过以下方式包含这些内容:
$ cat ./configuration.nix
{ config, lib, pkgs, ... }:
let
px4_drv = pkgs.callPackage ./px4_drv.nix;
it930x = pkgs.callPackage ./it930x.nix;
in {
boot.extraModulePackages = [
(px4_drv {
it930x-firmware = it930x;
kernel = pkgs.linux_4_19;
})
];
boot.kernelPackages = pkgs.linuxPackages_4_19;
...
}
结果是:
$ sudo nixos-rebuild test
error: cannot coerce a function to a string, at /nix/store/8zwm55m0754cn9cv6inwm469h0my219r-nixos-20.09pre218482.3320a06049f/nixos/pkgs/stdenv/generic/make-derivation.nix:191:11
(use '--show-trace' to show detailed location information)
nix-shell -E "with import <nixpkgs> {}; callPackage ./px4_drv.nix { it930x-firmware = callPackage ./it930x.nix; kernel = linux_4_19; }"
结果相同。
如何解决?
callPackage
的第二个参数似乎丢失了。您可以使用它来覆盖包的输入或提供额外的输入。
在configuration.nix
中,尝试
px4_drv = pkgs.callPackage ./px4_drv.nix { it930x-firmware = it930x; };
it930x = pkgs.callPackage ./it930x.nix {};
我正在按照以下说明操作:https://github.com/nns779/px4_drv
make
目录下fwtool
建立it930x-firmware.bin
driver
下的 make
构建 px4_drv
内核模块。
我写了这两个 nix expr:
$ cat ./it930x.nix
{ stdenv, fetchFromGitHub, fetchzip }:
stdenv.mkDerivation rec {
pname = "it930x-firmware";
version = "1";
src = fetchFromGitHub {
owner = "nns779";
repo = "px4_drv";
rev = "90e0a4b30b812e7e5fff4483144f165de8914157";
sha256 = "1s9y5szv9i8dj6pnbkph48nikzf1bhkj592pczbq7hy31xr60hmw";
};
plexSrc = fetchzip {
url = "http://plex-net.co.jp/plex/pxw3u4/pxw3u4_BDA_ver1x64.zip";
sha256 = "1ky28m8hv86vivk2clps5qpmlrmlvfya8qcfmcvpd3n2kisbqsrl";
};
sourceRoot = "fwtool/";
postUnpack = ''
cp "$plexSrc/pxw3u4_BDA_ver1x64/PXW3U4.sys" .
'';
installPhase = ''
mkdir -p $out/lib/firmware/
./fwtool PXW3U4.sys $out/lib/firmware/it930x-firmware.bin
'';
meta = with stdenv.lib; {
description = "it930x-firmware for px4_drv";
homepage = https://github.com/nns779/px4_drv;
license = licenses.gpl2;
};
}
$ cat ./px4_drv.nix
{ stdenv, fetchFromGitHub, kernel, it930x-firmware }:
stdenv.mkDerivation rec {
pname = "px4_drv";
version = "1";
src = fetchFromGitHub {
owner = "nns779";
repo = "px4_drv";
rev = "90e0a4b30b812e7e5fff4483144f165de8914157";
sha256 = "1s9y5szv9i8dj6pnbkph48nikzf1bhkj592pczbq7hy31xr60hmw";
};
sourceRoot = "driver/";
hardeningDisable = [ "pic" ];
KERNELDIR = "${kernel.dev}/lib/modules/${kernel.modDirVersion}/build";
INSTALL_MOD_PATH = "${out}";
NIX_CFLAGS = ["-Wno-error=cpp"];
nativeBuildInputs = [ it930x-firmware ] ++ kernel.moduleBuildDependencies;
buildFlags = [ "module" ];
installTargets = [ "module-install" ];
meta = with stdenv.lib; {
description = "Kernel module px4_drv";
homepage = https://github.com/nns779/px4_drv;
license = licenses.gpl2;
platforms = platforms.linux;
};
}
(原两码借用b43-firmware
和wireguard
。)
并通过以下方式包含这些内容:
$ cat ./configuration.nix
{ config, lib, pkgs, ... }:
let
px4_drv = pkgs.callPackage ./px4_drv.nix;
it930x = pkgs.callPackage ./it930x.nix;
in {
boot.extraModulePackages = [
(px4_drv {
it930x-firmware = it930x;
kernel = pkgs.linux_4_19;
})
];
boot.kernelPackages = pkgs.linuxPackages_4_19;
...
}
结果是:
$ sudo nixos-rebuild test
error: cannot coerce a function to a string, at /nix/store/8zwm55m0754cn9cv6inwm469h0my219r-nixos-20.09pre218482.3320a06049f/nixos/pkgs/stdenv/generic/make-derivation.nix:191:11
(use '--show-trace' to show detailed location information)
nix-shell -E "with import <nixpkgs> {}; callPackage ./px4_drv.nix { it930x-firmware = callPackage ./it930x.nix; kernel = linux_4_19; }"
结果相同。
如何解决?
callPackage
的第二个参数似乎丢失了。您可以使用它来覆盖包的输入或提供额外的输入。
在configuration.nix
中,尝试
px4_drv = pkgs.callPackage ./px4_drv.nix { it930x-firmware = it930x; };
it930x = pkgs.callPackage ./it930x.nix {};