77 lines
2.2 KiB
Nix
77 lines
2.2 KiB
Nix
{
|
|
inputs = {
|
|
nixpkgs.url = "github:nixos/nixpkgs/release-26.05";
|
|
flake-utils.url = "github:numtide/flake-utils";
|
|
|
|
python-games = {
|
|
url = "git+https://github.com/KenT2/python-games.git";
|
|
flake = false;
|
|
};
|
|
};
|
|
|
|
outputs = { nixpkgs, flake-utils, python-games, ... }:
|
|
flake-utils.lib.eachDefaultSystem (system:
|
|
let
|
|
pkgs = import nixpkgs {
|
|
inherit system;
|
|
};
|
|
|
|
python = pkgs.python313;
|
|
|
|
python-with-deps = python.withPackages (python-pkgs: with python-pkgs; [
|
|
pygame
|
|
]);
|
|
in
|
|
{
|
|
packages.default = pkgs.stdenvNoCC.mkDerivation {
|
|
name = "python-games";
|
|
|
|
nativeBuildInputs = with pkgs; [
|
|
makeWrapper
|
|
];
|
|
|
|
src = python-games;
|
|
|
|
installPhase = ''
|
|
mkdir -p $out/bin -p $out/share/python_games -p $out/share/applications
|
|
|
|
# Copy launcher to bin directory
|
|
cp launcher.sh $out/bin/python-games
|
|
|
|
# Copy everything else to share directory
|
|
cp -r . $out/share/python_games
|
|
rm $out/share/python_games/launcher.sh
|
|
|
|
# Substitute paths in the launcher script
|
|
substituteInPlace $out/bin/python-games \
|
|
--replace-fail "cd /home/\$USER/python_games" "cd $out/share/python_games"
|
|
|
|
# Use xdg-open instead of sensible-browser for opening the website
|
|
substituteInPlace $out/bin/python-games \
|
|
--replace-fail "sensible-browser" "${pkgs.xdg-utils}/bin/xdg-open"
|
|
|
|
chmod +x $out/bin/python-games
|
|
|
|
# Wrap the program to allow using packages
|
|
wrapProgram $out/bin/python-games \
|
|
--prefix PATH : "${pkgs.zenity}/bin" \
|
|
--prefix PATH : "${python-with-deps}/bin"
|
|
|
|
# Write desktop entry
|
|
cat <<EOF > $out/share/applications/python-games.desktop
|
|
[Desktop Entry]
|
|
Name=Python Games
|
|
Comment=Examples of games written in Python
|
|
Exec=$out/bin/python-games
|
|
Icon=python
|
|
Terminal=false
|
|
Type=Application
|
|
Categories=Application;Game;
|
|
StartupNotify=true
|
|
EOF
|
|
'';
|
|
};
|
|
}
|
|
);
|
|
}
|