fork/helix
git clone https://git.julia.blue/fork/helix
7b9b9329
25.01
1{ 2description = "A post-modern text editor." ; 3 4inputs = { 5nixpkgs . url = "github:nixos/nixpkgs/nixos-unstable" ; 6flake-utils . url = "github:numtide/flake-utils" ; 7rust-overlay = { 8url = "github:oxalica/rust-overlay" ; 9inputs . nixpkgs . follows = "nixpkgs" ; 10}; 11crane . url = "github:ipetkov/crane" ; 12}; 13 14outputs = { 15self , 16nixpkgs , 17crane , 18flake-utils , 19rust-overlay , 20 ... 21} : 22flake-utils . lib . eachDefaultSystem ( system :let 23pkgs = import nixpkgs { 24inherit system ; 25overlays = [( import rust-overlay )]; 26}; 27mkRootPath = rel : 28builtins . path { 29path = " ${ toString ./. } / ${ rel } " ; 30name = rel ; 31}; 32filteredSource = let 33pathsToIgnore = [ 34".envrc" 35".ignore" 36".github" 37".gitignore" 38"logo_dark.svg" 39"logo_light.svg" 40"rust-toolchain.toml" 41"rustfmt.toml" 42"runtime" 43"screenshot.png" 44"book" 45"docs" 46"README.md" 47"CHANGELOG.md" 48"shell.nix" 49"default.nix" 50"grammars.nix" 51"flake.nix" 52"flake.lock" 53]; 54ignorePaths = path :type :let 55inherit ( nixpkgs ) lib ; 56# split the nix store path into its components 57components = lib . splitString "/" path ; 58# drop off the `/nix/hash-source` section from the path 59relPathComponents = lib . drop 4 components ; 60# reassemble the path components 61relPath = lib . concatStringsSep "/" relPathComponents ; 62in 63lib . all ( p :! ( lib . hasPrefix p relPath )) pathsToIgnore ; 64in 65builtins . path { 66name = "helix-source" ; 67path = toString ./. ; 68# filter out unnecessary paths 69filter = ignorePaths ; 70}; 71makeOverridableHelix = old :config :let 72grammars = pkgs . callPackage ./grammars.nix config ; 73runtimeDir = pkgs . runCommand "helix-runtime" {} '' 74mkdir -p $ out 75ln -s ${ mkRootPath "runtime" } /* $ out 76rm -r $ out /grammars 77ln -s ${ grammars } $ out /grammars 78'' ; 79helix-wrapped = 80pkgs . runCommand 81old . name 82{ 83inherit ( old ) pname version ; 84meta = old . meta or {}; 85passthru = 86( old . passthru or {}) 87// { 88unwrapped = old ; 89}; 90nativeBuildInputs = [ pkgs . makeWrapper ]; 91makeWrapperArgs = config . makeWrapperArgs or []; 92} 93'' 94cp -rs --no-preserve=mode,ownership ${ old } $ out 95wrapProgram " $ out /bin/hx" '' $ { makeWrapperArgs [@]} -- set HELIX_RUNTIME " ${ runtimeDir } " 96'' ; 97in 98helix-wrapped 99// { 100override = makeOverridableHelix old ; 101passthru = 102helix-wrapped . passthru 103// { 104wrapper = old :makeOverridableHelix old config ; 105}; 106}; 107stdenv = 108if pkgs . stdenv . isLinux 109then pkgs . stdenv 110else pkgs . clangStdenv ; 111rustFlagsEnv = pkgs . lib . optionalString stdenv . isLinux "-C link-arg=-fuse-ld=lld -C target-cpu=native -Clink-arg=-Wl,--no-rosegment --cfg tokio_unstable" ; 112rustToolchain = pkgs . pkgsBuildHost . rust-bin . fromRustupToolchainFile ./rust-toolchain.toml ; 113craneLibMSRV = ( crane . mkLib pkgs ). overrideToolchain rustToolchain ; 114craneLibStable = ( crane . mkLib pkgs ). overrideToolchain pkgs . pkgsBuildHost . rust-bin . stable . latest . default ; 115commonArgs = { 116inherit stdenv ; 117inherit ( craneLibMSRV . crateNameFromCargoToml { cargoToml = ./helix-term/Cargo.toml ;}) pname ; 118inherit ( craneLibMSRV . crateNameFromCargoToml { cargoToml = ./Cargo.toml ;}) version ; 119src = filteredSource ; 120# disable fetching and building of tree-sitter grammars in the helix-term build.rs 121HELIX_DISABLE_AUTO_GRAMMAR_BUILD = "1" ; 122buildInputs = [ stdenv . cc . cc . lib ]; 123nativeBuildInputs = [ pkgs . installShellFiles ]; 124# disable tests 125doCheck = false ; 126meta . mainProgram = "hx" ; 127}; 128cargoArtifacts = craneLibMSRV . buildDepsOnly commonArgs ; 129in { 130packages = { 131helix-unwrapped = craneLibStable . buildPackage ( commonArgs 132// { 133cargoArtifacts = craneLibStable . buildDepsOnly commonArgs ; 134postInstall = '' 135mkdir -p $ out /share/applications $ out /share/icons/hicolor/scalable/apps $ out /share/icons/hicolor/256x256/apps 136cp contrib/Helix.desktop $ out /share/applications 137cp logo.svg $ out /share/icons/hicolor/scalable/apps/helix.svg 138cp contrib/helix.png $ out /share/icons/hicolor/256x256/apps 139installShellCompletion contrib/completion/hx.{bash,fish,zsh} 140'' ; 141# set git revision for nix flake builds, see 'git_hash' in helix-loader/build.rs 142HELIX_NIX_BUILD_REV = self . rev or self . dirtyRev or null ; 143}); 144helix = makeOverridableHelix self . packages .${ system }. helix-unwrapped {}; 145default = self . packages .${ system }. helix ; 146}; 147 148checks = { 149# Build the crate itself 150inherit ( self . packages .${ system }) helix ; 151 152clippy = craneLibMSRV . cargoClippy ( commonArgs 153// { 154inherit cargoArtifacts ; 155cargoClippyExtraArgs = "--all-targets -- --deny warnings" ; 156}); 157 158fmt = craneLibMSRV . cargoFmt commonArgs ; 159 160doc = craneLibMSRV . cargoDoc ( commonArgs 161// { 162inherit cargoArtifacts ; 163}); 164 165test = craneLibMSRV . cargoTest ( commonArgs 166// { 167inherit cargoArtifacts ; 168}); 169}; 170 171devShells . default = pkgs . mkShell { 172inputsFrom = builtins . attrValues self . checks .${ system }; 173nativeBuildInputs = with pkgs ; 174[ lld_13 cargo-flamegraph rust-analyzer ] 175++ ( lib . optional ( stdenv . isx86_64 && stdenv . isLinux ) pkgs . cargo-tarpaulin ) 176++ ( lib . optional stdenv . isLinux pkgs . lldb ) 177++ ( lib . optional stdenv . isDarwin pkgs . darwin . apple_sdk . frameworks . CoreFoundation ); 178shellHook = '' 179export HELIX_RUNTIME =" $ PWD /runtime" 180export RUST_BACKTRACE ="1" 181export RUSTFLAGS ="'' $ { RUSTFLAGS:- "" } ${ rustFlagsEnv } " 182'' ; 183}; 184}) 185// { 186overlays . default = final :prev :{ 187inherit ( self . packages .${ final . system }) helix ; 188}; 189}; 190 191nixConfig = { 192extra-substituters = [ "https://helix.cachix.org" ]; 193extra-trusted-public-keys = [ "helix.cachix.org-1:ejp9KQpR1FBI2onstMQ34yogDm4OgU2ru6lIwPvuCVs=" ]; 194}; 195}