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 6cffb2f
Show file tree
Hide file tree
Showing 3 changed files with 85 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
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
62 changes: 62 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -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;
};
}

0 comments on commit 6cffb2f

Please sign in to comment.