chore(Nix): add Makefile steps for building nix package

This commit is contained in:
William Edwards
2025-06-22 23:04:02 -07:00
parent a355be7ddd
commit 786e5229da
3 changed files with 127 additions and 0 deletions

1
.gitignore vendored
View File

@@ -7,3 +7,4 @@ dist
settings.mk
RyzenAdj
.gut_editor_config.json
result

View File

@@ -270,6 +270,28 @@ deploy-ext: dist-ext ## Build and deploy systemd extension to remote device
ssh $(SSH_USER)@$(SSH_HOST) systemd-sysext status
.PHONY: deploy-nix
deploy-nix: dist-nix ## Build and deploy the nix package to a remote device
nix copy $$(cat ./dist/opengamepadui.nix) --to ssh://$(SSH_USER)@$(SSH_HOST)
@echo "Copied OpenGamepadUI package: $$(cat ./dist/opengamepadui.nix)"
@echo "Modifying config to use package"
@DEPLOY_SCRIPT=$$(mktemp); set -e; \
echo "set -ex" >> $$DEPLOY_SCRIPT; \
echo "echo 'Removing old package references'" >> $$DEPLOY_SCRIPT; \
echo "sed -i '/.*programs.opengamepadui.package.*/d' /etc/nixos/configuration.nix" >> $$DEPLOY_SCRIPT; \
echo "echo 'Setting opengamepadui package in /etc/nixos/configuration.nix'" >> $$DEPLOY_SCRIPT; \
echo "sed -i 's|^}| programs.opengamepadui.package = $$(cat ./dist/opengamepadui.nix);\n}|g' /etc/nixos/configuration.nix" >> $$DEPLOY_SCRIPT; \
echo "echo 'Applying new configuration'" >> $$DEPLOY_SCRIPT; \
echo "nixos-rebuild switch --impure" >> $$DEPLOY_SCRIPT; \
echo "echo 'Applying new configuration'" >> $$DEPLOY_SCRIPT; \
echo "rm $$DEPLOY_SCRIPT" >> $$DEPLOY_SCRIPT; \
echo "Copying deployment script to target device"; \
scp $$DEPLOY_SCRIPT $(SSH_USER)@$(SSH_HOST):$$DEPLOY_SCRIPT; \
echo "Executing deployment script"; \
ssh -t $(SSH_USER)@$(SSH_HOST) sudo bash $$DEPLOY_SCRIPT; \
rm $$DEPLOY_SCRIPT
.PHONY: enable-debug
enable-debug: ## Set OpenGamepadUI command to use remote debug on target device
ssh $(SSH_USER)@$(SSH_HOST) mkdir -p .config/environment.d
@@ -336,6 +358,18 @@ dist/update.zip: build/metadata.json
cp $(CACHE_DIR)/update.zip $@
.PHONY: dist-nix
dist-nix: dist/opengamepadui.nix ## Create a nix package
dist/opengamepadui.nix: $(IMPORT_DIR) $(PROJECT_FILES)
@echo "Building nix package"
mkdir -p dist
nix build --impure \
--expr 'with import (builtins.getFlake "gitlab:shadowapex/os-flake?ref=main").inputs.nixpkgs {}; callPackage ./package/nix/package.nix {}'
echo $$(file result | cut -d' ' -f5) > $@
@rm result
@echo "Built OpenGamepadUI package: $$(cat ./dist/opengamepadui.nix)"
# https://blogs.igalia.com/berto/2022/09/13/adding-software-to-the-steam-deck-with-systemd-sysext/
.PHONY: dist-ext
dist-ext: dist/opengamepadui.raw ## Create a systemd-sysext extension archive

92
package/nix/package.nix Normal file
View File

@@ -0,0 +1,92 @@
{
cargo,
gamescope,
godot_4_4,
hwdata,
lib,
mesa-demos,
nix-update-script,
pkg-config,
rustPlatform,
stdenv,
udev,
upower,
withDebug ? false,
}:
stdenv.mkDerivation (finalAttrs: {
pname = "opengamepadui";
version = "latest";
buildType = if withDebug then "debug" else "release";
src = ../..;
cargoDeps = rustPlatform.fetchCargoVendor {
inherit (finalAttrs) src;
sourceRoot = "OpenGamepadUI/${finalAttrs.cargoRoot}";
hash = "sha256-vgaa7Pe0lksiGEpQbn2he5CzhVWoHUSPuXqCwSkoDco=";
};
cargoRoot = "extensions";
nativeBuildInputs = [
cargo
godot_4_4
pkg-config
rustPlatform.cargoSetupHook
];
dontStrip = withDebug;
env =
let
versionAndRelease = lib.splitString "-" godot_4_4.version;
in
{
GODOT = lib.getExe godot_4_4;
GODOT_VERSION = lib.elemAt versionAndRelease 0;
GODOT_RELEASE = lib.elemAt versionAndRelease 1;
EXPORT_TEMPLATE = "${godot_4_4.export-template}/share/godot/export_templates";
BUILD_TYPE = "${finalAttrs.buildType}";
};
makeFlags = [ "PREFIX=$(out)" ];
buildFlags = [ "build" ];
preBuild = ''
# Godot looks for export templates in HOME
export HOME=$(mktemp -d)
mkdir -p $HOME/.local/share/godot/
ln -s "$EXPORT_TEMPLATE" "$HOME"/.local/share/godot/
make clean
'';
postInstall =
let
runtimeDependencies = [
gamescope
hwdata
mesa-demos
udev
upower
];
in
''
# The Godot binary looks in "../lib" for gdextensions
mkdir -p $out/share/lib
mv $out/share/opengamepadui/*.so $out/share/lib
patchelf --add-rpath ${lib.makeLibraryPath runtimeDependencies} $out/share/lib/*.so
'';
passthru.updateScript = nix-update-script { };
meta = {
description = "Open source gamepad-native game launcher and overlay";
homepage = "https://github.com/ShadowBlip/OpenGamepadUI";
license = lib.licenses.gpl3Only;
platforms = [ "x86_64-linux" ];
maintainers = with lib.maintainers; [ shadowapex ];
mainProgram = "opengamepadui";
};
})