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