nixphone stuff

This commit is contained in:
Henry Hiles 2026-11-09 20:36:07 -05:00
commit f0fca1bad4
Signed by: Henry-Hiles
SSH key fingerprint: SHA256:VKQUdS31Q90KvX7EkKMHMBpUspcmItAh86a+v7PGiIs
3 changed files with 433 additions and 236 deletions

View file

@ -0,0 +1,41 @@
# Fixes for things that don't cross-compile (they run host binaries at build time).
{
inputs,
...
}:
{
nixpkgs.overlays = [
(final: prev: {
gnome = prev.gnome // {
nixos-gsettings-overrides = prev.gnome.nixos-gsettings-overrides.override {
glib = final.buildPackages.glib;
};
};
})
];
# The cache builder doesn't find gtk-query-immodules-3.0 when cross compiling,
# and GNOME Shell connects apps to IBus itself, so the GTK module isn't used anyway.
i18n.inputMethod.enableGtk3 = false;
# nix-maid runs the host mustache-go at build time, swap in a copy of its core
# module that uses the build platform's one for that step.
# TODO: upstream (use pkgs.buildPackages.mustache-go in core.nix)
maid.sharedModules =
let
core = "${inputs.nix-maid}/src/maid/modules/core.nix";
in
[
{
disabledModules = [ core ];
imports = [
(builtins.toFile "nix-maid-core.nix" (
builtins.replaceStrings
[ "import ../vars.nix" "lib.getExe pkgs.mustache-go" ]
[ "import ${inputs.nix-maid}/src/maid/vars.nix" "lib.getExe pkgs.buildPackages.mustache-go" ]
(builtins.readFile core)
))
];
}
];
}

130
clients/quadphone/cross.nix Normal file
View file

@ -0,0 +1,130 @@
{
inputs,
lib,
config,
...
}:
let
cfg = config.quadphone;
host = config.nixpkgs.hostPlatform;
otherOverlays = lib.init config.nixpkgs.overlays;
# cache-only due to no binfmt
nativePkgs = import inputs.nixpkgs {
localSystem = host;
inherit (config.nixpkgs) config;
};
# Only used to detect which packages the other overlays change.
nativeOverlaid = import inputs.nixpkgs {
localSystem = host;
inherit (config.nixpkgs) config;
overlays = otherOverlays;
};
# The cross toolchain and bootstrapping must stay cross.
# Interpreters too: their package sets splice the interpreter from this set.
toolchainRegex = "(python[0-9]*(Minimal|Full)?|.*[sS]tdenv.*|glibc|libc|libcCross|gcc|libgcc|binutils.*|bintools.*|musl|linuxHeaders)";
drvPathOf = v: (builtins.tryEval v.drvPath).value or null;
tryGet = path: set: (builtins.tryEval (lib.attrByPath path null set)).value or null;
useNative =
path: native:
let
name = lib.concatStringsSep "." path;
in
!(builtins.elem name cfg.crossPackages)
&& builtins.match toolchainRegex name == null
&& lib.isDerivation native
&& lib.meta.availableOn host native
&& (native.meta.license.free or true)
# Trivial builders (runCommand, buildEnv, ...) are never substituted
&& (native.allowSubstitutes or true) != false
&& (native.allowSubstitutes or true) != ""
# Not modified (directly or through a dependency) by another overlay
&& drvPathOf native == drvPathOf (tryGet path nativeOverlaid);
withCrossFunctions =
native: cross:
let
wrap =
n: arg:
let
r = native.${n} arg;
in
if lib.isDerivation r && drvPathOf r == drvPathOf native then
withCrossFunctions r (cross.${n} arg)
else
cross.${n} arg;
isBuilder = n: builtins.match builderRegex n != null && !lib.elem n customisers;
in
# Attr names must only depend on native, forcing cross here can recurse.
native
// lib.genAttrs (lib.filter (n: native ? ${n}) customisers) wrap
// lib.genAttrs (lib.filter isBuilder (builtins.attrNames native)) (n: cross.${n});
builderRegex = "(pkgs|.*[pP]ackages|callPackage|(mk|build|with|wrap)([A-Z].*)?)";
customisers = [
"override"
"overrideAttrs"
"overrideDerivation"
"overridePythonAttrs"
"overrideModAttrs"
];
pick =
path: v:
if lib.isDerivation v then
let
native = tryGet path nativePkgs;
in
if useNative path native then withCrossFunctions native v else v
# Package sets like kdePackages, gnomeExtensions, lixPackageSets.lix_2_96
else if builtins.length path <= 2 && builtins.isAttrs v && (v.recurseForDerivations or false) then
builtins.mapAttrs (name: pick (path ++ [ name ])) v
else
v;
in
{
options.quadphone.crossPackages = lib.mkOption {
type = with lib.types; listOf str;
default = [ ];
description = ''
Top-level attribute names that should always be cross-compiled instead of
substituted from the binary cache (i.e. ones that turn out not to be cached).
'';
};
config = {
nixpkgs.buildPlatform = "x86_64-linux";
# Must be the last overlay, see otherOverlays.
nixpkgs.overlays = lib.mkOrder 10000 [
(
_: prev:
lib.optionalAttrs (prev.stdenv.hostPlatform.config != prev.stdenv.buildPlatform.config) {
stdenv = prev.overrideCC prev.stdenv (
prev.stdenv.cc.override {
bintools = prev.stdenv.cc.bintools.override {
extraBuildCommands = ''
echo "-rpath-link ${nativePkgs.stdenv.cc.cc.lib}/lib" >> $out/nix-support/libc-ldflags
'';
};
}
);
}
)
(
_: prev:
builtins.mapAttrs (
name: v:
if prev.stdenv.hostPlatform.config == prev.stdenv.buildPlatform.config then v else pick [ name ] v
) prev
)
];
};
}

View file

@ -1,19 +1,21 @@
{ inputs, lib, ... }:
{
inputs,
lib,
config,
crossPkgs,
...
}:
{
imports = [
(
_:
import inputs.nixphone.nixosModules.sdm845-oneplus-fajita {
inherit lib config;
pkgs = crossPkgs;
inputs = inputs.sdm845.inputs;
}
)
imports = [ inputs.nixphone.nixosModules.sdm845-oneplus-fajita ];
quadphone.crossPackages = [
"nix-direnv"
];
# nixphone loads pmi8998_haptics in the initrd, but the kernel config doesn't build it
# TODO: upstream to nixphone
boot.kernelPatches = [
{
name = "pmi8998-haptics";
patch = null;
structuredExtraConfig.INPUT_QCOM_PMI8998_HAPTICS = lib.kernel.module;
}
];
# TODO: flutter apps don't cross compile, and the flake's package isn't cached
programs.nexus.enable = lib.mkForce false;
}