nix flake complete, added alternative data storage option
This commit is contained in:
parent
c583ad191d
commit
1f72e01273
1 changed files with 35 additions and 39 deletions
74
flake.nix
74
flake.nix
|
|
@ -1,5 +1,5 @@
|
||||||
{
|
{
|
||||||
description = "Install main.py to data directory with dependencies";
|
description = "py2fa-gtk packaged the Nix way";
|
||||||
|
|
||||||
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-25.11";
|
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-25.11";
|
||||||
|
|
||||||
|
|
@ -7,11 +7,8 @@
|
||||||
let
|
let
|
||||||
system = "x86_64-linux";
|
system = "x86_64-linux";
|
||||||
pkgs = nixpkgs.legacyPackages.${system};
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
packageName = "py2fa-gtk";
|
|
||||||
scriptSource = ./src/main.py;
|
|
||||||
|
|
||||||
# 1. Define Python environment
|
pythonEnv = pkgs.python312.withPackages (ps: with ps; [
|
||||||
python = pkgs.python312.withPackages (ps: with ps; [
|
|
||||||
cryptography
|
cryptography
|
||||||
opencv-python
|
opencv-python
|
||||||
pygobject3
|
pygobject3
|
||||||
|
|
@ -19,52 +16,51 @@
|
||||||
pyzbar
|
pyzbar
|
||||||
]);
|
]);
|
||||||
|
|
||||||
# 2. Define libraries for ZBar (shared object)
|
runtimeLibs = with pkgs; [
|
||||||
zbarLibs = [ pkgs.zbar ];
|
gtk3
|
||||||
|
zbar
|
||||||
|
gobject-introspection
|
||||||
|
];
|
||||||
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
packages.${system}.default = pkgs.stdenv.mkDerivation {
|
packages.${system}.default = pkgs.stdenv.mkDerivation {
|
||||||
name = packageName;
|
name = "py2fa-gtk";
|
||||||
|
|
||||||
|
src = ./src;
|
||||||
|
|
||||||
nativeBuildInputs = [ pkgs.wrapGAppsHook3 ];
|
nativeBuildInputs = [
|
||||||
|
pkgs.wrapGAppsHook3
|
||||||
|
pkgs.makeWrapper
|
||||||
|
];
|
||||||
|
|
||||||
buildInputs = with pkgs; [
|
buildInputs = runtimeLibs ++ [ pythonEnv ];
|
||||||
gtk3
|
|
||||||
pango
|
|
||||||
gdk-pixbuf
|
|
||||||
atk
|
|
||||||
cairo
|
|
||||||
gobject-introspection
|
|
||||||
# Python env included here so the wrapper knows about it
|
|
||||||
python
|
|
||||||
] ++ zbarLibs;
|
|
||||||
|
|
||||||
dontUnpack = true;
|
dontBuild = true;
|
||||||
|
|
||||||
installPhase = ''
|
installPhase = ''
|
||||||
mkdir -p $out/bin
|
runHook preInstall
|
||||||
|
|
||||||
cat > $out/bin/${packageName} <<EOF
|
# A. Create standard directory structure in the Nix Store
|
||||||
#!/bin/sh
|
mkdir -p $out/bin $out/share/py2fa-gtk
|
||||||
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}
|
# B. Copy the python script to the store (Read-Only)
|
||||||
|
cp main.py $out/share/py2fa-gtk/main.py
|
||||||
|
|
||||||
|
# C. Create the binary executable
|
||||||
|
# We wrap the python executable.
|
||||||
|
# 1. We tell it to run our specific script.
|
||||||
|
# 2. We inject the ZBar library path so pyzbar works.
|
||||||
|
makeWrapper ${pythonEnv}/bin/python3 $out/bin/py2fa-gtk \
|
||||||
|
--add-flags "$out/share/py2fa-gtk/main.py" \
|
||||||
|
--prefix LD_LIBRARY_PATH : "${pkgs.lib.makeLibraryPath [ pkgs.zbar ]}"
|
||||||
|
|
||||||
|
runHook postInstall
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
# wrapGAppsHook runs automatically after installPhase.
|
||||||
|
# It will see the binary in $out/bin/py2fa-gtk and double-wrap it
|
||||||
|
# to inject XDG_DATA_DIRS and GI_TYPELIB_PATH (fixing Pango/GTK).
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue