Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ dist
settings.mk
RyzenAdj
.gut_editor_config.json
result
34 changes: 34 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
92 changes: 92 additions & 0 deletions package/nix/package.nix
Original file line number Diff line number Diff line change
@@ -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";
};
})