mirror of
https://codeberg.org/mart-w/nixos-x13s.git
synced 2024-11-21 14:54:49 +01:00
init: x13s module and packages
This commit is contained in:
commit
df8c1f5256
5
.envrc
Normal file
5
.envrc
Normal file
|
@ -0,0 +1,5 @@
|
|||
use flake
|
||||
|
||||
if [ -e .secret.envrc ]; then
|
||||
source .secret.envrc
|
||||
fi
|
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
.secret.envrc
|
64
flake.lock
Normal file
64
flake.lock
Normal file
|
@ -0,0 +1,64 @@
|
|||
{
|
||||
"nodes": {
|
||||
"flake-parts": {
|
||||
"inputs": {
|
||||
"nixpkgs-lib": "nixpkgs-lib"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1704982712,
|
||||
"narHash": "sha256-2Ptt+9h8dczgle2Oo6z5ni5rt/uLMG47UFTR1ry/wgg=",
|
||||
"owner": "hercules-ci",
|
||||
"repo": "flake-parts",
|
||||
"rev": "07f6395285469419cf9d078f59b5b49993198c00",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "hercules-ci",
|
||||
"repo": "flake-parts",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1705856552,
|
||||
"narHash": "sha256-JXfnuEf5Yd6bhMs/uvM67/joxYKoysyE3M2k6T3eWbg=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "612f97239e2cc474c13c9dafa0df378058c5ad8d",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs-lib": {
|
||||
"locked": {
|
||||
"dir": "lib",
|
||||
"lastModified": 1703961334,
|
||||
"narHash": "sha256-M1mV/Cq+pgjk0rt6VxoyyD+O8cOUiai8t9Q6Yyq4noY=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "b0d36bd0a420ecee3bc916c91886caca87c894e9",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"dir": "lib",
|
||||
"owner": "NixOS",
|
||||
"ref": "nixos-unstable",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"flake-parts": "flake-parts",
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
25
flake.nix
Normal file
25
flake.nix
Normal file
|
@ -0,0 +1,25 @@
|
|||
{
|
||||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
flake-parts.url = "github:hercules-ci/flake-parts";
|
||||
};
|
||||
|
||||
outputs =
|
||||
inputs@{ flake-parts, ... }:
|
||||
flake-parts.lib.mkFlake { inherit inputs; } {
|
||||
imports = [ ./packages/part.nix ];
|
||||
|
||||
systems = [
|
||||
"x86_64-linux"
|
||||
"aarch64-linux"
|
||||
];
|
||||
|
||||
perSystem =
|
||||
{ pkgs, ... }:
|
||||
{
|
||||
devShells.default = pkgs.mkShellNoCC { packages = [ pkgs.npins ]; };
|
||||
};
|
||||
|
||||
flake.nixosModules.default = import ./module.nix;
|
||||
};
|
||||
}
|
123
module.nix
Normal file
123
module.nix
Normal file
|
@ -0,0 +1,123 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
let
|
||||
cfg = config.nixos-x13s;
|
||||
|
||||
x13sPackages = import ./packages/default.nix { inherit lib pkgs; };
|
||||
|
||||
dtbName = "sc8280xp-lenovo-thinkpad-x13s.dtb";
|
||||
linuxPackages_x13s = pkgs.linuxPackagesFor x13sPackages."x13s/linux";
|
||||
dtb = "${linuxPackages_x13s.kernel}/dtbs/qcom/${dtbName}";
|
||||
|
||||
alsa-ucm-conf-env.ALSA_CONFIG_UCM2 = "${x13sPackages."x13s/alsa-ucm-conf"}/share/alsa/ucm2";
|
||||
in
|
||||
{
|
||||
options.nixos-x13s = {
|
||||
enable = lib.mkEnableOption "x13s hardware support";
|
||||
|
||||
bluetoothMac = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
description = "mac address to set on boot";
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
environment.systemPackages = [ pkgs.efibootmgr ];
|
||||
|
||||
hardware.enableAllFirmware = true;
|
||||
hardware.firmware = [ x13sPackages."x13s/extra-firmware" ];
|
||||
|
||||
systemd.services.pd-mapper = {
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
|
||||
serviceConfig = {
|
||||
ExecStart = "${lib.getExe x13sPackages.pd-mapper}";
|
||||
Restart = "always";
|
||||
};
|
||||
};
|
||||
|
||||
environment.sessionVariables = alsa-ucm-conf-env;
|
||||
systemd.user.services.pipewire.environment = alsa-ucm-conf-env;
|
||||
systemd.user.services.wireplumber.environment = alsa-ucm-conf-env;
|
||||
|
||||
boot = {
|
||||
loader.efi.canTouchEfiVariables = true;
|
||||
loader.systemd-boot.enable = lib.mkDefault true;
|
||||
loader.systemd-boot.extraFiles = {
|
||||
"${dtbName}" = dtb;
|
||||
};
|
||||
|
||||
supportedFilesystems = lib.mkForce [
|
||||
"ext4"
|
||||
"btrfs"
|
||||
"vfat"
|
||||
];
|
||||
|
||||
initrd.supportedFilesystems = lib.mkForce [
|
||||
"btrfs"
|
||||
"vfat"
|
||||
];
|
||||
|
||||
kernelPackages = linuxPackages_x13s;
|
||||
|
||||
kernelParams = [
|
||||
# jhovold recommended
|
||||
"efi=noruntime"
|
||||
"clk_ignore_unused"
|
||||
"pd_ignore_unused"
|
||||
"arm64.nopauth"
|
||||
|
||||
# blacklist graphics in initrd so the firmware can load from disk
|
||||
"rd.driver.blacklist=msm"
|
||||
];
|
||||
|
||||
initrd = {
|
||||
includeDefaultModules = false;
|
||||
|
||||
kernelModules = [
|
||||
"nvme"
|
||||
"phy-qcom-qmp-pcie"
|
||||
"pcie-qcom"
|
||||
|
||||
"i2c-core"
|
||||
"i2c-hid"
|
||||
"i2c-hid-of"
|
||||
"i2c-qcom-geni"
|
||||
|
||||
"leds_qcom_lpg"
|
||||
"pwm_bl"
|
||||
"qrtr"
|
||||
"pmic_glink_altmode"
|
||||
"gpio_sbu_mux"
|
||||
"phy-qcom-qmp-combo"
|
||||
"gpucc_sc8280xp"
|
||||
"dispcc_sc8280xp"
|
||||
"phy_qcom_edp"
|
||||
"panel-edp"
|
||||
# "msm"
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
# default is performance
|
||||
powerManagement.cpuFreqGovernor = "ondemand";
|
||||
|
||||
systemd.services.bluetooth = {
|
||||
serviceConfig = {
|
||||
# disabled because btmgmt call hangs
|
||||
# ExecStartPre = [
|
||||
# ""
|
||||
# "${pkgs.util-linux}/bin/rfkill block bluetooth"
|
||||
# "${pkgs.bluez5-experimental}/bin/btmgmt public-addr ${cfg.bluetoothMac}"
|
||||
# "${pkgs.util-linux}/bin/rfkill unblock bluetooth"
|
||||
# ];
|
||||
RestartSec = 5;
|
||||
Restart = "on-failure";
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
47
npins/default.nix
Normal file
47
npins/default.nix
Normal file
|
@ -0,0 +1,47 @@
|
|||
# Generated by npins. Do not modify; will be overwritten regularly
|
||||
let
|
||||
data = builtins.fromJSON (builtins.readFile ./sources.json);
|
||||
version = data.version;
|
||||
|
||||
mkSource = spec:
|
||||
assert spec ? type; let
|
||||
path =
|
||||
if spec.type == "Git" then mkGitSource spec
|
||||
else if spec.type == "GitRelease" then mkGitSource spec
|
||||
else if spec.type == "PyPi" then mkPyPiSource spec
|
||||
else if spec.type == "Channel" then mkChannelSource spec
|
||||
else builtins.throw "Unknown source type ${spec.type}";
|
||||
in
|
||||
spec // { outPath = path; };
|
||||
|
||||
mkGitSource = { repository, revision, url ? null, hash, ... }:
|
||||
assert repository ? type;
|
||||
# At the moment, either it is a plain git repository (which has an url), or it is a GitHub/GitLab repository
|
||||
# In the latter case, there we will always be an url to the tarball
|
||||
if url != null then
|
||||
(builtins.fetchTarball {
|
||||
inherit url;
|
||||
sha256 = hash; # FIXME: check nix version & use SRI hashes
|
||||
})
|
||||
else assert repository.type == "Git"; builtins.fetchGit {
|
||||
url = repository.url;
|
||||
rev = revision;
|
||||
# hash = hash;
|
||||
};
|
||||
|
||||
mkPyPiSource = { url, hash, ... }:
|
||||
builtins.fetchurl {
|
||||
inherit url;
|
||||
sha256 = hash;
|
||||
};
|
||||
|
||||
mkChannelSource = { url, hash, ... }:
|
||||
builtins.fetchTarball {
|
||||
inherit url;
|
||||
sha256 = hash;
|
||||
};
|
||||
in
|
||||
if version == 3 then
|
||||
builtins.mapAttrs (_: mkSource) data.pins
|
||||
else
|
||||
throw "Unsupported format version ${toString version} in sources.json. Try running `npins upgrade`"
|
29
npins/sources.json
Normal file
29
npins/sources.json
Normal file
|
@ -0,0 +1,29 @@
|
|||
{
|
||||
"pins": {
|
||||
"alsa-ucm-conf": {
|
||||
"type": "Git",
|
||||
"repository": {
|
||||
"type": "GitHub",
|
||||
"owner": "alsa-project",
|
||||
"repo": "alsa-ucm-conf"
|
||||
},
|
||||
"branch": "master",
|
||||
"revision": "e87dde51d68950537f92af955ad0633437cc419a",
|
||||
"url": "https://github.com/alsa-project/alsa-ucm-conf/archive/e87dde51d68950537f92af955ad0633437cc419a.tar.gz",
|
||||
"hash": "14q6h5h4b6kyywmxf1jq726yrv1bl9q6i2pnfbl1hm7r66vgnaip"
|
||||
},
|
||||
"jhovold-linux": {
|
||||
"type": "Git",
|
||||
"repository": {
|
||||
"type": "GitHub",
|
||||
"owner": "jhovold",
|
||||
"repo": "linux"
|
||||
},
|
||||
"branch": "wip/sc8280xp-v6.7",
|
||||
"revision": "bac95eabe6577faa2773cbe7e91c34fd17ab79a0",
|
||||
"url": "https://github.com/jhovold/linux/archive/bac95eabe6577faa2773cbe7e91c34fd17ab79a0.tar.gz",
|
||||
"hash": "1y8abwa506q9dchqvnaqbb8n3i7nj2jnaxcll1f1476qi0yswc1n"
|
||||
}
|
||||
},
|
||||
"version": 3
|
||||
}
|
64
packages/default.nix
Normal file
64
packages/default.nix
Normal file
|
@ -0,0 +1,64 @@
|
|||
{ lib, pkgs, ... }:
|
||||
let
|
||||
sources = import ../npins;
|
||||
kp = [
|
||||
{
|
||||
name = "x13s-cfg";
|
||||
patch = null;
|
||||
extraStructuredConfig = with lib.kernel; {
|
||||
EFI_ARMSTUB_DTB_LOADER = lib.mkForce yes;
|
||||
OF_OVERLAY = lib.mkForce yes;
|
||||
BTRFS_FS = lib.mkForce yes;
|
||||
BTRFS_FS_POSIX_ACL = lib.mkForce yes;
|
||||
MEDIA_CONTROLLER = lib.mkForce yes;
|
||||
SND_USB_AUDIO_USE_MEDIA_CONTROLLER = lib.mkForce yes;
|
||||
SND_USB = lib.mkForce yes;
|
||||
SND_USB_AUDIO = lib.mkForce module;
|
||||
USB_XHCI_PCI = lib.mkForce module;
|
||||
NO_HZ_FULL = lib.mkForce yes;
|
||||
HZ_100 = lib.mkForce yes;
|
||||
HZ_250 = lib.mkForce no;
|
||||
DRM_AMDGPU = lib.mkForce no;
|
||||
DRM_NOUVEAU = lib.mkForce no;
|
||||
QCOM_TSENS = lib.mkForce yes;
|
||||
NVMEM_QCOM_QFPROM = lib.mkForce yes;
|
||||
ARM_QCOM_CPUFREQ_NVMEM = lib.mkForce yes;
|
||||
VIRTIO_PCI = lib.mkForce module;
|
||||
# forthcoming kernel work: QCOM_PD_MAPPER = lib.mkForce module;
|
||||
};
|
||||
}
|
||||
];
|
||||
|
||||
linux_x13s_pkg =
|
||||
{ buildLinux, ... }@args:
|
||||
let
|
||||
version = "6.7.0";
|
||||
modDirVersion = "${version}";
|
||||
in
|
||||
buildLinux (
|
||||
args
|
||||
// {
|
||||
inherit version modDirVersion;
|
||||
|
||||
src = sources.jhovold-linux;
|
||||
|
||||
kernelPatches = (args.kernelPatches or [ ]) ++ kp;
|
||||
extraMeta.branch = lib.versions.majorMinor version;
|
||||
}
|
||||
// (args.argsOverride or { })
|
||||
);
|
||||
in
|
||||
rec {
|
||||
"x13s/linux" = pkgs.callPackage linux_x13s_pkg { defconfig = "johan_defconfig"; };
|
||||
"x13s/alsa-ucm-conf" = pkgs.alsa-ucm-conf.overrideAttrs (
|
||||
prev: rec {
|
||||
version = "1.2.11-unstable-${builtins.substring 0 7 src.revision}";
|
||||
src = sources.alsa-ucm-conf;
|
||||
}
|
||||
);
|
||||
|
||||
pd-mapper = pkgs.callPackage ./pd-mapper { inherit qrtr; };
|
||||
qrtr = pkgs.callPackage ./qrtr { };
|
||||
|
||||
"x13s/extra-firmware" = pkgs.callPackage ./extra-firmware.nix { };
|
||||
}
|
21
packages/extra-firmware.nix
Normal file
21
packages/extra-firmware.nix
Normal file
|
@ -0,0 +1,21 @@
|
|||
{ stdenvNoCC, fetchFromGitHub }:
|
||||
|
||||
stdenvNoCC.mkDerivation {
|
||||
pname = "x13s-extra-firmware";
|
||||
version = "1.0.0";
|
||||
|
||||
src = fetchFromGitHub {
|
||||
owner = "ironrobin";
|
||||
repo = "x13s-alarm";
|
||||
rev = "efa51c3b519f75b3983aef67855b1561d9828771";
|
||||
sha256 = "sha256-weETbWXz9aL2pDQDKk7fkb1ecQH0qrhUYDs2E5EiJcI=";
|
||||
};
|
||||
|
||||
dontFixup = true;
|
||||
dontBuild = true;
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/lib/firmware/qcom/sc8280xp/LENOVO/21BX
|
||||
cp x13s-firmware/qcvss8280.mbn $out/lib/firmware/qcom/sc8280xp/LENOVO/21BX/
|
||||
'';
|
||||
}
|
6
packages/part.nix
Normal file
6
packages/part.nix
Normal file
|
@ -0,0 +1,6 @@
|
|||
{ lib, withSystem, ... }:
|
||||
{
|
||||
flake.packages.aarch64-linux = withSystem "aarch64-linux" (
|
||||
{ pkgs, ... }: import ./default.nix { inherit lib pkgs; }
|
||||
);
|
||||
}
|
36
packages/pd-mapper/default.nix
Normal file
36
packages/pd-mapper/default.nix
Normal file
|
@ -0,0 +1,36 @@
|
|||
{
|
||||
stdenv,
|
||||
lib,
|
||||
fetchFromGitHub,
|
||||
qrtr,
|
||||
xz,
|
||||
}:
|
||||
|
||||
stdenv.mkDerivation {
|
||||
pname = "pd-mapper";
|
||||
version = "unstable-2023-09-01";
|
||||
|
||||
buildInputs = [
|
||||
qrtr
|
||||
xz
|
||||
];
|
||||
|
||||
src = fetchFromGitHub {
|
||||
owner = "andersson";
|
||||
repo = "pd-mapper";
|
||||
rev = "10997ba7c43a3787a40b6b1b161408033e716374";
|
||||
hash = "sha256-qGrYNoPCxtdpTdbkSmB39+6/pSXml96Aul8b9opF9Lc=";
|
||||
};
|
||||
|
||||
patches = [ ./pd-mapper-firmware-path.diff ];
|
||||
|
||||
installFlags = [ "prefix=$(out)" ];
|
||||
|
||||
meta = with lib; {
|
||||
description = "Qualcomm PD mapper";
|
||||
homepage = "https://github.com/andersson/pd-mapper";
|
||||
license = licenses.bsd3;
|
||||
mainProgram = "pd-mapper";
|
||||
platforms = platforms.aarch64;
|
||||
};
|
||||
}
|
13
packages/pd-mapper/pd-mapper-firmware-path.diff
Normal file
13
packages/pd-mapper/pd-mapper-firmware-path.diff
Normal file
|
@ -0,0 +1,13 @@
|
|||
diff --git a/pd-mapper.c b/pd-mapper.c
|
||||
index 65c4b80..669d9a0 100644
|
||||
--- a/pd-mapper.c
|
||||
+++ b/pd-mapper.c
|
||||
@@ -194,7 +194,7 @@ static int pd_load_map(const char *file)
|
||||
}
|
||||
|
||||
#ifndef ANDROID
|
||||
-#define FIRMWARE_BASE "/lib/firmware/"
|
||||
+#define FIRMWARE_BASE "/run/current-system/firmware/"
|
||||
#else
|
||||
#define FIRMWARE_BASE "/vendor/firmware/"
|
||||
#endif
|
26
packages/qrtr/default.nix
Normal file
26
packages/qrtr/default.nix
Normal file
|
@ -0,0 +1,26 @@
|
|||
{
|
||||
stdenv,
|
||||
lib,
|
||||
fetchFromGitHub,
|
||||
}:
|
||||
|
||||
stdenv.mkDerivation {
|
||||
pname = "qrtr";
|
||||
version = "unstable-2023-01-17";
|
||||
|
||||
src = fetchFromGitHub {
|
||||
owner = "andersson";
|
||||
repo = "qrtr";
|
||||
rev = "d0d471c96e7d112fac6f48bd11f9e8ce209c04d2";
|
||||
hash = "sha256-KF0gCBRw3BDJdK1s+dYhHkokVTHwRFO58ho0IwHPehc=";
|
||||
};
|
||||
|
||||
installFlags = [ "prefix=$(out)" ];
|
||||
|
||||
meta = with lib; {
|
||||
description = "QMI IDL compiler";
|
||||
homepage = "https://github.com/andersson/qrtr";
|
||||
license = licenses.bsd3;
|
||||
platforms = platforms.aarch64;
|
||||
};
|
||||
}
|
Loading…
Reference in a new issue