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