From 6cffb2f60e579aeb0e11816ad865bdee1f2b06bd Mon Sep 17 00:00:00 2001 From: LorenzBischof <1837725+LorenzBischof@users.noreply.github.com> Date: Sat, 23 Mar 2024 16:01:04 +0100 Subject: [PATCH] Add Nix support --- Makefile | 2 +- README.md | 22 ++++++++++++++++++++ flake.nix | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 flake.nix 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/README.md b/README.md index ed2dee5..9a86579 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,28 @@ make sudo make install ``` +### NixOS +Include the platform drivers in your `flake.nix` as follows: +``` +{ + inputs.asustor-platform-driver.url = "github:mafredri/asustor-platform-driver"; + # optional, not necessary for the module + #inputs.asustor-platform-driver.inputs.nixpkgs.follows = "nixpkgs"; + + outputs = { self, nixpkgs, asustor-platform-driver }: { + # change `yourhostname` to your actual hostname + nixosConfigurations.yourhostname = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + modules = [ + ./configuration.nix + asustor-platform-driver.nixosModules.default + { hardware.asustor.enable = true; } + ]; + }; + }; +} +``` + ## Tips ### Control blinking LEDs with `it87` diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..b6a3035 --- /dev/null +++ b/flake.nix @@ -0,0 +1,62 @@ +{ + 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 + { + 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; + }; +}