try 2 , nix run copies the script to a dir... without checking if it's there, i should add alternate store location to nix-ran version

This commit is contained in:
TheK0tYaRa 2025-12-10 23:42:39 +02:00
parent 9ace38e77c
commit c583ad191d
4 changed files with 69 additions and 73 deletions

46
flake.lock generated
View file

@ -1,59 +1,25 @@
{ {
"nodes": { "nodes": {
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1731533236,
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1751274312, "lastModified": 1765311797,
"narHash": "sha256-/bVBlRpECLVzjV19t5KMdMFWSwKLtb5RyXdjz3LJT+g=", "narHash": "sha256-mSD5Ob7a+T2RNjvPvOA1dkJHGVrNVl8ZOrAwBjKBDQo=",
"owner": "NixOS", "owner": "nixos",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "50ab793786d9de88ee30ec4e4c24fb4236fc2674", "rev": "09eb77e94fa25202af8f3e81ddc7353d9970ac1b",
"type": "github" "type": "github"
}, },
"original": { "original": {
"owner": "NixOS", "owner": "nixos",
"ref": "nixos-24.11", "ref": "nixos-25.11",
"repo": "nixpkgs", "repo": "nixpkgs",
"type": "github" "type": "github"
} }
}, },
"root": { "root": {
"inputs": { "inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs" "nixpkgs": "nixpkgs"
} }
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
} }
}, },
"root": "root", "root": "root",

View file

@ -1,40 +1,70 @@
{ {
description = "run py2fa-gtk"; description = "Install main.py to data directory with dependencies";
inputs = { inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-25.11";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }: outputs = { self, nixpkgs }:
flake-utils.lib.eachDefaultSystem (system:
let let
pkgs = import nixpkgs { inherit system; }; system = "x86_64-linux";
python = pkgs.python312 or pkgs.python3; pkgs = nixpkgs.legacyPackages.${system};
in { packageName = "py2fa-gtk";
devShells.default = pkgs.mkShell { scriptSource = ./src/main.py;
name = "py2fa-gtk-shell";
nativeBuildInputs = [ # 1. Define Python environment
pkgs.gobject-introspection python = pkgs.python312.withPackages (ps: with ps; [
];
buildInputs = [
(python.withPackages (ps: with ps; [
cryptography cryptography
opencv4 opencv-python
pygobject3 pygobject3
pyotp pyotp
pyzbar pyzbar
])) ]);
pkgs.gtk3
pkgs.zbar
];
shellHook = '' # 2. Define libraries for ZBar (shared object)
echo "Environment ready. Run the app with:" zbarLibs = [ pkgs.zbar ];
echo " python main.py"
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}
''; '';
}; };
}); };
} }