From e9eb05fc7d05009bd31fc0c3f9140f3d584ff932 Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Sun, 22 Jun 2025 18:07:04 +0200 Subject: add default.nix and shell.nix --- .gitignore | 4 +- 0001-force-frozen-true.patch | 27 +++++++ ...nvocation-use-python-script-as-entrypoint.patch | 34 +++++++++ default.nix | 86 ++++++++++++++++++++++ pystitch.nix | 17 +++++ shell.nix | 28 +++++++ 6 files changed, 195 insertions(+), 1 deletion(-) create mode 100644 0001-force-frozen-true.patch create mode 100644 0002-plugin-invocation-use-python-script-as-entrypoint.patch create mode 100644 default.nix create mode 100644 pystitch.nix create mode 100644 shell.nix diff --git a/.gitignore b/.gitignore index e0cc640f..15540606 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,6 @@ __pycache__ *.spec *.zip *.tar.gz -*.po *.log dist/ build/ @@ -33,3 +32,6 @@ logs/ /DEBUG /PROFILE /profile* + +# nix +/result diff --git a/0001-force-frozen-true.patch b/0001-force-frozen-true.patch new file mode 100644 index 00000000..ef345bb0 --- /dev/null +++ b/0001-force-frozen-true.patch @@ -0,0 +1,27 @@ +From af541a4f8ddda287f74687327e4ed89b79557777 Mon Sep 17 00:00:00 2001 +From: tropf +Date: Mon, 5 Aug 2024 21:25:33 +0200 +Subject: [PATCH 1/3] force frozen=true + +Enforce installation in frozen mode, i.e. as a packaged version where +source can not be modified. +--- + inkstitch.py | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/inkstitch.py b/inkstitch.py +index 50f33d19..398465ca 100644 +--- a/inkstitch.py ++++ b/inkstitch.py +@@ -40,7 +40,7 @@ else: + ini = {} + # -------------------------------------------------------------------------------------------- + +-running_as_frozen = getattr(sys, 'frozen', None) is not None # check if running from pyinstaller bundle ++running_as_frozen = True + + if not running_as_frozen: # override running_as_frozen from DEBUG.toml - for testing + if safe_get(ini, "DEBUG", "force_frozen", default=False): +-- +2.36.0 + diff --git a/0002-plugin-invocation-use-python-script-as-entrypoint.patch b/0002-plugin-invocation-use-python-script-as-entrypoint.patch new file mode 100644 index 00000000..3db643c9 --- /dev/null +++ b/0002-plugin-invocation-use-python-script-as-entrypoint.patch @@ -0,0 +1,34 @@ +From a86412c57833c24743214c9d3abb76093365769f Mon Sep 17 00:00:00 2001 +From: tropf +Date: Mon, 5 Aug 2024 21:26:13 +0200 +Subject: [PATCH 2/3] plugin invocation: use python script as entrypoint + +Ink/Stitch is invoked by calling a script with command line parameters. +Depending on the distribution format, this is bundled into a standalone +binary -- at least for vanilla Ink/Stitch. For the nix version, we +follow manual install, which does *not* bundle the file. Hence, the +generation is patched to treat this packaged install as manual install, +and to still refer to the python file. + +To keep the patchset small, only an if statement is changed, with the +intent of only using the else path. +--- + lib/inx/utils.py | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/lib/inx/utils.py b/lib/inx/utils.py +index 9168f2a2..00313639 100755 +--- a/lib/inx/utils.py ++++ b/lib/inx/utils.py +@@ -21,7 +21,7 @@ def build_environment(): + extensions=['jinja2.ext.i18n'] + ) + +- if "BUILD" in os.environ: ++ if False: + # building a ZIP release, with inkstitch packaged as a binary + # Command tag and icons path + if sys.platform == "win32": +-- +2.36.0 + diff --git a/default.nix b/default.nix new file mode 100644 index 00000000..912d1b8d --- /dev/null +++ b/default.nix @@ -0,0 +1,86 @@ +{ + pkgs ? import {}, +}: +let + version = "git"; + dependencies = + with pkgs.python3.pkgs; + [ + (callPackage ./pystitch.nix {}) + inkex + wxpython + networkx + shapely + lxml + platformdirs + numpy + jinja2 + requests + colormath2 + flask + fonttools + trimesh + scipy + diskcache + flask-cors + ] + # Inkstitch uses the builtin tomllib instead when Python >=3.11 + ++ lib.optional (pythonOlder "3.11") tomli; + pyEnv = pkgs.python3.withPackages (_: dependencies); +in +pkgs.python3.pkgs.buildPythonApplication { + pname = "inkstitch"; + inherit version; + pyproject = false; # Uses a Makefile (yikes) + + src = pkgs.nix-gitignore.gitignoreSource [] ./.; + + nativeBuildInputs = [ + pkgs.gettext + pkgs.pyenv + ]; + + inherit dependencies; + + env = { + # to overwrite version string + GITHUB_REF = version; + BUILD = "nixpkgs"; + }; + makeFlags = [ "manual" ]; + + installPhase = '' + runHook preInstall + + mkdir -p $out/share/inkscape/extensions + cp -a . $out/share/inkscape/extensions/inkstitch + + runHook postInstall + ''; + + patches = [ + ./0001-force-frozen-true.patch + ./0002-plugin-invocation-use-python-script-as-entrypoint.patch + ]; + + postPatch = '' + # Add shebang with python dependencies + substituteInPlace lib/inx/utils.py --replace-fail ' interpreter="python"' "" + sed -i -e '1i#!${pyEnv.interpreter}' inkstitch.py + chmod a+x inkstitch.py + ''; + + nativeCheckInputs = with pkgs.python3.pkgs; [ + pytestCheckHook + ]; + + meta = { + description = "Inkscape extension for machine embroidery design"; + homepage = "https://inkstitch.org/"; + license = with pkgs.lib.licenses; [ gpl3Plus ]; + maintainers = with pkgs.lib.maintainers; [ + tropf + pluiedev + ]; + }; +} diff --git a/pystitch.nix b/pystitch.nix new file mode 100644 index 00000000..0785b5c1 --- /dev/null +++ b/pystitch.nix @@ -0,0 +1,17 @@ +{ + pkgs ? import {}, +}: +with pkgs.python312Packages; + +buildPythonPackage { + pname = "pystitch"; + version = "0-git"; + src = pkgs.fetchFromGitHub { + owner = "inkstitch"; + repo = "pystitch"; + rev = "6771fbbbc265acc0ac48c7b0a8e3474a86f0c9a9"; + hash = "sha256-TkaVaiCzmwcb4Yke+yK68UvW6aMTCbwaxSMbZc+tk5Q="; + }; + build-system = [setuptools]; + pyproject = true; +} diff --git a/shell.nix b/shell.nix new file mode 100644 index 00000000..f75e9b28 --- /dev/null +++ b/shell.nix @@ -0,0 +1,28 @@ +{ pkgs ? import {} }: + +pkgs.mkShell { + buildInputs = [ + (pkgs.python3.withPackages (ps: with ps; [ + pytest + platformdirs + + inkex + (callPackage ./pystitch.nix {}) + wxpython + networkx + shapely + lxml + appdirs + numpy + jinja2 + requests + colormath2 + flask + fonttools + trimesh + scipy + diskcache + flask-cors + ])) + ]; +} -- cgit v1.2.3