From ac32649783c9defa976da69b2c683a0c732775ce Mon Sep 17 00:00:00 2001 From: Frank LoTurco Date: Tue, 1 Sep 2026 10:45:21 -0400 Subject: [PATCH] fork: https://github.com/mrshmllow/affinity-nix --- .coderabbit.yaml | 13 + .envrc | 1 + .gitignore | 6 + .yamllint.yaml | 9 + Cargo.lock | 561 +++++++++++++++++++++ Cargo.toml | 14 + LICENSE.txt | 674 ++++++++++++++++++++++++++ README.md | 206 ++++++++ crates/runner/Cargo.toml | 26 + crates/runner/src/check.rs | 115 +++++ crates/runner/src/main.rs | 619 +++++++++++++++++++++++ crates/runner/src/migrate.rs | 117 +++++ default.nix | 13 + flake.lock | 247 ++++++++++ flake.nix | 65 +++ nix/fmt.nix | 14 + nix/hooks.nix | 48 ++ nix/shells.nix | 45 ++ overlay.nix | 22 + packages/affinity-v3/default.nix | 18 + packages/affinity-v3/desktopItems.nix | 30 ++ packages/affinity-v3/icons.nix | 20 + packages/affinity-v3/package.nix | 50 ++ packages/affinity/default.nix | 22 + packages/affinity/desktopItems.nix | 71 +++ packages/affinity/icons.nix | 35 ++ packages/affinity/package.nix | 59 +++ packages/apl/apl-combined.nix | 30 ++ packages/apl/apl.nix | 26 + packages/apl/bootstrap.nix | 37 ++ packages/apl/default.nix | 13 + packages/apl/deps.json | 17 + packages/apl/no-login.patch | 589 ++++++++++++++++++++++ packages/basePrefix.nix | 193 ++++++++ packages/default.nix | 28 ++ packages/dependencies.nix | 30 ++ packages/prefixWithAffinity.nix | 61 +++ packages/registry-patches.nix | 21 + packages/runner/default.nix | 30 ++ packages/runner/package.nix | 88 ++++ packages/sources.nix | 47 ++ packages/wine/default.nix | 21 + packages/wine/packages.nix | 27 ++ packages/wine/symlink.nix | 15 + packages/wine/wrapWithPrefix.nix | 21 + tests/default.nix | 52 ++ tests/pyproject.toml | 18 + tests/uv.lock | 302 ++++++++++++ tests/v2.py | 27 ++ tests/v3.py | 15 + typos.toml | 9 + 51 files changed, 4837 insertions(+) create mode 100644 .coderabbit.yaml create mode 100644 .envrc create mode 100644 .gitignore create mode 100644 .yamllint.yaml create mode 100644 Cargo.lock create mode 100644 Cargo.toml create mode 100644 LICENSE.txt create mode 100644 README.md create mode 100644 crates/runner/Cargo.toml create mode 100644 crates/runner/src/check.rs create mode 100644 crates/runner/src/main.rs create mode 100644 crates/runner/src/migrate.rs create mode 100644 default.nix create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 nix/fmt.nix create mode 100644 nix/hooks.nix create mode 100644 nix/shells.nix create mode 100644 overlay.nix create mode 100644 packages/affinity-v3/default.nix create mode 100644 packages/affinity-v3/desktopItems.nix create mode 100644 packages/affinity-v3/icons.nix create mode 100644 packages/affinity-v3/package.nix create mode 100644 packages/affinity/default.nix create mode 100644 packages/affinity/desktopItems.nix create mode 100644 packages/affinity/icons.nix create mode 100644 packages/affinity/package.nix create mode 100644 packages/apl/apl-combined.nix create mode 100644 packages/apl/apl.nix create mode 100644 packages/apl/bootstrap.nix create mode 100644 packages/apl/default.nix create mode 100644 packages/apl/deps.json create mode 100644 packages/apl/no-login.patch create mode 100644 packages/basePrefix.nix create mode 100644 packages/default.nix create mode 100644 packages/dependencies.nix create mode 100644 packages/prefixWithAffinity.nix create mode 100644 packages/registry-patches.nix create mode 100644 packages/runner/default.nix create mode 100644 packages/runner/package.nix create mode 100644 packages/sources.nix create mode 100644 packages/wine/default.nix create mode 100644 packages/wine/packages.nix create mode 100644 packages/wine/symlink.nix create mode 100644 packages/wine/wrapWithPrefix.nix create mode 100644 tests/default.nix create mode 100644 tests/pyproject.toml create mode 100644 tests/uv.lock create mode 100644 tests/v2.py create mode 100644 tests/v3.py create mode 100644 typos.toml diff --git a/.coderabbit.yaml b/.coderabbit.yaml new file mode 100644 index 0000000..459c372 --- /dev/null +++ b/.coderabbit.yaml @@ -0,0 +1,13 @@ +# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json +language: "en-US" +early_access: false +reviews: + profile: "chill" + request_changes_workflow: false + high_level_summary: false + poem: false + review_status: true + review_details: false + auto_review: + enabled: true + drafts: false diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..15998a3 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +result +.direnv +/.pre-commit-config.yaml +*.AppImage +*.exe +/target diff --git a/.yamllint.yaml b/.yamllint.yaml new file mode 100644 index 0000000..9e821c6 --- /dev/null +++ b/.yamllint.yaml @@ -0,0 +1,9 @@ +extends: default +rules: + line-length: + max: 160 + truthy: + check-keys: false + document-start: + present: false + comments-indentation: disable diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..3bb4df3 --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,561 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "anstream" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "824a212faf96e9acacdbd09febd34438f8f711fb84e09a8916013cd7815ca28d" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "940b3a0ca603d1eade50a4846a2afffd5ef57a9feac2c0e2ec2e14f9ead76000" + +[[package]] +name = "anstyle-parse" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52ce7f38b242319f7cabaa6813055467063ecdc9d355bbb4ce0c68908cd8130e" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" +dependencies = [ + "anstyle", + "once_cell_polyfill", + "windows-sys 0.61.2", +] + +[[package]] +name = "anyhow" +version = "1.0.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470" + +[[package]] +name = "bitflags" +version = "2.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4512299f36f043ab09a583e57bceb5a5aab7a73db1805848e8fef3c9e8c78b3" + +[[package]] +name = "cfg-if" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" + +[[package]] +name = "cfg_aliases" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" + +[[package]] +name = "clap" +version = "4.6.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "473c7e07f409a8d772161724aa8db6a765a2532a70f9667eeb7b49d3d02fbdca" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.6.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b48fea5a88e9ae728a2dcbedbfc0e730f7d60da42e1cb049a83c9fb8b789889" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d012d2b9d65aca7f18f4d9878a045bc17899bba951561ba5ec3c2ba1eed9a061" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 3.0.4", +] + +[[package]] +name = "clap_lex" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8d4a3bb8b1e0c1050499d1815f5ab16d04f0959b233085fb31653fbfc9d98f9" + +[[package]] +name = "colorchoice" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570" + +[[package]] +name = "duct" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e66e9c0c03d094e1a0ba1be130b849034aa80c3a2ab8ee94316bc809f3fa684" +dependencies = [ + "libc", + "os_pipe", + "shared_child", + "shared_thread", +] + +[[package]] +name = "errno" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "is_terminal_polyfill" +version = "1.70.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" + +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" + +[[package]] +name = "libc" +version = "0.2.189" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2" + +[[package]] +name = "log" +version = "0.4.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" + +[[package]] +name = "mutually_exclusive_features" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e94e1e6445d314f972ff7395df2de295fe51b71821694f0b0e1e79c4f12c8577" + +[[package]] +name = "nix" +version = "0.31.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf20d2fde8ff38632c426f1165ed7436270b44f199fc55284c38276f9db47c3d" +dependencies = [ + "bitflags", + "cfg-if", + "cfg_aliases", + "libc", +] + +[[package]] +name = "nu-ansi-term" +version = "0.50.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "once_cell" +version = "1.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" + +[[package]] +name = "once_cell_polyfill" +version = "1.70.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" + +[[package]] +name = "os_pipe" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d8fae84b431384b68627d0f9b3b1245fcf9f46f6c0e3dc902e9dce64edd1967" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" + +[[package]] +name = "proc-macro2" +version = "1.0.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "runner" +version = "0.1.0" +dependencies = [ + "anyhow", + "clap", + "duct", + "mutually_exclusive_features", + "nix", + "tracing", + "tracing-subscriber", + "walkdir", + "xdgdir", +] + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "sharded-slab" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" +dependencies = [ + "lazy_static", +] + +[[package]] +name = "shared_child" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e362d9935bc50f019969e2f9ecd66786612daae13e8f277be7bfb66e8bed3f7" +dependencies = [ + "libc", + "sigchld", + "windows-sys 0.60.2", +] + +[[package]] +name = "shared_thread" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52b86057fcb5423f5018e331ac04623e32d6b5ce85e33300f92c79a1973928b0" + +[[package]] +name = "sigchld" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47106eded3c154e70176fc83df9737335c94ce22f821c32d17ed1db1f83badb1" +dependencies = [ + "libc", + "os_pipe", + "signal-hook", +] + +[[package]] +name = "signal-hook" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d881a16cf4426aa584979d30bd82cb33429027e42122b169753d6ef1085ed6e2" +dependencies = [ + "libc", + "signal-hook-registry", +] + +[[package]] +name = "signal-hook-registry" +version = "1.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b" +dependencies = [ + "errno", + "libc", +] + +[[package]] +name = "smallvec" +version = "1.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "syn" +version = "2.0.117" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "3.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6275cddf4610d1775e6d1fe9469b2e77d0f39fd98fb7450901b821e0c53649f" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "thread_local" +version = "1.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f60246a4944f24f6e018aa17cdeffb7818b76356965d03b07d6a9886e8962185" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "tracing" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" +dependencies = [ + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.117", +] + +[[package]] +name = "tracing-core" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" +dependencies = [ + "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" +dependencies = [ + "log", + "once_cell", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb7f578e5945fb242538965c2d0b04418d38ec25c79d160cd279bf0731c8d319" +dependencies = [ + "nu-ansi-term", + "sharded-slab", + "smallvec", + "thread_local", + "tracing-core", + "tracing-log", +] + +[[package]] +name = "unicode-ident" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" + +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + +[[package]] +name = "valuable" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" + +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + +[[package]] +name = "winapi-util" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-sys" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-targets" +version = "0.53.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3" +dependencies = [ + "windows-link", + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006" + +[[package]] +name = "windows_i686_gnu" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c" + +[[package]] +name = "windows_i686_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.53.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" + +[[package]] +name = "xdgdir" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c93fba109a63f08e168ab02529ddabd99e4ebb78b98ed6bce82e3da52522d235" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..36a5044 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,14 @@ +[workspace] +resolver = "3" +members = ["crates/runner"] + +[workspace.package] +edition = "2024" +version = "0.1.0" + +[workspace.metadata.crane] +name = "affinity-nix" + +[workspace.lints.clippy] +pedantic = { level = "deny" } +nursery = { level = "deny" } diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..f288702 --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/README.md b/README.md new file mode 100644 index 0000000..2b9bbae --- /dev/null +++ b/README.md @@ -0,0 +1,206 @@ +# affinity-nix + +![image](https://github.com/user-attachments/assets/d81f1805-c72b-4999-909e-c5666b5e0a11) + +## About + +Affinity v3 & v2 packaged with Nix! + +Based on https://github.com/lf-/affinity-crimes and https://affinity.liz.pet/, and uses [ElementalWarrior's wine](https://gitlab.winehq.org/ElementalWarrior/wine). + +We also install https://github.com/noahc3/AffinityPluginLoader for a far more pleasant experience. + +> [!WARNING] +> Affinity on Wine is far from perfect and you will likely experience bugs and issues. Please have patience and [report any issues you experience](https://github.com/mrshmllow/affinity-nix/issues/new/choose). + +## Support + +Thank you to my GitHub sponsors! + +![Supporter Graph](./.github/graph.png) + +## Preamble + +> [!TIP] +> We provide a binary cache for this repo. Please [add cache.forall.systems as a substituter](https://cache.forall.systems/) to avoid compiling yourself. + +> [!NOTE] +> This repo does not attempt to redistribute affinity archives. Any instance of caching Canva IP should be reported as a bug. + +User preferences are located in `$XDG_DATA_HOME/affinity/` or `$XDG_DATA_HOME/affinity-v3/` falling back to `$HOME/.local/share/affinity/` or `$HOME/.local/share/affinity-v3/`. + +## How it works + +A wine prefix containing all the necessary dependencies and the affinity installation is built in nix and mounted at runtime. +Overlayfs is used to keep your user preferences intact. [fuse-overlayfs](https://github.com/containers/fuse-overlayfs) will be fallen back on if your kernel rejects unprivileged user namespaces, common on hardened systems. This can reduce performance. + +```mermaid +graph LR; + A([Winetricks])-.->B[Nix Store]; + C([Affinity])-.->B; + D([Wine])-.->B; + + B e1@-->E[Overlayfs]; + F[User Data] e2@<-->E; + + E<-- Mounted @ Runtime -->G[Affinity Application]; +``` + +## Usage Instructions + +### Running Ad-hoc + +```bash +$ nix run github:mrshmllow/affinity-nix#affinity-v3 + +-- v2 versions: + +$ nix run github:mrshmllow/affinity-nix#affinity-photo +$ nix run github:mrshmllow/affinity-nix#affinity-designer +$ nix run github:mrshmllow/affinity-nix#affinity-publisher +``` + +### Installing the applications on your system (Optional) + +#### Install with nix-profile + +```bash +$ nix profile install github:mrshmllow/affinity-nix#affinity-v3 + +-- v2 versions: + +$ nix profile install github:mrshmllow/affinity-nix#affinity-photo +$ nix profile install github:mrshmllow/affinity-nix#affinity-designer +$ nix profile install github:mrshmllow/affinity-nix#affinity-publisher +``` + +#### Install on NixOS / Home Manager with Flakes + +Installing via an overlay is recommended, as the package is `unfree` +making it difficult to use directly. + +Install with NixOS: + +```nix +# flake.nix +{ + inputs = { + affinity-nix.url = "github:mrshmllow/affinity-nix"; + # ... + }; + + outputs = inputs @ { + affinity-nix, + ... + }: { + nixosConfigurations.my-system = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + specialArgs = {inherit inputs;}; + modules = [ + # ... + ({ pkgs, ... }: { + nixpkgs.overlays = [ affinity-nix.overlays.default ]; + + environment.systemPackages = [ pkgs.affinity-v3 ]; + }) + ]; + }; + } +} +``` + +Install with Home Manager: + +```nix +# flake.nix +{ + inputs = { + affinity-nix.url = "github:mrshmllow/affinity-nix"; + # ... + }; + + outputs = inputs @ { + affinity-nix, + ... + }: { + homeConfigurations.my-user = home-manager.lib.homeManagerConfiguration { + pkgs = nixpkgs.legacyPackages."x86_64-linux"; + extraSpecialArgs = {inherit inputs;}; + modules = [ + # ... + ({ pkgs, ... }: { + nixpkgs.overlays = [ affinity-nix.overlays.default ]; + + home.packages = [ pkgs.affinity-v3 ]; + }) + ]; + }; + } +} +``` + +#### Install on NixOS without Flakes + +Install without flakes: + +```nixos +# configuration.nix +{ config, pkgs, ... }: + +let + affinity = import (fetchTarball "https://github.com/mrshmllow/affinity-nix/archive/refs/heads/main.tar.gz"); +in +{ + nixpkgs.overlays = [ + affinity.overlays.default + ]; + + users.users.my-user.packages = with pkgs; [ + affinity-photo + ]; +} +``` + +### Troubleshooting, winetricks, wineboot, and more + +Each package (`v3|photo|designer|publisher`) has the following usage: + +```sh +$ affinity-v3 --help +Usage: affinity-v3 [OPTIONS] [AFFINITY_ARGUMENTS]... [COMMAND] + +Commands: + wine Run wine within sandbox + winetricks Run winetricks within sandbox + wineboot Run wineboot within sandbox + wineserver Run wineserver within sandbox + help Print this message or the help of the given subcommand(s) + +Arguments: + [AFFINITY_ARGUMENTS]... Arguments for affinity application + +Options: + --verbose Make Wine far more verbose + -h, --help Print help + -V, --version Print version + +``` + +> [!TIP] +> Armed with these you should be able to follow https://affinity.liz.pet/v2/misc-troubleshooting/ for troubleshooting steps. + +For example, accessing `wine`: + +```sh +$ affinity-v3 wine +Usage: wine PROGRAM [ARGUMENTS...] Run the specified program + wine --help Display this help and exit + wine --version Output version information and exit + +``` + +Or `winecfg`: + +```sh +$ affinity-v3 wine winecfg +``` diff --git a/crates/runner/Cargo.toml b/crates/runner/Cargo.toml new file mode 100644 index 0000000..aa2e99e --- /dev/null +++ b/crates/runner/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "runner" +version = "0.1.0" +edition.workspace = true + +[lints] +workspace = true + +[dependencies] +anyhow = "1.0.102" +clap = { version = "4.6.0", features = ["derive"] } +duct = "1.1.1" +mutually_exclusive_features = "0.1.0" +nix = { version = "0.31.2", features = ["sched", "mount"] } +tracing = "0.1.44" +tracing-subscriber = "0.3.23" +walkdir = "2.5.0" +xdgdir = "0.8.0" + +[features] +default = ["v3"] + +v3 = [] +photo = [] +designer = [] +publisher = [] diff --git a/crates/runner/src/check.rs b/crates/runner/src/check.rs new file mode 100644 index 0000000..bbde18b --- /dev/null +++ b/crates/runner/src/check.rs @@ -0,0 +1,115 @@ +use std::{ + fs, + path::{Path, PathBuf}, + sync::LazyLock, +}; + +use anyhow::{Context, Result}; +use duct::cmd; +use tracing::{info, instrument}; + +use crate::make_env; + +pub static REGISTRY_PATCHES: LazyLock = + LazyLock::new(|| PathBuf::from(env!("REGISTRY_PATCHES"))); +pub static ON_LINUX: LazyLock = LazyLock::new(|| PathBuf::from(env!("ON_LINUX"))); +pub const RSYNC: &str = env!("RSYNC"); + +const LATEST_REVISION: u32 = 10; + +#[instrument(skip_all, ret)] +pub fn read_revision(wine_prefix: &Path) -> Result> { + let revision_file = wine_prefix.join(".revision"); + + if !revision_file.is_file() { + return Ok(None); + } + + let revision: u32 = fs::read_to_string(revision_file) + .context("reading revision file")? + .split_whitespace() + .collect::() + .parse() + .context("parsing revision to u32")?; + + return Ok(Some(revision)); +} + +#[instrument(skip_all)] +pub fn sync_v2_settings(wine_prefix: &Path, user: &str) -> Result<()> { + for app in ["Photo", "Designer", "Publisher"] { + let app_settings_dst = wine_prefix.join(format!( + "drive_c/users/{user}/AppData/Roaming/Affinity/{app}/2.0/" + )); + let app_settings_src = ON_LINUX.join(format!("Auxiliary/Settings/{app}/2.0/")); + + fs::create_dir_all(&app_settings_dst).context(format!( + "creating settings directory for {app} w/ user {user}: {}", + app_settings_dst.display() + ))?; + + let rsync = cmd!( + RSYNC, + "-v", + "--ignore-existing", + "--chmod=D755,F644", + "--recursive", + &app_settings_src, + &app_settings_dst + ) + .stderr_to_stdout() + .read() + .context(format!( + "syncing {app} settings with rsync: dst {}, src {}", + app_settings_dst.display(), + app_settings_src.display() + ))?; + + for line in rsync.lines().filter(|x| !x.is_empty()) { + info!(app = ?app, "{line}"); + } + } + + Ok(()) +} + +pub fn write_revision(wine_prefix: &Path) -> Result<()> { + let revision_file = wine_prefix.join(".revision"); + + fs::write(&revision_file, LATEST_REVISION.to_string()).context("writing revision to file")?; + + info!("wrote {LATEST_REVISION:?} to {revision_file:?}"); + + Ok(()) +} + +#[instrument(skip_all)] +pub fn perform_migrations(wine_prefix: &Path) -> Result<()> { + let revision = crate::check::read_revision(wine_prefix)?.unwrap_or(0); + + if revision < 10 { + let migration = make_env( + &cmd!( + crate::WINE, + "regedit", + "/S", + REGISTRY_PATCHES.join("one.reg") + ), + wine_prefix, + true, + ) + .stderr_to_stdout() + .read() + .context("applying one.reg")?; + + for line in migration.lines() { + info!("vkd3d migration: {line}"); + } + + info!("finished vkd3d migration."); + } + + write_revision(wine_prefix).context("writing revision")?; + + Ok(()) +} diff --git a/crates/runner/src/main.rs b/crates/runner/src/main.rs new file mode 100644 index 0000000..f07c6ab --- /dev/null +++ b/crates/runner/src/main.rs @@ -0,0 +1,619 @@ +use std::{ + env, + fs::{self}, + io::{self, BufRead, BufReader}, + os::unix::fs::PermissionsExt, + path::{Path, PathBuf}, + sync::LazyLock, +}; + +use anyhow::Context; +use clap::{Parser, Subcommand}; +use duct::cmd; +use mutually_exclusive_features::exactly_one_of; +use nix::{ + libc::{self, S_IWUSR}, + mount::{MsFlags, mount, umount}, + sched::{CloneFlags, unshare}, + sys::wait::{WaitStatus, waitpid}, + unistd::{ForkResult, fork}, +}; +use tracing::{Level, error, info, instrument}; +use tracing_subscriber::FmtSubscriber; +use walkdir::WalkDir; +use xdgdir::BaseDir; + +use crate::check::{perform_migrations, sync_v2_settings}; + +mod check; +mod migrate; + +exactly_one_of!("v3", "photo", "designer", "publisher"); + +const MOUNT_FAIL_STATUS: i32 = 111; + +pub(crate) const WINE: &str = env!("WINE"); +pub(crate) const WINESERVER: &str = env!("WINESERVER"); +pub(crate) const WINETRICKS: &str = env!("WINETRICKS"); +pub(crate) const FUSE_OVERLAYFS: &str = env!("FUSE_OVERLAYFS"); +pub(crate) const GNUTAR: &str = env!("GNUTAR"); +pub(crate) const ZENITY: &str = env!("ZENITY"); + +pub(crate) static LOWER_DIR: LazyLock = + LazyLock::new(|| PathBuf::from(env::var("LOWER_DIR").expect("LOWER_DIR env var to exist"))); + +#[derive(Parser, Debug)] +#[command(version, about, long_about = None)] +struct Arguments { + /// Make Wine far more verbose. + #[arg(long)] + verbose: bool, + + /// Specified tool to use. If none matches, defaults to the affinity application. + #[command(subcommand)] + subcommand: Option, + + /// Arguments for affinity application + #[arg(trailing_var_arg = true, allow_hyphen_values = true)] + affinity: Vec, +} + +#[derive(Subcommand, Debug)] +enum Program { + /// Run wine within sandbox + Wine { + /// arguments to wine + #[arg(trailing_var_arg = true, allow_hyphen_values = true)] + arguments: Vec, + }, + /// Run winetricks within sandbox + Winetricks { + /// arguments to winetricks + #[arg(trailing_var_arg = true, allow_hyphen_values = true)] + arguments: Vec, + }, + /// Run wineboot within sandbox + Wineboot { + /// arguments to wineboot + #[arg(trailing_var_arg = true, allow_hyphen_values = true)] + arguments: Vec, + }, + /// Run wineserver within sandbox + Wineserver { + /// arguments to wineserver + #[arg(trailing_var_arg = true, allow_hyphen_values = true)] + arguments: Vec, + }, +} + +#[derive(Debug)] +enum ProgramToExecute { + Affinity { arguments: Vec }, + Other(Program), +} + +#[derive(Debug)] +struct Paths { + upper: PathBuf, + work: PathBuf, + wine_prefix: PathBuf, +} + +impl Paths { + fn ensure_created(&self) -> anyhow::Result<()> { + let work_dir = self.work.join("work"); + + if work_dir.is_dir() { + let mut perms = fs::metadata(&work_dir)?.permissions(); + perms.set_mode(0o700); + fs::set_permissions(&work_dir, perms).context("set workdir permissions")?; + + fs::remove_dir_all(&work_dir).context("delete workdir")?; + } + + fs::create_dir_all(&self.upper).context("creating upper")?; + fs::create_dir_all(&self.work).context("creating work")?; + fs::create_dir_all(&self.wine_prefix).context("creating wine_prefix")?; + + Ok(()) + } +} + +fn init_tracing() { + let subscriber = FmtSubscriber::builder() + .with_max_level(Level::TRACE) + .finish(); + + tracing::subscriber::set_global_default(subscriber).expect("setting default subscriber failed"); +} + +fn make_env(expression: &duct::Expression, wine_prefix: &Path, verbose: bool) -> duct::Expression { + let expression = expression.env("WINEPREFIX", wine_prefix.display().to_string()); + + if verbose { + return expression; + } + + expression.env("WINEDEBUG", "-all,fixme-all".to_string()) +} + +#[instrument] +fn warmup_prefix_directories(destination: &PathBuf) -> io::Result<()> { + for entry in WalkDir::new(&*LOWER_DIR) + .into_iter() + .filter_map(std::result::Result::ok) + { + if !entry.file_type().is_dir() { + continue; + } + + let relative_path = entry.path().strip_prefix(&*LOWER_DIR).unwrap(); + let target_path = destination.join(relative_path); + + if let Err(err) = fs::create_dir_all(&target_path) { + error!(target_path = ?target_path, err = ?err, "failed to create"); + } + } + + Ok(()) +} + +#[instrument] +fn warmup_prefix_registry(destination: &PathBuf, user: &String) -> io::Result<()> { + let important_files = vec!["system.reg", "user.reg", "userdef.reg", ".update-timestamp"]; + + for file in important_files { + let src_path = LOWER_DIR.join(file); + let dst_path = destination.join(file); + + if !src_path.try_exists()? || dst_path.try_exists()? { + continue; + } + + let content = fs::read_to_string(&src_path)?; + let modified_content = content.replace("nixbld", user); + + fs::write(&dst_path, modified_content)?; + + let mut perms = fs::metadata(&dst_path)?.permissions(); + let current_mode = perms.mode(); + + // set write bit + perms.set_mode(current_mode | S_IWUSR); + fs::set_permissions(&dst_path, perms)?; + } + + Ok(()) +} + +#[instrument(skip_all)] +fn wineboot_update(wine_prefix: &Path, verbose: bool) -> anyhow::Result<()> { + let handle = make_env( + &cmd!(WINE, "wineboot", "--update") + .stderr_to_stdout() + .unchecked(), + wine_prefix, + verbose, + ) + .reader()?; + + let lines = BufReader::new(&handle).lines(); + + for line in lines { + let line = line?; + info!("{line}"); + } + + match handle.try_wait()? { + Some(output) => { + if !output.status.success() { + return Err(anyhow::anyhow!( + "wineboot --update failed: {:?}", + output.status + )); + } + } + None => { + error!("wineboot child is still running in some way."); + } + } + + Ok(()) +} + +#[instrument(skip_all)] +fn execute(paths: &Paths, program: &ProgramToExecute, verbose: bool) -> anyhow::Result<()> { + let user = std::env::var("USER")?; + + info!(user = ?user); + + if let Err(e) = warmup_prefix_directories(&paths.upper) { + error!(error = %e, "warmup prefix directories failed (non-fatal)"); + } + if let Err(e) = warmup_prefix_registry(&paths.upper, &user) { + error!(error = %e, "warmup prefix registry failed (non-fatal)"); + } + wineboot_update(&paths.wine_prefix, verbose)?; + + info!("finished warming & wineboot"); + + perform_migrations(&paths.wine_prefix).context("performing migrations")?; + + if cfg!(not(feature = "v3")) { + sync_v2_settings(&paths.wine_prefix, &user).context("sync v2 settings")?; + } + + info!("finished pre-check"); + + let application_handle = match program { + ProgramToExecute::Affinity { arguments } => { + let exe_suffix = if cfg!(feature = "v3") { + "Affinity/AffinityHook.exe" + } else if cfg!(feature = "photo") { + "Photo 2/Photo.exe" + } else if cfg!(feature = "publisher") { + "Publisher 2/Publisher.exe" + } else if cfg!(feature = "designer") { + "Designer 2/Designer.exe" + } else { + unreachable!() + }; + + let exe_path = format!( + "{}/drive_c/Program Files/Affinity/{}", + paths.wine_prefix.display(), + exe_suffix + ); + + info!("using exe {exe_path:?}"); + + cmd( + WINE, + std::iter::once(exe_path).chain(arguments.iter().cloned()), + ) + } + ProgramToExecute::Other(Program::Wine { arguments }) => cmd(WINE, arguments), + ProgramToExecute::Other(Program::Winetricks { arguments }) => cmd(WINETRICKS, arguments), + ProgramToExecute::Other(Program::Wineboot { arguments }) => cmd( + WINE, + std::iter::once("wineboot".to_string()).chain(arguments.iter().cloned()), + ), + ProgramToExecute::Other(Program::Wineserver { arguments }) => cmd(WINESERVER, arguments), + }; + + let application_handle = make_env( + &application_handle.stderr_to_stdout().unchecked(), + &paths.wine_prefix, + verbose, + ) + .reader()?; + + let lines = BufReader::new(&application_handle).lines(); + + for line in lines { + let line = line?; + println!("{line}"); + } + + match application_handle.try_wait()? { + Some(output) => { + if output.status.success() { + info!(status = ?output.status, "application process ended cleanly"); + } else { + return Err(anyhow::anyhow!( + "application process failed: {:?}", + output.status + )); + } + } + None => { + error!("application process is still running in some way."); + } + } + + let wineserver_wait = make_env( + &cmd!(WINESERVER, "-w").stderr_to_stdout().unchecked(), + &paths.wine_prefix, + verbose, + ) + .reader()?; + + let lines = BufReader::new(&wineserver_wait).lines(); + + for line in lines { + let line = line?; + info!("{line}"); + } + + match wineserver_wait.try_wait()? { + Some(output) => { + if output.status.success() { + info!(status = ?output.status, "wineserver -w exited cleanly"); + } else { + return Err(anyhow::anyhow!("wineserver -w failed: {:?}", output.status)); + } + } + None => { + error!("wineserver child is still running in some way."); + } + } + + Ok(()) +} + +#[instrument(skip_all, ret)] +fn make_mount_options(paths: &Paths) -> String { + format!( + "lowerdir={},upperdir={},workdir={}", + LOWER_DIR.display(), + paths.upper.display(), + paths.work.display() + ) +} + +#[instrument(skip(paths))] +fn cleanup_fuse(paths: &Paths) -> anyhow::Result<()> { + let fusermount3 = cmd!( + "/usr/bin/env", + "fusermount3", + "-u", + "-z", + paths.wine_prefix.display().to_string() + ) + .stdout_to_stderr() + .stderr_capture() + .run(); + + let success = match &fusermount3 { + Ok(output) => { + if output.status.success() { + true + } else { + error!(status = %output.status, stderr = ?output.stderr, "`fusermount3` failed"); + false + } + } + Err(err) => { + error!(error = ?err, "`fusermount3` failed"); + false + } + }; + + if !success { + let fusermount = cmd!( + "/usr/bin/env", + "fusermount", + "-u", + "-z", + paths.wine_prefix.display().to_string() + ) + .stdout_to_stderr() + .stderr_capture() + .run()?; + + if !fusermount.status.success() { + error!(status = %fusermount.status, stderr = ?String::from_utf8_lossy(&fusermount.stderr), "`fusermount2` failed"); + + return Err(anyhow::anyhow!( + "both `fusermount3` & `fusermount` failed! fusermount2: {:?}", + String::from_utf8_lossy(&fusermount.stderr) + )); + } + } + + info!("unmounted fuse cleanly"); + + let _ = fs::remove_dir(&paths.wine_prefix) + .inspect_err(|err| error!(error = ?err, "failed to remove wine_prefix")); + + Ok(()) +} + +#[instrument(skip_all)] +fn mount_run_unprivileged( + paths: &Paths, + program: &ProgramToExecute, + verbose: bool, +) -> anyhow::Result<()> { + let handle = cmd!( + FUSE_OVERLAYFS, + "-o", + make_mount_options(paths), + &paths.wine_prefix + ) + .stderr_to_stdout() + .unchecked() + .reader()?; + + let lines = BufReader::new(&handle).lines(); + + for line in lines { + let line = line?; + info!("{line}"); + } + + match handle.try_wait()? { + Some(output) => { + if !output.status.success() { + return Err(anyhow::anyhow!( + "fuse-overlayfs failed to mount: {:?}", + output.status + )); + } + } + None => { + error!("fuse-overlayfs child is still running in some way."); + } + } + + if let Err(err) = execute(paths, program, verbose) { + error!(error = ?err, "Running with fuse failed."); + let _ = cleanup_fuse(paths); + return Err(anyhow::anyhow!( + "failed to run application with `fuse-overlayfs`: {err:?}" + )); + } + + cleanup_fuse(paths)?; + + Ok(()) +} + +#[instrument(skip(paths))] +fn cleanup_privileged(paths: &Paths) { + let _ = umount(&paths.wine_prefix) + .inspect_err(|err| error!(error = ?err, "failed to unmount wine_prefix")); + let _ = fs::remove_dir(&paths.wine_prefix) + .inspect_err(|err| error!(error = ?err, "failed to remove wine_prefix")); +} + +#[instrument(skip_all)] +fn mount_execute_privileged(paths: &Paths, program: &ProgramToExecute, verbose: bool) { + match mount( + Some("overlay"), + &paths.wine_prefix, + Some("overlay"), + MsFlags::empty(), + Some(make_mount_options(paths).as_str()), + ) { + Ok(()) => { + if let Err(err) = execute(paths, program, verbose) { + error!(error = ?err, "Running privileged failed."); + cleanup_privileged(paths); + std::process::exit(1); + } + } + Err(err) => { + error!(errorno = ?err, "Mount failed."); + std::process::exit(MOUNT_FAIL_STATUS); + } + } + + cleanup_privileged(paths); +} + +#[instrument(skip_all)] +fn mount_run_privileged( + paths: &Paths, + ids: (u32, u32), + program: &ProgramToExecute, + verbose: bool, +) -> anyhow::Result<()> { + if let Err(err) = fs::write("/proc/self/setgroups", b"deny\n") { + error!(error = ?err, "failed to write setgroups"); + mount_run_unprivileged(paths, program, verbose)?; + return Ok(()); + } + + let uid_map = format!("0 {} 1\n", ids.0); + if let Err(err) = fs::write("/proc/self/uid_map", uid_map) { + error!(error = ?err, "failed to write uid_map"); + mount_run_unprivileged(paths, program, verbose)?; + return Ok(()); + } + + let gid_map = format!("0 {} 1\n", ids.1); + if let Err(err) = fs::write("/proc/self/gid_map", gid_map) { + error!(error = ?err, "failed to write gid_map"); + mount_run_unprivileged(paths, program, verbose)?; + return Ok(()); + } + + match unsafe { fork() } { + Ok(ForkResult::Parent { child }) => match waitpid(child, None) { + Ok(WaitStatus::Exited(_, status)) if status == MOUNT_FAIL_STATUS => { + info!("Falling back on unprivileged due to failed mount"); + mount_run_unprivileged(paths, program, verbose)?; + } + Ok(WaitStatus::Exited(_, status)) => { + std::process::exit(status); + } + Ok(WaitStatus::Signaled(_, signal, _)) => { + info!(signal= ?signal, "child was killed by signal"); + std::process::exit(1); + } + Err(err) => { + error!(errorno = ?err, "failed to wait for child"); + std::process::exit(1); + } + _ => {} + }, + Ok(ForkResult::Child) => { + unsafe { + // make sure this namespace dies if the parent ends + nix::libc::prctl(nix::libc::PR_SET_PDEATHSIG, nix::libc::SIGKILL); + } + mount_execute_privileged(paths, program, verbose); + std::process::exit(0); + } + Err(err) => { + error!(errorno = ?err, "Fork failed."); + info!("Falling back on unprivileged"); + mount_run_unprivileged(paths, program, verbose)?; + } + } + + Ok(()) +} + +fn main() -> anyhow::Result<()> { + init_tracing(); + + let args = Arguments::parse(); + + let base = BaseDir::new(if cfg!(feature = "v3") { + "affinity-v3" + } else { + "affinity" + }) + .expect("obtaining xdg basedir failed"); + + let paths = Paths { + upper: base.data, + work: base.state, + wine_prefix: base + .runtime + .unwrap_or_else(std::env::temp_dir) + .join(format!("affinity-nix-prefix-{}", std::process::id())), + }; + + info!(paths = ?paths, lower = ?LOWER_DIR.display()); + + if !LOWER_DIR.is_dir() { + return Err(anyhow::anyhow!( + "{} does not exist or is not a directory! If $LOWER_DIR does not exist, you are likely using the wrong package, refer to affinity-nix's readme for correct usage.", + LOWER_DIR.display() + )); + } + + paths + .ensure_created() + .context("setting up tmp directories")?; + migrate::migrate(&paths).context("migrating to new overlayfs runner")?; + + let uid = unsafe { libc::getuid() }; + let gid = unsafe { libc::getgid() }; + + let unshare = + unshare(CloneFlags::CLONE_NEWUSER | CloneFlags::CLONE_NEWNS | CloneFlags::CLONE_NEWPID); + + let program = if let Some(subcommand) = args.subcommand { + ProgramToExecute::Other(subcommand) + } else { + ProgramToExecute::Affinity { + arguments: args.affinity, + } + }; + + info!(program = ?program); + + match unshare { + Ok(()) => mount_run_privileged(&paths, (uid, gid), &program, args.verbose), + Err(err) => { + error!(errorno = ?err, "Unshare failed."); + mount_run_unprivileged(&paths, &program, args.verbose)?; + + Ok(()) + } + } +} diff --git a/crates/runner/src/migrate.rs b/crates/runner/src/migrate.rs new file mode 100644 index 0000000..8e2aeaa --- /dev/null +++ b/crates/runner/src/migrate.rs @@ -0,0 +1,117 @@ +use std::{ + env, fs, + io::{BufRead, BufReader}, + path::Path, +}; + +use anyhow::Context; +use duct::cmd; +use tracing::{error, info, instrument}; + +use crate::{GNUTAR, Paths, ZENITY}; + +const MESSAGE: &str = "There have been upgrades to affinity-nix! + +Affinity and it's dependencies are no longer installed directly, reducing startup time and manual updating. + +To migrate, we need to delete the old installation. Your registry files and user data won't be touched."; + +fn make_message(backup_location: &Path) -> String { + format!( + "{MESSAGE} A backup will be created in at {}. Is that OK?", + backup_location.display() + ) +} + +#[instrument(skip_all)] +pub fn migrate(paths: &Paths) -> anyhow::Result<()> { + let Some(revision) = crate::check::read_revision(&paths.upper)? else { + info!("revision does not exist, skipping backup"); + return Ok(()); + }; + + if revision >= 9 { + info!("revision more than or equal to 9, skipping backup"); + return Ok(()); + } + + let backup_path = Path::new(&env::var("HOME").context("finding $HOME var")?).join(format!( + "affinity-nix-backup-{}.tar.zst", + std::process::id() + )); + + let question = cmd!( + ZENITY, + "--question", + "--width", + "480", + format!("--text={}", make_message(&backup_path)) + ) + .unchecked() + .run()?; + + if !question.status.success() { + return Err(anyhow::anyhow!( + "User refused to migrate, we cannot continue or there may be data loss." + )); + } + + let tar_handle = cmd!(GNUTAR, "--zstd", "-cvpf", backup_path, &paths.upper) + .stdout_to_stderr() + .stderr_capture() + .reader()?; + + let lines = BufReader::new(&tar_handle).lines(); + + for line in lines { + let line = line?; + info!("{line}"); + } + + match tar_handle.try_wait()? { + Some(output) => { + if !output.status.success() { + return Err(anyhow::anyhow!( + "backing up with tar failed: {:?}", + output.status + )); + } + + info!(status = %output.status, "tar ended cleanly"); + } + None => { + error!("tar child is still running in some way."); + } + } + + let drive_c = paths.upper.join("drive_c"); + + if !drive_c.is_dir() { + return Ok(()); + } + + for entry in drive_c.read_dir().context("reading drive_c")? { + let entry = entry.context("reading drive_c entry")?; + + if entry.file_name() == "users" { + continue; + } + + let path = entry.path(); + + info!(path = ?path, "removing entry"); + + if entry + .file_type() + .context("reading entry filetype")? + .is_dir() + { + fs::remove_dir_all(&path) + .with_context(|| format!("removing directory {}", path.display()))?; + } else { + fs::remove_file(&path).with_context(|| format!("removing file {}", path.display()))?; + } + } + + Ok(()) +} diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..ffc7816 --- /dev/null +++ b/default.nix @@ -0,0 +1,13 @@ +let + lockFile = builtins.fromJSON (builtins.readFile ./flake.lock); + flake-compat-node = lockFile.nodes.${lockFile.nodes.root.inputs.flake-compat}; + flake-compat = builtins.fetchTarball { + inherit (flake-compat-node.locked) url; + sha256 = flake-compat-node.locked.narHash; + }; + + flake = import flake-compat { + src = ./.; + }; +in +flake.defaultNix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..2f180f6 --- /dev/null +++ b/flake.lock @@ -0,0 +1,247 @@ +{ + "nodes": { + "corefonts": { + "flake": false, + "locked": { + "lastModified": 1431183738, + "narHash": "sha256-610Km9GCtYWxi2SH5jH/XYPXc5f58q5lB05/5XxO/qM=", + "owner": "pushcx", + "repo": "corefonts", + "rev": "8f8627b0004b5f1b952c09cf6390e4ae46475e59", + "type": "github" + }, + "original": { + "owner": "pushcx", + "repo": "corefonts", + "type": "github" + } + }, + "crane": { + "locked": { + "lastModified": 1787326676, + "narHash": "sha256-lWhBbBvC05/xwivKBBiM2YNizpmgqCgyOIzomvRuwxs=", + "owner": "ipetkov", + "repo": "crane", + "rev": "692f7e9ef2ece8125b466f66f2af532b3edaed0d", + "type": "github" + }, + "original": { + "owner": "ipetkov", + "repo": "crane", + "type": "github" + } + }, + "flake-compat": { + "locked": { + "lastModified": 1751685974, + "narHash": "sha256-NKw96t+BgHIYzHUjkTK95FqYRVKB8DHpVhefWSz/kTw=", + "rev": "549f2762aebeff29a2e5ece7a7dc0f955281a1d1", + "type": "tarball", + "url": "https://git.lix.systems/api/v1/repos/lix-project/flake-compat/archive/549f2762aebeff29a2e5ece7a7dc0f955281a1d1.tar.gz?rev=549f2762aebeff29a2e5ece7a7dc0f955281a1d1" + }, + "original": { + "type": "tarball", + "url": "https://git.lix.systems/lix-project/flake-compat/archive/main.tar.gz" + } + }, + "flake-compat_2": { + "flake": false, + "locked": { + "lastModified": 1767039857, + "narHash": "sha256-vNpUSpF5Nuw8xvDLj2KCwwksIbjua2LZCqhV1LNRDns=", + "owner": "NixOS", + "repo": "flake-compat", + "rev": "5edf11c44bc78a0d334f6334cdaf7d60d732daab", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1785627969, + "narHash": "sha256-4dtXQk/NMePegK/nWp5NSeuZKLATItOq61lpEvmXqGw=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "427bf4bd9435fdf21321c8cc628c24efc14c0f7a", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "git-hooks": { + "inputs": { + "flake-compat": "flake-compat_2", + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1787138109, + "narHash": "sha256-O2tBn84NNuHrnqNVxx/XqsXwfYvS1YwBh+7CBnbCYsk=", + "owner": "cachix", + "repo": "git-hooks.nix", + "rev": "928612b364dc241a05bf6567ad44d499efb6b9aa", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "git-hooks.nix", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1782918843, + "narHash": "sha256-ETYnV9U7Sr+A45dohzZdfCZKOss4qrTkO+wgNZNvEc0=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e8273b29fe1390ec8d4603f2477357555291432e", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1785031560, + "narHash": "sha256-OmshNvn2vupOFpYinLUu+1Dnpu4n7Q5N3ggGVNHpkUI=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "0e79af5e3d4dcfcd676ab5ba3f95d2e3352e078c", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" + } + }, + "nixpkgs-wine": { + "locked": { + "lastModified": 1735834308, + "narHash": "sha256-dklw3AXr3OGO4/XT1Tu3Xz9n/we8GctZZ75ZWVqAVhk=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "6df24922a1400241dae323af55f30e4318a6ca65", + "type": "github" + }, + "original": { + "owner": "nixos", + "repo": "nixpkgs", + "rev": "6df24922a1400241dae323af55f30e4318a6ca65", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1787135253, + "narHash": "sha256-RD2kNWCG+Bjo6h+JVjWVNntZs2GtRoeY2xHjts/FNkA=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "ffb3c9b700e759be2ef13237c9d8f953b32a1e46", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_3": { + "locked": { + "lastModified": 1770107345, + "narHash": "sha256-tbS0Ebx2PiA1FRW8mt8oejR0qMXmziJmPaU1d4kYY9g=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "4533d9293756b63904b7238acb84ac8fe4c8c2c4", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "on-linux": { + "flake": false, + "locked": { + "lastModified": 1787365621, + "narHash": "sha256-aRS0sZ6p7YJagjFaZFrS1zuvN3PVKNBJOze1Ek/bOi8=", + "owner": "seapear", + "repo": "AffinityOnLinux", + "rev": "0fe210754999a2ace3039c11fbbd11b45b5ee399", + "type": "github" + }, + "original": { + "owner": "seapear", + "repo": "AffinityOnLinux", + "type": "github" + } + }, + "plugin-loader-src": { + "flake": false, + "locked": { + "lastModified": 1776972538, + "narHash": "sha256-2EvrOYQCB2Z2YXhcPnjR67KoOCvwTVW3TfLcmU3//ak=", + "owner": "noahc3", + "repo": "AffinityPluginLoader", + "rev": "1d7956d5b791bd6a213e8b28c1e25e1f4bcc6166", + "type": "github" + }, + "original": { + "owner": "noahc3", + "repo": "AffinityPluginLoader", + "rev": "1d7956d5b791bd6a213e8b28c1e25e1f4bcc6166", + "type": "github" + } + }, + "root": { + "inputs": { + "corefonts": "corefonts", + "crane": "crane", + "flake-compat": "flake-compat", + "flake-parts": "flake-parts", + "git-hooks": "git-hooks", + "nixpkgs": "nixpkgs_2", + "nixpkgs-wine": "nixpkgs-wine", + "on-linux": "on-linux", + "plugin-loader-src": "plugin-loader-src", + "treefmt-nix": "treefmt-nix" + } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": "nixpkgs_3" + }, + "locked": { + "lastModified": 1786901030, + "narHash": "sha256-WSFCsDSE5ffgD2MqzkM2CYjeFiKhRF/dJUN8uedb6YE=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "27b3b12a8e6375f28ebe122f07d230ca5459bbfa", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..2ee285b --- /dev/null +++ b/flake.nix @@ -0,0 +1,65 @@ +{ + description = "An attempt at packaging affinity photo for nix"; + + inputs = { + # a known working revision of nixpkgs for wine. somewhat tracked by #63 + nixpkgs-wine.url = "github:nixos/nixpkgs/6df24922a1400241dae323af55f30e4318a6ca65"; + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + + on-linux = { + url = "github:seapear/AffinityOnLinux"; + flake = false; + }; + + plugin-loader-src = { + url = "github:noahc3/AffinityPluginLoader/1d7956d5b791bd6a213e8b28c1e25e1f4bcc6166"; + flake = false; + }; + + flake-parts.url = "github:hercules-ci/flake-parts"; + treefmt-nix.url = "github:numtide/treefmt-nix"; + git-hooks.url = "github:cachix/git-hooks.nix"; + + flake-compat.url = "https://git.lix.systems/lix-project/flake-compat/archive/main.tar.gz"; + + corefonts = { + url = "github:pushcx/corefonts"; + flake = false; + }; + + crane.url = "github:ipetkov/crane"; + }; + + outputs = + inputs@{ + flake-parts, + git-hooks, + treefmt-nix, + ... + }: + flake-parts.lib.mkFlake { inherit inputs; } { + imports = [ + git-hooks.flakeModule + treefmt-nix.flakeModule + ./nix/hooks.nix + ./nix/fmt.nix + ./nix/shells.nix + ./packages + ./tests/default.nix + ./overlay.nix + ]; + systems = [ + "x86_64-linux" + ]; + perSystem = + { + pkgs, + ... + }: + { + _module.args = { + craneLib = inputs.crane.mkLib pkgs; + }; + }; + }; +} diff --git a/nix/fmt.nix b/nix/fmt.nix new file mode 100644 index 0000000..4c67210 --- /dev/null +++ b/nix/fmt.nix @@ -0,0 +1,14 @@ +{ + perSystem = _: { + treefmt = { + projectRootFile = "flake.nix"; + programs = { + nixfmt.enable = true; + yamlfmt.enable = true; + shfmt.enable = true; + rustfmt.enable = true; + taplo.enable = true; + }; + }; + }; +} diff --git a/nix/hooks.nix b/nix/hooks.nix new file mode 100644 index 0000000..4b204ce --- /dev/null +++ b/nix/hooks.nix @@ -0,0 +1,48 @@ +{ + perSystem = + { + config, + lib, + pkgs, + ... + }: + { + pre-commit = { + settings = { + hooks = { + statix.enable = true; + zizmor.enable = true; + typos.enable = true; + deadnix = { + enable = true; + settings.edit = true; + }; + fmt = { + enable = true; + name = "nix fmt"; + entry = "${lib.getExe config.formatter} --no-cache"; + }; + ty = { + enable = true; + name = "ty check"; + files = "\\.py$"; + entry = lib.getExe ( + pkgs.writeShellScriptBin "ty-check" '' + cd tests/ + ${lib.getExe pkgs.uv} run ty check + '' + ); + }; + actionlint = { + enable = true; + files = "^\\.github/workflows/.*\\.(yml|yaml)$"; + }; + yamllint = { + enable = true; + settings.configPath = ".yamllint.yaml"; + }; + }; + }; + }; + }; +} diff --git a/nix/shells.nix b/nix/shells.nix new file mode 100644 index 0000000..8002db5 --- /dev/null +++ b/nix/shells.nix @@ -0,0 +1,45 @@ +{ inputs, ... }: +{ + perSystem = + { + config, + lib, + craneLib, + pkgs, + self', + wine-packages, + ... + }: + let + cfg = config.pre-commit; + in + { + # Adapted from + # https://github.com/cachix/git-hooks.nix/blob/dcf5072734cb576d2b0c59b2ac44f5050b5eac82/flake-module.nix#L66-L78 + devShells.default = craneLib.devShell { + packages = lib.flatten [ + cfg.settings.enabledPackages + cfg.settings.package + + pkgs.uv + pkgs.rust-analyzer + ]; + + env = { + WINE = lib.getExe self'.packages.wine; + WINESERVER = lib.getExe wine-packages.wineserver; + WINETRICKS = lib.getExe wine-packages.winetricks; + FUSE_OVERLAYFS = lib.getExe pkgs.fuse-overlayfs; + GNUTAR = lib.getExe pkgs.gnutar; + ZENITY = lib.getExe pkgs.zenity; + RSYNC = lib.getExe pkgs.rsync; + REGISTRY_PATCHES = (pkgs.callPackage ../packages/registry-patches.nix { }).combined; + ON_LINUX = inputs.on-linux.outPath; + }; + + shellHook = builtins.concatStringsSep "\n" [ + cfg.installationScript + ]; + }; + }; +} diff --git a/overlay.nix b/overlay.nix new file mode 100644 index 0000000..a907c59 --- /dev/null +++ b/overlay.nix @@ -0,0 +1,22 @@ +{ withSystem, inputs, ... }: +{ + flake.overlays.default = + _final: prev: + withSystem prev.stdenv.hostPlatform.system (_: { + affinity-v3 = prev.callPackage ./packages/affinity-v3/package.nix { + inherit inputs; + }; + affinity-photo = prev.callPackage ./packages/affinity/package.nix { + name = "Photo"; + inherit inputs; + }; + affinity-designer = prev.callPackage ./packages/affinity/package.nix { + name = "Designer"; + inherit inputs; + }; + affinity-publisher = prev.callPackage ./packages/affinity/package.nix { + name = "Publisher"; + inherit inputs; + }; + }); +} diff --git a/packages/affinity-v3/default.nix b/packages/affinity-v3/default.nix new file mode 100644 index 0000000..a881a55 --- /dev/null +++ b/packages/affinity-v3/default.nix @@ -0,0 +1,18 @@ +{ inputs, ... }: +{ + perSystem = + { + pkgs, + self', + ... + }: + { + packages = { + affinity-v3 = pkgs.callPackage ./package.nix { + inherit inputs; + }; + + default = self'.packages.affinity-v3; + }; + }; +} diff --git a/packages/affinity-v3/desktopItems.nix b/packages/affinity-v3/desktopItems.nix new file mode 100644 index 0000000..f9872fe --- /dev/null +++ b/packages/affinity-v3/desktopItems.nix @@ -0,0 +1,30 @@ +{ + makeDesktopItem, + lib, + affinity-v3 ? null, +}: +{ + affinity-v3 = makeDesktopItem rec { + desktopName = "Affinity"; + name = "affinity-v3"; + exec = "${lib.getExe affinity-v3} %U"; + icon = name; + type = "Application"; + categories = [ "Graphics" ]; + keywords = [ + "Graphics" + "2DGraphics" + "RasterGraphics" + "VectorGraphics" + "image" + "editor" + "vector" + "drawing" + ]; + mimeTypes = [ + "application/afphoto" + "application/afdesign" + ]; + startupWMClass = "affinity.exe"; + }; +} diff --git a/packages/affinity-v3/icons.nix b/packages/affinity-v3/icons.nix new file mode 100644 index 0000000..10e6b09 --- /dev/null +++ b/packages/affinity-v3/icons.nix @@ -0,0 +1,20 @@ +{ + fetchurl, + pkgs, + lib, +}: +rec { + icon = fetchurl { + url = "https://web.archive.org/web/20260310003857/https://static.canva.com/domain-assets/affinity/static/images/apple-touch-180x180-1.png"; + sha256 = "sha256-KLT9loFiD2y8uNXNzc27DZ4A73yEs6Ntr4h3WULG5HM="; + }; + + iconPackage = pkgs.runCommand "affinity-v3-icons" { } '' + mkdir -p $out/share/icons/hicolor/256x256/apps + + ${lib.getExe pkgs.imagemagick} \ + ${icon} \ + -resize 256x256 \ + $out/share/icons/hicolor/256x256/apps/affinity-v3.png + ''; +} diff --git a/packages/affinity-v3/package.nix b/packages/affinity-v3/package.nix new file mode 100644 index 0000000..403ed17 --- /dev/null +++ b/packages/affinity-v3/package.nix @@ -0,0 +1,50 @@ +{ + symlinkJoin, + callPackage, + inputs, + lib, + ... +}: +let + wine-packages = callPackage ../wine/packages.nix { + inherit inputs; + }; + + apl-combined = callPackage ../apl/apl-combined.nix { + src = inputs.plugin-loader-src; + }; + + prefixBase = callPackage ../prefixWithAffinity.nix { + inherit inputs wine-packages apl-combined; + }; + + runner = callPackage ../runner/package.nix { + inherit prefixBase inputs wine-packages; + registry-patches = (callPackage ../registry-patches.nix { }).combined; + name = "v3"; + }; + + desktop = callPackage ./desktopItems.nix { + affinity-v3 = runner.package; + }; + + icons = callPackage ./icons.nix { }; + icon-package = icons.iconPackage; +in +symlinkJoin { + name = "Affinity v3"; + pname = "affinity-v3"; + paths = [ + runner.package + desktop.affinity-v3 + icon-package + ]; + meta = { + mainProgram = "affinity-v3"; + + description = "Affinity v3"; + license = lib.licenses.unfree; + homepage = "https://affinity.serif.com/"; + platforms = [ "x86_64-linux" ]; + }; +} diff --git a/packages/affinity/default.nix b/packages/affinity/default.nix new file mode 100644 index 0000000..9430175 --- /dev/null +++ b/packages/affinity/default.nix @@ -0,0 +1,22 @@ +{ inputs, ... }: +{ + perSystem = + { + pkgs, + ... + }: + let + makeV2Package = + name: + (pkgs.callPackage ./package.nix { + inherit inputs name; + }); + in + { + packages = { + affinity-photo = makeV2Package "Photo"; + affinity-designer = makeV2Package "Designer"; + affinity-publisher = makeV2Package "Publisher"; + }; + }; +} diff --git a/packages/affinity/desktopItems.nix b/packages/affinity/desktopItems.nix new file mode 100644 index 0000000..1a82467 --- /dev/null +++ b/packages/affinity/desktopItems.nix @@ -0,0 +1,71 @@ +{ + makeDesktopItem, + lib, + photo ? null, + publisher ? null, + designer ? null, +}: +{ + photo = makeDesktopItem rec { + desktopName = "Affinity Photo 2"; + name = "affinity-photo"; + exec = "${lib.getExe photo} %U"; + icon = name; + type = "Application"; + categories = [ "Graphics" ]; + keywords = [ + "Graphics" + "2DGraphics" + "RasterGraphics" + "image" + "editor" + "vector" + "drawing" + ]; + mimeTypes = [ "application/afphoto" ]; + startupWMClass = "photo.exe"; + }; + designer = makeDesktopItem rec { + desktopName = "Affinity Designer 2"; + name = "affinity-designer"; + exec = "${lib.getExe designer} %U"; + icon = name; + type = "Application"; + categories = [ "Graphics" ]; + keywords = [ + "Graphics" + "2DGraphics" + "VectorGraphics" + "image" + "editor" + "vector" + "drawing" + ]; + mimeTypes = [ "application/afdesign" ]; + startupWMClass = "designer.exe"; + }; + publisher = makeDesktopItem rec { + desktopName = "Affinity Publisher 2"; + name = "affinity-publisher"; + exec = "${lib.getExe publisher} %U"; + icon = name; + type = "Application"; + categories = [ "Graphics" ]; + keywords = [ + "Graphics" + "2DGraphics" + "RasterGraphics" + "VectorGraphics" + "image" + "editor" + "vector" + "drawing" + ]; + mimeTypes = [ + "application/afdesign" + "application/afphoto" + # Note that there is no mime type for a `.afpub` file + ]; + startupWMClass = "publisher.exe"; + }; +} diff --git a/packages/affinity/icons.nix b/packages/affinity/icons.nix new file mode 100644 index 0000000..91b960f --- /dev/null +++ b/packages/affinity/icons.nix @@ -0,0 +1,35 @@ +{ + fetchurl, + pkgs, + lib, +}: +rec { + icons = { + photo = fetchurl { + url = "https://cdn.serif.com/store/img/logos/affinity-photo-2-020520191502.svg"; + sha256 = "04bnf12znp9dgkwpk46c01381cw298gq14ga7j7dwccyl3m556d7"; + }; + designer = fetchurl { + url = "https://cdn.serif.com/store/img/logos/affinity-designer-2-020520191502.svg"; + sha256 = "025j4aq8py2a5r34hx39nlhdmps06z6506h7wxchyxbbz6xz3d11"; + }; + publisher = fetchurl { + url = "https://cdn.serif.com/store/img/logos/affinity-publisher-2-020520191502.svg"; + sha256 = "16ghh3mc2vjhvphbyy9zgan066ccp3xj1ilb6z5lmvsb94dp37aj"; + }; + }; + + mkIconPackageFor = + name: + pkgs.runCommand "${name}-icons" { } '' + mkdir -p $out/share/icons/hicolor/{256x256,scalable}/apps + + cp ${icons.${lib.toLower name}} \ + $out/share/icons/hicolor/scalable/apps/affinity-${lib.toLower name}.svg + + ${lib.getExe pkgs.inkscape} \ + -w 256 -h 256 \ + ${icons.${lib.toLower name}} \ + -o - > $out/share/icons/hicolor/256x256/apps/affinity-${lib.toLower name}.png + ''; +} diff --git a/packages/affinity/package.nix b/packages/affinity/package.nix new file mode 100644 index 0000000..b251900 --- /dev/null +++ b/packages/affinity/package.nix @@ -0,0 +1,59 @@ +{ + symlinkJoin, + callPackage, + lib, + name, + inputs, + ... +}: +let + wine-packages = callPackage ../wine/packages.nix { + inherit inputs; + }; + + apl-combined = callPackage ../apl/apl-combined.nix { + src = inputs.plugin-loader-src; + }; + + prefixBase = callPackage ../prefixWithAffinity.nix { + inherit inputs wine-packages apl-combined; + v3 = false; + }; + + runner = callPackage ../runner/package.nix { + inherit + prefixBase + inputs + wine-packages + name + ; + registry-patches = (callPackage ../registry-patches.nix { }).combined; + }; + + desktop = callPackage ./desktopItems.nix { + ${lib.toLower name} = runner.package; + }; + + icons = callPackage ./icons.nix { }; + icon-package = icons.mkIconPackageFor name; + + # last version of affinity v2 released + lastV2Version = "2.6.5"; +in +symlinkJoin { + name = "affinity-${lib.toLower name}-${lastV2Version}"; + pname = "affinity-${lib.toLower name}"; + paths = [ + runner.package + desktop.${lib.toLower name} + icon-package + ]; + meta = { + mainProgram = "affinity-${lib.toLower name}"; + + description = "Affinity ${name} ${lastV2Version}"; + license = lib.licenses.unfree; + homepage = "https://affinity.serif.com/"; + platforms = [ "x86_64-linux" ]; + }; +} diff --git a/packages/apl/apl-combined.nix b/packages/apl/apl-combined.nix new file mode 100644 index 0000000..bf3d95e --- /dev/null +++ b/packages/apl/apl-combined.nix @@ -0,0 +1,30 @@ +{ + callPackage, + symlinkJoin, + src, + ... +}: +let + version = "unstable"; + + apl = callPackage ./apl.nix { + inherit version src; + }; + + bootstrap = callPackage ./bootstrap.nix { + inherit version src; + }; +in +symlinkJoin { + pname = "apl-combined"; + inherit version; + paths = [ + apl + bootstrap + ]; + + postBuild = '' + mv $out/lib/AffinityPluginLoader/* $out + rm -rf $out/lib + ''; +} diff --git a/packages/apl/apl.nix b/packages/apl/apl.nix new file mode 100644 index 0000000..1ca28c1 --- /dev/null +++ b/packages/apl/apl.nix @@ -0,0 +1,26 @@ +{ + buildDotnetModule, + src, + version, + ... +}: +buildDotnetModule rec { + pname = "AffinityPluginLoader"; + + inherit version src; + + projectFile = "AffinityPluginLoader.sln"; + + patches = [ ./no-login.patch ]; + + nugetDeps = ./deps.json; + + postInstall = '' + pushd $out/lib/${pname} + rm *.pdb + rm *.config + + mkdir -p ./apl/plugins + mv ./WineFix.dll ./apl/plugins + ''; +} diff --git a/packages/apl/bootstrap.nix b/packages/apl/bootstrap.nix new file mode 100644 index 0000000..d7d3cc4 --- /dev/null +++ b/packages/apl/bootstrap.nix @@ -0,0 +1,37 @@ +{ + pkgs, + version, + src, + ... +}: +pkgs.pkgsCross.mingwW64.stdenv.mkDerivation { + pname = "affinity-bootstrap"; + + inherit version; + + src = "${src}/AffinityBootstrap"; + + nativeBuildInputs = [ pkgs.wine64 ]; + + buildPhase = '' + mkdir -p build + + cat << 'EOF' > mscoree.def + LIBRARY mscoree.dll + EXPORTS + CLRCreateInstance + EOF + + x86_64-w64-mingw32-dlltool -d mscoree.def -l build/libmscoree.a + + $CC -shared -o build/AffinityBootstrap.dll bootstrap.c \ + -I${pkgs.wine64}/include/wine/windows \ + -Lbuild \ + -lole32 -loleaut32 -luuid -lmscoree + ''; + + installPhase = '' + mkdir -p $out/lib/AffinityPluginLoader + cp build/AffinityBootstrap.dll $out/lib/AffinityPluginLoader + ''; +} diff --git a/packages/apl/default.nix b/packages/apl/default.nix new file mode 100644 index 0000000..c03ec59 --- /dev/null +++ b/packages/apl/default.nix @@ -0,0 +1,13 @@ +{ inputs, ... }: +{ + perSystem = + { + pkgs, + ... + }: + { + packages.apl-combined = pkgs.callPackage ./apl-combined.nix { + src = inputs.plugin-loader-src; + }; + }; +} diff --git a/packages/apl/deps.json b/packages/apl/deps.json new file mode 100644 index 0000000..11e8c15 --- /dev/null +++ b/packages/apl/deps.json @@ -0,0 +1,17 @@ +[ + { + "pname": "Lib.Harmony", + "version": "2.4.2", + "hash": "sha256-1kWS5TCQRkVZ/OSGEsnKfI3HMROEE3a3qjRV9G/F1Xk=" + }, + { + "pname": "Microsoft.NETFramework.ReferenceAssemblies", + "version": "1.0.3", + "hash": "sha256-FBoJP5DHZF0QHM0xLm9yd4HJZVQOuSpSKA+VQRpphEE=" + }, + { + "pname": "Microsoft.NETFramework.ReferenceAssemblies.net48", + "version": "1.0.3", + "hash": "sha256-in40hTjn65E1FpaRFon0nj1PY/i6tRdDK74Vm4sRBKI=" + } +] diff --git a/packages/apl/no-login.patch b/packages/apl/no-login.patch new file mode 100644 index 0000000..0dbb048 --- /dev/null +++ b/packages/apl/no-login.patch @@ -0,0 +1,589 @@ +From 45ff4e8c5615af1e8f0a41e92580506788a10b24 Mon Sep 17 00:00:00 2001 +From: marshmallow +Date: Mon, 13 Apr 2026 20:11:35 +1000 +Subject: [PATCH] Revert "Restore Canva sign-in: Textbox to capture + authorization token (#44)" + +This reverts commit 915e1cc5096475f433b8447fc7c6b7cb3b52b7d9. +--- + WineFix/Patches/CanvaSignInPatch.cs | 435 ----------------------- + WineFix/Patches/MainWindowLoadedPatch.cs | 55 +++ + WineFix/WineFix.csproj | 4 - + WineFix/WineFixPlugin.cs | 14 - + 4 files changed, 55 insertions(+), 453 deletions(-) + delete mode 100644 WineFix/Patches/CanvaSignInPatch.cs + +diff --git a/WineFix/Patches/CanvaSignInPatch.cs b/WineFix/Patches/CanvaSignInPatch.cs +deleted file mode 100644 +index 7c05fcb..0000000 +--- a/WineFix/Patches/CanvaSignInPatch.cs ++++ /dev/null +@@ -1,435 +0,0 @@ +-using System; +-using System.Globalization; +-using System.Linq; +-using System.Reflection; +-using System.Windows; +-using System.Windows.Controls; +-using System.Windows.Data; +-using System.Windows.Media; +-using System.Windows.Media.Imaging; +-using HarmonyLib; +-using AffinityPluginLoader.Core; +- +-namespace WineFix.Patches +-{ +- /// +- /// Adds a paste-URL textbox to the Canva sign-in dialog so users can manually +- /// paste the authentication redirect URL from their browser, bypassing the need +- /// for the affinity:// protocol handler which doesn't work under Wine. +- /// +- public static class CanvaSignInPatch +- { +- private static FieldInfo _authHookField; +- private static object _cloudServicesService; +- private static Border _overlayPanel; +- +- public static void ApplyPatches(Harmony harmony) +- { +- Logger.Info("Applying CanvaSignIn patch..."); +- +- var serifAffinity = AppDomain.CurrentDomain.GetAssemblies() +- .FirstOrDefault(a => a.GetName().Name == "Serif.Affinity"); +- var serifInterop = AppDomain.CurrentDomain.GetAssemblies() +- .FirstOrDefault(a => a.GetName().Name == "Serif.Interop.Persona"); +- +- if (serifAffinity == null || serifInterop == null) +- { +- Logger.Error("Required assemblies not found"); +- return; +- } +- +- // Resolve the AuthHookReceived backing field on CloudServicesService +- var cssType = serifInterop.GetType("Serif.Interop.Persona.Services.CloudServicesService"); +- _authHookField = cssType?.GetField("AuthHookReceived", +- BindingFlags.NonPublic | BindingFlags.Instance); +- +- if (_authHookField == null) +- { +- // Try the mangled name from decompilation +- _authHookField = cssType?.GetFields(BindingFlags.NonPublic | BindingFlags.Instance) +- .FirstOrDefault(f => f.Name.Contains("AuthHookReceived") && f.FieldType == typeof(Action)); +- } +- +- if (_authHookField == null) +- { +- Logger.Error("Could not find AuthHookReceived backing field"); +- return; +- } +- +- // Patch ProductKeyDialog_Loaded to inject our UI +- var dialogType = serifAffinity.GetType("Serif.Affinity.UI.ProductKeyDialog"); +- var loadedMethod = dialogType?.GetMethod("ProductKeyDialog_Loaded", +- BindingFlags.NonPublic | BindingFlags.Instance); +- +- if (loadedMethod == null) +- { +- Logger.Error("ProductKeyDialog_Loaded not found"); +- return; +- } +- +- harmony.Patch(loadedMethod, +- postfix: new HarmonyMethod(typeof(CanvaSignInPatch), nameof(OnDialogLoaded))); +- Logger.Info("Patched ProductKeyDialog_Loaded"); +- } +- +- public static void OnDialogLoaded(object __instance) +- { +- try +- { +- var window = __instance as Window; +- if (window == null) return; +- +- // Get CloudServicesService via Application.Current.GetService() +- var app = Application.Current; +- var getServiceMethod = app.GetType().GetMethods(BindingFlags.Public | BindingFlags.Instance) +- .Where(m => m.Name == "GetService" && m.IsGenericMethod) +- .FirstOrDefault(); +- +- if (getServiceMethod != null) +- { +- var cssType = _authHookField.DeclaringType; +- var bound = getServiceMethod.MakeGenericMethod(cssType); +- _cloudServicesService = bound.Invoke(app, null); +- } +- +- // Listen for DataContext property changes to detect state transitions +- var model = ((FrameworkElement)window).DataContext; +- if (model is System.ComponentModel.INotifyPropertyChanged npc) +- { +- npc.PropertyChanged += (s, e) => +- { +- if (e.PropertyName == "State") +- InjectPasteUI(window); +- }; +- } +- +- // Also try immediately in case we're already in SigningIn +- InjectPasteUI(window); +- } +- catch (Exception ex) +- { +- Logger.Error($"OnDialogLoaded failed: {ex.Message}"); +- } +- } +- +- private static void InjectPasteUI(Window window) +- { +- try +- { +- var model = ((FrameworkElement)window).DataContext; +- var stateProp = model.GetType().GetProperty("State"); +- if (stateProp == null) return; +- +- var state = stateProp.GetValue(model); +- if (state.ToString() == "SigningIn") +- { +- window.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Loaded, +- new Action(() => InjectPasteUIImpl(window))); +- } +- else +- { +- HideOverlay(); +- } +- } +- catch (Exception ex) +- { +- Logger.Error($"InjectPasteUI failed: {ex.Message}"); +- } +- } +- +- private static void InjectPasteUIImpl(Window window) +- { +- try +- { +- if (_overlayPanel != null) +- { +- _overlayPanel.Visibility = Visibility.Visible; +- return; +- } +- +- var existingContent = window.Content as UIElement; +- if (existingContent == null) return; +- +- // Wrap existing window content in a new Grid so we can overlay on top +- var wrapperGrid = new Grid(); +- window.Content = wrapperGrid; +- wrapperGrid.Children.Add(existingContent); +- +- // Build overlay content +- var panel = new StackPanel +- { +- VerticalAlignment = VerticalAlignment.Center, +- Margin = new Thickness(30) +- }; +- +- var heading = new TextBlock +- { +- Text = "Running under Wine?", +- FontSize = 14, +- FontWeight = FontWeights.SemiBold, +- Foreground = new SolidColorBrush(Color.FromRgb(0x33, 0x33, 0x33)), +- Margin = new Thickness(0, 0, 0, 8) +- }; +- +- var instructions = new TextBlock +- { +- Text = "After signing in, your browser will show a " + +- "\"Launching Affinity\" page. Copy the full URL " + +- "from the address bar and paste it below:", +- Foreground = new SolidColorBrush(Color.FromRgb(0x65, 0x65, 0x65)), +- FontSize = 12, +- TextWrapping = TextWrapping.Wrap, +- Margin = new Thickness(0, 0, 0, 10) +- }; +- +- var screenshot = LoadEmbeddedImage("WineFix.Resources.signin.png"); +- Image screenshotImage = null; +- if (screenshot != null) +- { +- screenshotImage = new Image +- { +- Source = screenshot, +- Stretch = Stretch.Uniform, +- HorizontalAlignment = HorizontalAlignment.Stretch, +- Margin = new Thickness(0, 0, 0, 12) +- }; +- } +- +- var textBox = new TextBox +- { +- Height = 28, +- FontSize = 12, +- VerticalContentAlignment = VerticalAlignment.Center, +- HorizontalAlignment = HorizontalAlignment.Stretch +- }; +- +- var placeholder = new TextBlock +- { +- Text = "https://page.service.serif.com/canva-auth-redirect/...", +- Foreground = new SolidColorBrush(Color.FromRgb(0xAA, 0xAA, 0xAA)), +- FontSize = 12, +- IsHitTestVisible = false, +- VerticalAlignment = VerticalAlignment.Center, +- Margin = new Thickness(4, 0, 0, 0) +- }; +- var textBoxContainer = new Grid { Height = 28, HorizontalAlignment = HorizontalAlignment.Stretch }; +- textBoxContainer.Children.Add(textBox); +- textBoxContainer.Children.Add(placeholder); +- textBox.TextChanged += (s, e) => placeholder.Visibility = +- string.IsNullOrEmpty(textBox.Text) ? Visibility.Visible : Visibility.Collapsed; +- textBox.GotFocus += (s, e) => placeholder.Visibility = Visibility.Collapsed; +- textBox.LostFocus += (s, e) => placeholder.Visibility = +- string.IsNullOrEmpty(textBox.Text) ? Visibility.Visible : Visibility.Collapsed; +- +- var button = new Button +- { +- Content = "Submit", +- Margin = new Thickness(0, 8, 0, 0), +- Padding = new Thickness(0, 8, 0, 8), +- HorizontalAlignment = HorizontalAlignment.Stretch +- }; +- +- var errorText = new TextBlock +- { +- Foreground = Brushes.Red, +- FontSize = 11, +- TextWrapping = TextWrapping.Wrap, +- Visibility = Visibility.Collapsed, +- Margin = new Thickness(0, 4, 0, 0) +- }; +- +- button.Click += (s, e) => OnSubmitUrl(textBox.Text, errorText); +- +- panel.Children.Add(heading); +- panel.Children.Add(instructions); +- if (screenshotImage != null) +- panel.Children.Add(screenshotImage); +- panel.Children.Add(textBoxContainer); +- panel.Children.Add(button); +- panel.Children.Add(errorText); +- +- // Overlay: right-aligned, 50% width, full height, white background +- _overlayPanel = new Border +- { +- Background = new SolidColorBrush(Color.FromArgb(0xF0, 0xFF, 0xFF, 0xFF)), +- HorizontalAlignment = HorizontalAlignment.Right, +- VerticalAlignment = VerticalAlignment.Stretch, +- Child = panel +- }; +- _overlayPanel.SetBinding(FrameworkElement.WidthProperty, +- new Binding("ActualWidth") +- { +- Source = window, +- Converter = new HalfWidthConverter() +- }); +- +- wrapperGrid.Children.Add(_overlayPanel); +- +- // Nudge the "Back" button left so it's not covered by the overlay +- var contentControl = FindChild(existingContent, +- c => c.ContentTemplateSelector != null); +- if (contentControl != null) +- { +- var backButton = FindChild