nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at devShellTools-shell 125 lines 3.3 kB view raw
1{ 2 lib, 3 fetchFromGitHub, 4 makeWrapper, 5 nodejs, 6 matrix-sdk-crypto-nodejs, 7 python3, 8 sqlite, 9 srcOnly, 10 removeReferencesTo, 11 mkYarnPackage, 12 fetchYarnDeps, 13 stdenv, 14 cctools, 15 nixosTests, 16}: 17 18# docs: https://github.com/NixOS/nixpkgs/blob/master/doc/languages-frameworks/javascript.section.md#yarn2nix-javascript-yarn2nix 19let 20 hashesFile = builtins.fromJSON (builtins.readFile ./hashes.json); 21 nodeSources = srcOnly nodejs; 22in 23mkYarnPackage rec { 24 pname = "draupnir"; 25 version = "2.5.0"; 26 27 src = fetchFromGitHub { 28 owner = "the-draupnir-project"; 29 repo = "Draupnir"; 30 tag = "v${version}"; 31 hash = "sha256-au0qYS646MAXyfQTk6gJem3geTecgDwzZl+87/6VE5A="; 32 }; 33 34 nativeBuildInputs = [ 35 makeWrapper 36 sqlite 37 ]; 38 39 offlineCache = fetchYarnDeps { 40 name = "${pname}-yarn-offline-cache"; 41 yarnLock = src + "/yarn.lock"; 42 hash = hashesFile.yarn_offline_cache_hash; 43 }; 44 45 packageJSON = ./package.json; 46 47 pkgConfig = { 48 "@matrix-org/matrix-sdk-crypto-nodejs" = { 49 postInstall = '' 50 # replace with the existing package in nixpkgs 51 cd .. 52 rm -r matrix-sdk-crypto-nodejs 53 ln -s ${matrix-sdk-crypto-nodejs}/lib/node_modules/@matrix-org/* ./ 54 ''; 55 }; 56 57 better-sqlite3 = { 58 nativeBuildInputs = [ python3 ] ++ lib.optional stdenv.hostPlatform.isDarwin cctools.libtool; 59 postInstall = '' 60 # build native sqlite bindings 61 npm run build-release --offline --nodedir="${nodeSources}" 62 find build -type f -exec \ 63 ${lib.getExe removeReferencesTo} -t "${nodeSources}" {} \; 64 ''; 65 }; 66 }; 67 68 preBuild = '' 69 # install proper version info 70 mkdir --parents deps/draupnir/ 71 echo "${version}-nix" > deps/draupnir/version.txt 72 73 # makes network requests 74 sed -i 's/corepack //g' deps/draupnir/package.json 75 ''; 76 77 buildPhase = '' 78 runHook preBuild 79 80 yarn --offline --verbose build 81 82 runHook postBuild 83 ''; 84 85 installPhase = '' 86 runHook preInstall 87 88 mkdir --parents $out/share 89 cp --archive . $out/share/draupnir 90 91 makeWrapper ${lib.getExe nodejs} $out/bin/draupnir \ 92 --add-flags $out/share/draupnir/deps/draupnir/lib/index.js 93 94 runHook postInstall 95 ''; 96 97 distPhase = "true"; 98 99 passthru = { 100 tests = { inherit (nixosTests) draupnir; }; 101 updateScript = ./update.sh; 102 }; 103 104 meta = with lib; { 105 description = "Moderation tool for Matrix"; 106 homepage = "https://github.com/the-draupnir-project/Draupnir"; 107 longDescription = '' 108 As an all-in-one moderation tool, it can protect your server from 109 malicious invites, spam messages, and whatever else you don't want. 110 In addition to server-level protection, Draupnir is great for communities 111 wanting to protect their rooms without having to use their personal 112 accounts for moderation. 113 114 The bot by default includes support for bans, redactions, anti-spam, 115 server ACLs, room directory changes, room alias transfers, account 116 deactivation, room shutdown, and more. 117 118 A Synapse module is also available to apply the same rulesets the bot 119 uses across an entire homeserver. 120 ''; 121 license = licenses.afl3; 122 maintainers = with maintainers; [ RorySys ]; 123 mainProgram = "draupnir"; 124 }; 125}