this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: don't use nix eval

isabel 25dab262 39787f1f

+125 -36
+3
.env.example
··· 1 1 DISCORD_TOKEN=discord token 2 2 GITHUB_TOKEN=github token 3 + # you can find this file at https://releases.nixos.org/nixpkgs/nixpkgs-25.11pre844992.32f313e49e42/packages.json.br 4 + # p.s. remeber to decompress it 5 + NIXPKGS_JSON=./nixpkgs.json
+92
Cargo.lock
··· 33 33 ] 34 34 35 35 [[package]] 36 + name = "allocator-api2" 37 + version = "0.2.21" 38 + source = "registry+https://github.com/rust-lang/crates.io-index" 39 + checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923" 40 + 41 + [[package]] 36 42 name = "android-tzdata" 37 43 version = "0.1.1" 38 44 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 211 217 "serde", 212 218 "serde_json", 213 219 "serenity", 220 + "simd-json", 214 221 "tokio", 215 222 ] 216 223 ··· 695 702 ] 696 703 697 704 [[package]] 705 + name = "float-cmp" 706 + version = "0.10.0" 707 + source = "registry+https://github.com/rust-lang/crates.io-index" 708 + checksum = "b09cf3155332e944990140d967ff5eceb70df778b34f77d8075db46e4704e6d8" 709 + dependencies = [ 710 + "num-traits", 711 + ] 712 + 713 + [[package]] 698 714 name = "fnv" 699 715 version = "1.0.7" 700 716 source = "registry+https://github.com/rust-lang/crates.io-index" 701 717 checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" 718 + 719 + [[package]] 720 + name = "foldhash" 721 + version = "0.1.5" 722 + source = "registry+https://github.com/rust-lang/crates.io-index" 723 + checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" 702 724 703 725 [[package]] 704 726 name = "foreign-types" ··· 849 871 checksum = "73fea8450eea4bac3940448fb7ae50d91f034f941199fcd9d909a5a07aa455f0" 850 872 dependencies = [ 851 873 "cfg-if", 874 + "js-sys", 852 875 "libc", 853 876 "r-efi", 854 877 "wasi 0.14.2+wasi-0.2.4", 878 + "wasm-bindgen", 855 879 ] 856 880 857 881 [[package]] ··· 905 929 ] 906 930 907 931 [[package]] 932 + name = "halfbrown" 933 + version = "0.3.0" 934 + source = "registry+https://github.com/rust-lang/crates.io-index" 935 + checksum = "aa2c385c6df70fd180bbb673d93039dbd2cd34e41d782600bdf6e1ca7bce39aa" 936 + dependencies = [ 937 + "hashbrown 0.15.2", 938 + "serde", 939 + ] 940 + 941 + [[package]] 908 942 name = "hashbrown" 909 943 version = "0.14.5" 910 944 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 915 949 version = "0.15.2" 916 950 source = "registry+https://github.com/rust-lang/crates.io-index" 917 951 checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" 952 + dependencies = [ 953 + "allocator-api2", 954 + "equivalent", 955 + "foldhash", 956 + ] 918 957 919 958 [[package]] 920 959 name = "heck" ··· 1889 1928 ] 1890 1929 1891 1930 [[package]] 1931 + name = "ref-cast" 1932 + version = "1.0.24" 1933 + source = "registry+https://github.com/rust-lang/crates.io-index" 1934 + checksum = "4a0ae411dbe946a674d89546582cea4ba2bb8defac896622d6496f14c23ba5cf" 1935 + dependencies = [ 1936 + "ref-cast-impl", 1937 + ] 1938 + 1939 + [[package]] 1940 + name = "ref-cast-impl" 1941 + version = "1.0.24" 1942 + source = "registry+https://github.com/rust-lang/crates.io-index" 1943 + checksum = "1165225c21bff1f3bbce98f5a1f889949bc902d3575308cc7b0de30b4f6d27c7" 1944 + dependencies = [ 1945 + "proc-macro2", 1946 + "quote", 1947 + "syn 2.0.100", 1948 + ] 1949 + 1950 + [[package]] 1892 1951 name = "regex" 1893 1952 version = "1.11.1" 1894 1953 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 2353 2412 dependencies = [ 2354 2413 "libc", 2355 2414 ] 2415 + 2416 + [[package]] 2417 + name = "simd-json" 2418 + version = "0.15.1" 2419 + source = "registry+https://github.com/rust-lang/crates.io-index" 2420 + checksum = "c962f626b54771990066e5435ec8331d1462576cd2d1e62f24076ae014f92112" 2421 + dependencies = [ 2422 + "getrandom 0.3.2", 2423 + "halfbrown", 2424 + "ref-cast", 2425 + "serde", 2426 + "serde_json", 2427 + "simdutf8", 2428 + "value-trait", 2429 + ] 2430 + 2431 + [[package]] 2432 + name = "simdutf8" 2433 + version = "0.1.5" 2434 + source = "registry+https://github.com/rust-lang/crates.io-index" 2435 + checksum = "e3a9fe34e3e7a50316060351f37187a3f546bce95496156754b601a5fa71b76e" 2356 2436 2357 2437 [[package]] 2358 2438 name = "siphasher" ··· 3017 3097 version = "0.1.1" 3018 3098 source = "registry+https://github.com/rust-lang/crates.io-index" 3019 3099 checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" 3100 + 3101 + [[package]] 3102 + name = "value-trait" 3103 + version = "0.11.0" 3104 + source = "registry+https://github.com/rust-lang/crates.io-index" 3105 + checksum = "0508fce11ad19e0aab49ce20b6bec7f8f82902ded31df1c9fc61b90f0eb396b8" 3106 + dependencies = [ 3107 + "float-cmp", 3108 + "halfbrown", 3109 + "itoa", 3110 + "ryu", 3111 + ] 3020 3112 3021 3113 [[package]] 3022 3114 name = "vcpkg"
+1
Cargo.toml
··· 22 22 serde_json = "1.0.140" 23 23 serenity = "0.12.4" 24 24 poise = { git = "https://github.com/serenity-rs/poise", branch = "current" } 25 + simd-json = { version = "0.15.1", features = ["serde"] } 25 26 26 27 [dependencies.serde] 27 28 version = "1.0.219"
+29 -36
src/commands/nix/nixpkg.rs
··· 1 + use std::fs; 2 + 1 3 use crate::types::Context; 2 4 use color_eyre::eyre::Result; 3 5 use poise::{serenity_prelude::CreateEmbed, CreateReply}; 4 - use std::process::Command; 6 + 7 + #[derive(serde::Deserialize)] 8 + struct Package { 9 + pname: String, 10 + version: String, 11 + meta: PackageMeta, 12 + } 5 13 6 14 #[derive(serde::Deserialize)] 7 15 struct PackageMeta { 8 - name: String, 9 16 description: String, 10 17 homepage: Option<String>, 11 18 license: License, 12 19 maintainers: Vec<Maintainers>, 13 20 position: String, 14 - // broken: bool, 21 + broken: bool, 15 22 insecure: bool, 16 23 unfree: bool, 17 24 } ··· 25 32 #[derive(serde::Deserialize)] 26 33 struct Maintainers { 27 34 name: String, 28 - // email: Option<String>, 35 + github: String, 29 36 } 30 37 31 38 /// Track nixpkgs PRs ··· 38 45 ctx: Context<'_>, 39 46 #[description = "package name"] package: String, 40 47 ) -> Result<()> { 41 - let pkg = 42 - Command::new("nix") 43 - .args([ 44 - "eval", 45 - "--impure", 46 - "--json", 47 - "--expr", 48 - &format!( 49 - "with import <nixpkgs> {{ config.allowUnfree = true; }}; pkgs.{package}.meta", 50 - ), 51 - ]) 52 - .output()?; 48 + ctx.defer().await?; 53 49 54 - if !pkg.status.success() { 55 - ctx.say("Package not found or an error occurred.").await?; 56 - ctx.say(format!("Error: {}", String::from_utf8_lossy(&pkg.stderr))) 57 - .await?; 58 - return Ok(()); 59 - } 50 + let nixpkgs_json = 51 + std::env::var("NIXPKGS_JSON").expect("NIXPKGS_JSON environment variable must be set"); 60 52 61 - let pkg: PackageMeta = serde_json::from_slice(&pkg.stdout)?; 53 + let mut data = fs::read(nixpkgs_json)?; 54 + let pkgs: serde_json::Value = simd_json::serde::from_slice(&mut data)?; 55 + let pkg: Package = serde_json::from_value(pkgs["packages"][package].clone())?; 62 56 63 - let file = &pkg.position[51..]; 64 - let fin_file = file 65 - .split_once(':') 66 - .map_or_else(|| file.to_string(), |(before, _)| before.to_string()); 57 + let file = pkg.meta.position.split(':').next().unwrap_or("unknown"); 67 58 68 59 let embed = CreateEmbed::new() 69 - .title(pkg.name) 60 + .title(format!("{} {}", pkg.pname, pkg.version)) 70 61 .url(format!( 71 - "https://github.com/nixos/nixpkgs/blob/master/{fin_file}" 62 + "https://github.com/nixos/nixpkgs/blob/master/{file}" 72 63 )) 73 - .description(pkg.description) 64 + .description(pkg.meta.description) 74 65 .field( 75 66 "Homepage", 76 - pkg.homepage.unwrap_or_else(|| "N/A".to_string()), 67 + pkg.meta.homepage.unwrap_or_else(|| "N/A".to_string()), 77 68 false, 78 69 ) 79 - .field("license", pkg.license.spdx_id, true) 80 - .field("insecure", pkg.insecure.to_string(), true) 81 - .field("unfree", pkg.unfree.to_string(), true) 70 + .field("license", pkg.meta.license.spdx_id, true) 71 + .field("insecure", pkg.meta.insecure.to_string(), true) 72 + .field("unfree", pkg.meta.unfree.to_string(), true) 73 + .field("broken", pkg.meta.broken.to_string(), true) 82 74 .field( 83 75 "maintainers", 84 - pkg.maintainers 76 + pkg.meta 77 + .maintainers 85 78 .iter() 86 - .map(|m| m.name.clone()) 79 + .map(|m| format!("[{}](https://github.com/{})", m.name, m.github)) 87 80 .collect::<Vec<String>>() 88 81 .join(", "), 89 82 false,