summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--flake.nix2
-rw-r--r--home/packages.nix2
-rw-r--r--pkgs/overlay.nix23
-rw-r--r--pkgs/patches/transport-validator-without-daemon.patch123
4 files changed, 149 insertions, 1 deletions
diff --git a/flake.nix b/flake.nix
index e984866..2771329 100644
--- a/flake.nix
+++ b/flake.nix
@@ -155,7 +155,7 @@
travelynx crs-tracker crs-php bahnhof-name matrix-to
hikari_unstable heartwood radicle-interface radicle-tui
inweb nomsring bookwyrm mollysocket git-annex-remote-remarkable2
- ntfy-matrix-bot;
+ ntfy-matrix-bot transport_validator;
tests.bookwyrm = nixpkgs.nixosTest ./tests/bookwyrm.nix;
};
diff --git a/home/packages.nix b/home/packages.nix
index 5b984a6..1f5e8cf 100644
--- a/home/packages.nix
+++ b/home/packages.nix
@@ -33,6 +33,8 @@ in
kitty baobab
# gnss things
gpsd galmon-full
+ # transport things
+ transport_validator
# things for emacs
sqlite brightnessctl scrot playerctl tlp (aspellWithDicts (ds: [ds.en]))
emacs.pkgs.mu4e
diff --git a/pkgs/overlay.nix b/pkgs/overlay.nix
index f40aac1..4d1d55d 100644
--- a/pkgs/overlay.nix
+++ b/pkgs/overlay.nix
@@ -75,6 +75,29 @@ in
doCheck = false;
};
+ transport_validator = rustPlatform.buildRustPackage rec {
+ pname = "transport-validator";
+ version = "git";
+ src = self.fetchFromGitHub {
+ owner = "etalab";
+ repo = pname;
+ rev = "f50bee8af83af04805b1b4fcca334152d382c276";
+ hash = "sha256-MB66OkSldL0Uy9N0aNOWr293R1Wisu/r0IZNC08m/Ps=";
+ };
+
+ # i patch the Cargo.toml to have it optionally not depend on actix
+ buildNoDefaultFeatures = true;
+ patches = [ ./patches/transport-validator-without-daemon.patch ];
+
+ cargoLock.lockFile = "${src}/Cargo.lock";
+ # binary name is `main` for some reason
+ postInstall = ''
+ mv $out/bin/main $out/bin/transport-validator
+ '';
+
+ meta.mainProgram = "transport-validator";
+ };
+
kijetesantakaluotokieni = self.rustPlatform.buildRustPackage rec {
pname = "kijetesantakaluotokieni";
version = "git";
diff --git a/pkgs/patches/transport-validator-without-daemon.patch b/pkgs/patches/transport-validator-without-daemon.patch
new file mode 100644
index 0000000..1703cbe
--- /dev/null
+++ b/pkgs/patches/transport-validator-without-daemon.patch
@@ -0,0 +1,123 @@
+From c9d0a4df3dbad5ed6cf1dd6d70e70f926cf42bb0 Mon Sep 17 00:00:00 2001
+From: stuebinm <stuebinm@disroot.org>
+Date: Mon, 15 Apr 2024 21:01:27 +0200
+Subject: [PATCH] make daemon support optional behind a cargo feature
+
+This greatly saves on compile times and binary size
+(282 vs. 181 crates, and 141 MiB vs 47 MiB for debug builds,
+8 MiB vs 3.2 MiB for release builds)
+---
+ Cargo.toml | 15 ++++++++++-----
+ readme.md | 6 ++++++
+ src/bin/main.rs | 18 +++++++++++++++---
+ src/lib.rs | 1 +
+ 4 files changed, 32 insertions(+), 8 deletions(-)
+
+diff --git a/Cargo.toml b/Cargo.toml
+index df15b04..94c9e19 100644
+--- a/Cargo.toml
++++ b/Cargo.toml
+@@ -9,14 +9,19 @@ lto = true # Enable Link Time Optimization
+ codegen-units = 1 # Reduce number of codegen units to increase optimizations.
+ panic = 'abort' # Abort on panic
+
++[features]
++default = ["daemon"]
++daemon = ["actix-web", "actix-rt", "futures", "read-url", "env_logger"]
++read-url = ["gtfs-structures/read-url"]
++
+ [dependencies]
+ chrono = { version = "0.4", features = ["serde"] }
+ chrono-tz = "0.8"
+-env_logger = "0.10"
++env_logger = { version = "0.10", optional = true }
+ anyhow = "1"
+-futures = "0.3"
++futures = { version = "0.3", optional = true }
+ geo = "0.27"
+-gtfs-structures = "0.40"
++gtfs-structures = { version = "0.40", default-features = false }
+ iso4217 = "0.3"
+ isolang = "2.1"
+ itertools = "0.12"
+@@ -26,8 +31,8 @@ serde_json = "1.0"
+ serde_yaml = "0.9"
+ structopt = "0.3"
+ url = "2"
+-actix-web = "4.0"
+-actix-rt = "2"
++actix-web = { version = "4.0", optional = true }
++actix-rt = { version = "2", optional = true }
+ geojson = "0.24"
+ rgb = "0.8"
+
+diff --git a/readme.md b/readme.md
+index 667a2f1..f8e175b 100644
+--- a/readme.md
++++ b/readme.md
+@@ -317,6 +317,12 @@ cargo run --release -- -i some_gtfs.zip
+ cargo run --release -- -i https://example.com/network.gfts
+ ```
+
++If you do not intend to run the validator as a dæmon, it can be compiled without dæmon support, saving on compile time and binary size:
++
++```
++cargo run --release --no-default-features -- -i some_gtfs.zip
++```
++
+ ### Run as a dæmon
+
+ The validator can run as a HTTP dæmon to validate any file from a url.
+diff --git a/src/bin/main.rs b/src/bin/main.rs
+index 52d93a9..e9bd7f2 100644
+--- a/src/bin/main.rs
++++ b/src/bin/main.rs
+@@ -1,4 +1,6 @@
+-use validator::{custom_rules, daemon, validate};
++#[cfg(feature = "daemon")]
++use validator::daemon;
++use validator::{custom_rules, validate};
+
+ use structopt::clap::arg_enum;
+ use structopt::StructOpt;
+@@ -45,6 +47,7 @@ struct Opt {
+ }
+
+ fn main() -> Result<(), anyhow::Error> {
++ #[cfg(feature = "daemon")]
+ env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info")).init();
+
+ let opt = Opt::from_args();
+@@ -59,8 +62,17 @@ fn main() -> Result<(), anyhow::Error> {
+ };
+ println!("{}", serialized);
+ } else {
+- log::info!("Starting the validator as a dæmon");
+- daemon::run_server()?;
++ #[cfg(feature = "daemon")]
++ {
++ log::info!("Starting the validator as a dæmon");
++ daemon::run_server()?;
++ }
++ #[cfg(not(feature = "daemon"))]
++ {
++ eprintln!("transport-validator was compiled without support for running as daemon.");
++ eprintln!("use -i to supply a local file to test instead.");
++ std::process::exit(1);
++ }
+ }
+ Ok(())
+ }
+diff --git a/src/lib.rs b/src/lib.rs
+index d0e76f9..c4e8188 100644
+--- a/src/lib.rs
++++ b/src/lib.rs
+@@ -1,4 +1,5 @@
+ pub mod custom_rules;
++#[cfg(feature = "daemon")]
+ pub mod daemon;
+ pub mod issues;
+ pub mod metadatas;
+--
+2.42.0
+