70 lines
1.6 KiB
Nix
70 lines
1.6 KiB
Nix
{
|
|
description = "Install main.py to data directory with dependencies";
|
|
|
|
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-25.11";
|
|
|
|
outputs = { self, nixpkgs }:
|
|
let
|
|
system = "x86_64-linux";
|
|
pkgs = nixpkgs.legacyPackages.${system};
|
|
packageName = "py2fa-gtk";
|
|
scriptSource = ./src/main.py;
|
|
|
|
# 1. Define Python environment
|
|
python = pkgs.python312.withPackages (ps: with ps; [
|
|
cryptography
|
|
opencv-python
|
|
pygobject3
|
|
pyotp
|
|
pyzbar
|
|
]);
|
|
|
|
# 2. Define libraries for ZBar (shared object)
|
|
zbarLibs = [ pkgs.zbar ];
|
|
|
|
in
|
|
{
|
|
packages.${system}.default = pkgs.stdenv.mkDerivation {
|
|
name = packageName;
|
|
|
|
nativeBuildInputs = [ pkgs.wrapGAppsHook3 ];
|
|
|
|
buildInputs = with pkgs; [
|
|
gtk3
|
|
pango
|
|
gdk-pixbuf
|
|
atk
|
|
cairo
|
|
gobject-introspection
|
|
# Python env included here so the wrapper knows about it
|
|
python
|
|
] ++ zbarLibs;
|
|
|
|
dontUnpack = true;
|
|
|
|
installPhase = ''
|
|
mkdir -p $out/bin
|
|
|
|
cat > $out/bin/${packageName} <<EOF
|
|
#!/bin/sh
|
|
export LD_LIBRARY_PATH="${pkgs.lib.makeLibraryPath zbarLibs}:\$LD_LIBRARY_PATH"
|
|
|
|
TARGET_DIR="\$HOME/.local/share/${packageName}"
|
|
TARGET_FILE="\$TARGET_DIR/main.py"
|
|
|
|
mkdir -p "\$TARGET_DIR"
|
|
|
|
if [ ! -f "\$TARGET_FILE" ]; then
|
|
echo "Installing main.py to \$TARGET_FILE..."
|
|
cp "${scriptSource}" "\$TARGET_FILE"
|
|
chmod +w "\$TARGET_FILE"
|
|
fi
|
|
|
|
exec ${python}/bin/python3 "\$TARGET_FILE" "\$@"
|
|
EOF
|
|
|
|
chmod +x $out/bin/${packageName}
|
|
'';
|
|
};
|
|
};
|
|
}
|