{ description = "A terminal UI client for the matrix chat protocol"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; # inputs for following flake-compat = { url = "github:edolstra/flake-compat"; flake = false; }; crane = { url = "github:ipetkov/crane"; inputs = { nixpkgs.follows = "nixpkgs"; flake-compat.follows = "flake-compat"; flake-utils.follows = "flake-utils"; rust-overlay.follows = "rust-overlay"; }; }; flake-utils = { url = "github:numtide/flake-utils"; inputs = {}; }; rust-overlay = { url = "github:oxalica/rust-overlay"; inputs = { nixpkgs.follows = "nixpkgs"; flake-utils.follows = "flake-utils"; }; }; # cranelift rustc_cranelift_backend = { url = "github:bjorn3/rustc_codegen_cranelift/dev"; flake = false; }; rustc_cranelift_backend_src = { url = "https://github.com/bjorn3/rustc_codegen_cranelift/releases/download/dev/cg_clif-x86_64-unknown-linux-gnu.tar.xz"; flake = false; }; }; outputs = { self, nixpkgs, crane, flake-utils, rust-overlay, rustc_cranelift_backend, rustc_cranelift_backend_src, ... }: flake-utils.lib.eachDefaultSystem (system: let inherit (pkgs) lib; bintools-wrapper = "${nixpkgs}/pkgs/build-support/bintools-wrapper"; mold' = pkgs.symlinkJoin { name = "mold"; paths = [pkgs.mold]; nativeBuildInputs = [pkgs.makeWrapper]; suffixSalt = lib.replaceStrings ["-" "."] ["_" "_"] pkgs.targetPlatform.config; postBuild = '' for bin in ${pkgs.mold}/bin/*; do rm $out/bin/"$(basename "$bin")" export prog="$bin" substituteAll "${bintools-wrapper}/ld-wrapper.sh" $out/bin/"$(basename "$bin")" chmod +x $out/bin/"$(basename "$bin")" mkdir -p $out/nix-support substituteAll "${bintools-wrapper}/add-flags.sh" $out/nix-support/add-flags.sh substituteAll "${bintools-wrapper}/add-hardening.sh" $out/nix-support/add-hardening.sh substituteAll "${bintools-wrapper}/../wrapper-common/utils.bash" $out/nix-support/utils.bash done ''; }; c_rust = pkgs.rust-bin.fromRustupToolchainFile "${rustc_cranelift_backend}/rust-toolchain"; rcb = pkgs.stdenv.mkDerivation { pname = "rustc_cranelift_backend"; version = "1.0"; buildInputs = [c_rust]; nativeBuildInputs = with pkgs; [gawk fd]; srcs = ["${rustc_cranelift_backend_src}" "${c_rust}"]; sourceRoot = "."; postUnpack = '' rust_dir="$(fd . --max-depth 1 | awk '!/source/ && !/env-vars/')" # remove unneeded stuff rm -r "$rust_dir"/{bin,nix-support,share}; rm -r "$rust_dir"/lib/rustlib/{etc,src,rustc-src}; cp -r "$rust_dir"/. source/extra_dependencies rm -r "$rust_dir" cd source ''; postPatch = '' # patch bins for file in $(fd . --type file);do file="$(file --mime "$file" | awk 'BEGIN{FS=":"}/application\/x-pie-executable/{print $1}')"; if [ "$file" ]; then echo "file: '$file' matches"; correct_interpreter_path="$(ldd "$file" | tail -n1 | awk 'BEGIN{FS="=> "} {print $2}' | awk 'BEGIN{FS=" "}{print $1}')" echo "correct interpreter path is: '$correct_interpreter_path'" patchelf --set-interpreter "$correct_interpreter_path" "$file" if [ "$(patchelf --print-interpreter "$file")" = "$correct_interpreter_path" ];then echo "Set interpreter"; else echo "Failed to set interprter, the interpreter still is $(patchelf --print-interpreter )"; exit 1 fi fi done # patch libs all_files=$(mktemp); for file in $(fd .);do canonical_path="$(readlink -f "$file")" file="$(file --mime "$canonical_path" | awk 'BEGIN{FS=":"}/application\/x-sharedlib/{print $1}')"; if [ "$file" ]; then echo "$file" >> $all_files; fi done while read -r file; do echo "___________________"; echo "Checking file: '$file'"; is_missing="$(ldd "$file" | awk 'BEGIN{FS="=>"}{if (/not found/){print $1}}')" if [ "$is_missing" ];then echo "Warning: The following things are missing:"; for line in $is_missing; do echo " $line"; done echo for line in $is_missing; do echo "Searching for a substitute for '$line'" substitute="$(grep "$line" "$all_files" | awk 'BEGIN{FS=" "}{print $1}' | tail -n1)"; if [ "$substitute" ]; then echo "Found '$substitute', which can substitute '$line'" echo "Patching.." patchelf --replace-needed "$line" "$(readlink -f "$substitute")" "$file"; else echo "Error: Failed to find a substitute" fi done else echo "This file is not missing anything" fi done < $all_files rm $all_files ''; installPhase = '' install -d $out/ cp -r ./. $out/ ''; }; pkgs = import nixpkgs { inherit system; overlays = [(import rust-overlay)]; }; nightly = false; rust = if nightly then pkgs.rust-bin.selectLatestNightlyWith (toolchain: toolchain.default) else pkgs.rust-bin.stable.latest.default; craneLib = (crane.mkLib pkgs).overrideToolchain rust; nativeBuildInputs = with pkgs; [ pkg-config mold' rcb ]; buildInputs = with pkgs; [ openssl lua54Packages.lua ]; craneBuild = craneLib.buildPackage { src = craneLib.cleanCargoSource ./.; doCheck = true; inherit nativeBuildInputs buildInputs; }; in { packages = { default = craneBuild; }; app.default = { type = "app"; program = "${self.packages.${system}.default}/bin/trinitix"; }; devShells.default = pkgs.mkShell { packages = with pkgs; [ nil alejandra statix ltex-ls rust rust-analyzer cargo-edit cargo-expand ]; inherit nativeBuildInputs buildInputs; }; }); } # vim: ts=2