diff --git a/Makefile b/Makefile index f206859..4afa11b 100644 --- a/Makefile +++ b/Makefile @@ -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: diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..6b53d80 --- /dev/null +++ b/flake.nix @@ -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; + }; +}