10.nixos-hardware/microsoft/surface/common/default.nix

85 lines
2.1 KiB
Nix

{
config,
lib,
pkgs,
...
}:
let
inherit (builtins)
attrNames
;
inherit (lib)
mkDefault
mkOption
types
versions
;
supportedKernels = {
"longterm" = {
version = "6.12.19";
hash = "sha256-1zvwV77ARDSxadG2FkGTb30Ml865I6KB8y413U3MZTE=";
};
"stable" = {
version = "6.18.8";
hash = "sha256-N/DF1cJCwdYE6H1I8IeV6GGlqF9yW0yhHQpTjxL/jP8=";
};
};
# Set the version and hash for the kernel sources
srcVersion = supportedKernels.${config.hardware.microsoft-surface.kernelVersion}.version;
srcHash = supportedKernels.${config.hardware.microsoft-surface.kernelVersion}.hash;
# Fetch the latest linux-surface patches
linux-surface = pkgs.fetchFromGitHub {
owner = "linux-surface";
repo = "linux-surface";
rev = "faedd344762f9db3fe3c79e4f085d4ca7891e0c8"; # debian-6.18.8-1
hash = "sha256-2t5tMvne8W1q/hCO+O5XfuHj6DAzO6iKtCC6egXsWWM=";
};
# Fetch and build the kernel
inherit (pkgs.callPackage ./kernel/linux-package.nix { })
linuxPackage
surfacePatches
;
kernelPatches = surfacePatches {
version = srcVersion;
patchFn = ./kernel/${versions.majorMinor srcVersion}/patches.nix;
patchSrc = linux-surface + "/patches/${versions.majorMinor srcVersion}";
};
kernelPackages = linuxPackage {
inherit kernelPatches;
version = srcVersion;
sha256 = srcHash;
ignoreConfigErrors = true;
};
in
{
options.hardware.microsoft-surface.kernelVersion = mkOption {
description = "Kernel Version to use (patched for MS Surface)";
type = types.enum (attrNames supportedKernels);
default = "longterm";
};
config = {
boot = {
inherit kernelPackages;
# Seems to be required to properly enable S0ix "Modern Standby":
kernelParams = mkDefault [ "mem_sleep_default=deep" ];
};
# NOTE: Check the README before enabling TLP:
services.tlp.enable = mkDefault false;
# Needed for wifi firmware, see https://github.com/NixOS/nixos-hardware/issues/364
hardware = {
enableRedistributableFirmware = mkDefault true;
sensor.iio.enable = mkDefault true;
};
};
}