Skip to content

Commit

Permalink
Add Nix support
Browse files Browse the repository at this point in the history
  • Loading branch information
LorenzBischof committed Oct 1, 2024
1 parent 89e029b commit 855157b
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ modules:
install: modules_modules

modules_modules:
$(foreach mod,$(DRIVER),/usr/bin/install -m 644 -D $(mod).ko $($(mod)_DEST_DIR)/$(mod).ko;)
$(foreach mod,$(DRIVER),install -m 644 -D $(mod).ko $($(mod)_DEST_DIR)/$(mod).ko;)
depmod -a -F $(SYSTEM_MAP) $(TARGET)

clean:
Expand Down
63 changes: 63 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
description = "Install Asustor kernel modules on NixOS";

inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
};

outputs = { self, nixpkgs }:
let
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
module =
({ stdenv, lib, kernel, kmod, ... }:

stdenv.mkDerivation rec {
name = "asustor-platform-driver-${version}-${kernel.version}";
version = "0.1";

src = ./.;

hardeningDisable = [ "pic" "format" ];
# Install kmod for depmod dependency if we need it
#nativeBuildInputs = kernel.moduleBuildDependencies ++ [ kmod ];
nativeBuildInputs = kernel.moduleBuildDependencies;

buildFlags = [
"KERNEL_MODULES=${kernel.dev}/lib/modules/${kernel.modDirVersion}"
];
installFlags = [
"KERNEL_MODULES=${placeholder "out"}/lib/modules/${kernel.modDirVersion}"
];

# TODO: check if we need depmod.
preConfigure = ''
sed -i 's|depmod|#depmod|' Makefile
'';

meta = with lib; {
description = "A kernel module to support Asustor devices";
homepage = "https://github.com/mafredri/asustor-platform-driver";
license = licenses.gpl3;
maintainers = [ ];
platforms = platforms.linux;
};
});
in
{
packages.${system}.default = pkgs.callPackage ./default.nix { };
nixosModules.default = ({ config, lib, ... }:
let
asustor-platform-driver = config.boot.kernelPackages.callPackage module { };
in
{
options = {
hardware.asustor.enable = lib.mkEnableOption "Enable the Asustor kernel module";
};
config = lib.mkIf config.hardware.asustor.enable {
boot.extraModulePackages = [ asustor-platform-driver ];
};
});
formatter.${system} = pkgs.nixpkgs-fmt;
};
}

0 comments on commit 855157b

Please sign in to comment.