@ -3,166 +3,190 @@
inputs = {
nixpkgs . url = " g i t h u b : n i x o s / n i x p k g s / n i x o s - u n s t a b l e " ;
flake-utils . url = " g i t h u b : n u m t i d e / f l a k e - u t i l s " ;
rust-overlay = {
url = " g i t h u b : o x a l i c a / r u s t - o v e r l a y " ;
inputs . nixpkgs . follows = " n i x p k g s " ;
inputs = {
nixpkgs . follows = " n i x p k g s " ;
flake-utils . follows = " f l a k e - u t i l s " ;
} ;
} ;
nci = {
url = " g i t h u b : y u s d a c r a / n i x - c a r g o - i n t e g r a t i o n " ;
inputs . nixpkgs . follows = " n i x p k g s " ;
crane = {
url = " g i t h u b : i p e t k o v / c r a n e " ;
inputs . rust-overlay . follows = " r u s t - o v e r l a y " ;
inputs . flake-utils . follows = " f l a k e - u t i l s " ;
inputs . nixpkgs . follows = " n i x p k g s " ;
} ;
parts . url = " g i t h u b : h e r c u l e s - c i / f l a k e - p a r t s " ;
} ;
outputs = inp : let
mkRootPath = rel :
builtins . path {
path = " ${ toString ./. } / ${ rel } " ;
name = rel ;
outputs = {
self ,
nixpkgs ,
crane ,
flake-utils ,
rust-overlay ,
. . .
} :
flake-utils . lib . eachDefaultSystem ( system : let
pkgs = import nixpkgs {
inherit system ;
overlays = [ ( import rust-overlay ) ] ;
} ;
filteredSource = let
pathsToIgnore = [
" . e n v r c "
" . i g n o r e "
" . g i t h u b "
" . g i t i g n o r e "
" l o g o . s v g "
" l o g o _ d a r k . s v g "
" l o g o _ l i g h t . s v g "
" r u s t - t o o l c h a i n . t o m l "
" r u s t f m t . t o m l "
" r u n t i m e "
" s c r e e n s h o t . p n g "
" b o o k "
" c o n t r i b "
" d o c s "
" R E A D M E . m d "
" C H A N G E L O G . m d "
" s h e l l . n i x "
" d e f a u l t . n i x "
" g r a m m a r s . n i x "
" f l a k e . n i x "
" f l a k e . l o c k "
] ;
ignorePaths = path : type : let
inherit ( inp . nixpkgs ) lib ;
# split the nix store path into its components
components = lib . splitString " / " path ;
# drop off the `/nix/hash-source` section from the path
relPathComponents = lib . drop 4 components ;
# reassemble the path components
relPath = lib . concatStringsSep " / " relPathComponents ;
in
lib . all ( p : ! ( lib . hasPrefix p relPath ) ) pathsToIgnore ;
in
builtins . path {
name = " h e l i x - s o u r c e " ;
path = toString ./. ;
# filter out unnecessary paths
filter = ignorePaths ;
} ;
in
inp . parts . lib . mkFlake { inputs = inp ; } {
imports = [ inp . nci . flakeModule inp . parts . flakeModules . easyOverlay ] ;
systems = [
" x 8 6 _ 6 4 - l i n u x "
" x 8 6 _ 6 4 - d a r w i n "
" a a r c h 6 4 - l i n u x "
" a a r c h 6 4 - d a r w i n "
" i 6 8 6 - l i n u x "
] ;
perSystem = {
config ,
pkgs ,
lib ,
. . .
} : let
makeOverridableHelix = old : config : let
grammars = pkgs . callPackage ./grammars.nix config ;
runtimeDir = pkgs . runCommand " h e l i x - r u n t i m e " { } ''
mkdir - p $ out
ln - s $ { mkRootPath " r u n t i m e " } /* $ o u t
rm - r $ out/grammars
ln - s $ { grammars } $ out/grammars
'' ;
helix-wrapped =
pkgs . runCommand
old . name
{
inherit ( old ) pname version ;
meta = old . meta or { } ;
passthru =
( old . passthru or { } )
// {
unwrapped = old ;
} ;
nativeBuildInputs = [ pkgs . makeWrapper ] ;
makeWrapperArgs = config . makeWrapperArgs or [ ] ;
}
''
cp - rs - - no-preserve = mode , ownership $ { old } $ out
wrapProgram " $ o u t / b i n / h x " '' ${ makeWrapperArgs [ @ ] } - - s e t H E L I X _ R U N T I M E " ${ runtimeDir } "
'' ;
mkRootPath = rel :
builtins . path {
path = " ${ toString ./. } / ${ rel } " ;
name = rel ;
} ;
filteredSource = let
pathsToIgnore = [
" . e n v r c "
" . i g n o r e "
" . g i t h u b "
" . g i t i g n o r e "
" l o g o . s v g "
" l o g o _ d a r k . s v g "
" l o g o _ l i g h t . s v g "
" r u s t - t o o l c h a i n . t o m l "
" r u s t f m t . t o m l "
" r u n t i m e "
" s c r e e n s h o t . p n g "
" b o o k "
" c o n t r i b "
" d o c s "
" R E A D M E . m d "
" C H A N G E L O G . m d "
" s h e l l . n i x "
" d e f a u l t . n i x "
" g r a m m a r s . n i x "
" f l a k e . n i x "
" f l a k e . l o c k "
] ;
ignorePaths = path : type : let
inherit ( nixpkgs ) lib ;
# split the nix store path into its components
components = lib . splitString " / " path ;
# drop off the `/nix/hash-source` section from the path
relPathComponents = lib . drop 4 components ;
# reassemble the path components
relPath = lib . concatStringsSep " / " relPathComponents ;
in
helix-wrapped
// {
override = makeOverridableHelix old ;
lib . all ( p : ! ( lib . hasPrefix p relPath ) ) pathsToIgnore ;
in
builtins . path {
name = " h e l i x - s o u r c e " ;
path = toString ./. ;
# filter out unnecessary paths
filter = ignorePaths ;
} ;
makeOverridableHelix = old : config : let
grammars = pkgs . callPackage ./grammars.nix config ;
runtimeDir = pkgs . runCommand " h e l i x - r u n t i m e " { } ''
mkdir - p $ out
ln - s $ { mkRootPath " r u n t i m e " } /* $ o u t
rm - r $ out/grammars
ln - s $ { grammars } $ out/grammars
'' ;
helix-wrapped =
pkgs . runCommand
old . name
{
inherit ( old ) pname version ;
meta = old . meta or { } ;
passthru =
helix-wrapped . passthru
( old . passthru or { } )
// {
wrapper = old : makeOverridableHelix old config ;
unwrapped = old ;
} ;
} ;
stdenv =
if pkgs . stdenv . isLinux
then pkgs . stdenv
else pkgs . clangStdenv ;
rustFlagsEnv =
if stdenv . isLinux
then '' $R U S T F L A G S - C l i n k - a r g = - f u s e - l d = l l d - C t a r g e t - c p u = n a t i v e - C l i n k - a r g = - W l , - - n o - r o s e g m e n t ''
else " $ R U S T F L A G S " ;
in {
nci . projects . " h e l i x - p r o j e c t " . relPath = " " ;
nci . crates . " h e l i x - t e r m " = {
overrides = {
add-meta . override = _ : { meta . mainProgram = " h x " ; } ;
add-inputs . overrideAttrs = prev : {
buildInputs = ( prev . buildInputs or [ ] ) ++ [ stdenv . cc . cc . lib ] ;
} ;
disable-grammar-builds = {
# disable fetching and building of tree-sitter grammars in the helix-term build.rs
HELIX_DISABLE_AUTO_GRAMMAR_BUILD = " 1 " ;
nativeBuildInputs = [ pkgs . makeWrapper ] ;
makeWrapperArgs = config . makeWrapperArgs or [ ] ;
}
''
cp - rs - - no-preserve = mode , ownership $ { old } $ out
wrapProgram " $ o u t / b i n / h x " '' ${ makeWrapperArgs [ @ ] } - - s e t H E L I X _ R U N T I M E " ${ runtimeDir } "
'' ;
in
helix-wrapped
// {
override = makeOverridableHelix old ;
passthru =
helix-wrapped . passthru
// {
wrapper = old : makeOverridableHelix old config ;
} ;
disable-tests = { checkPhase = " : " ; } ;
set-stdenv . override = _ : { inherit stdenv ; } ;
set-filtered-src . override = _ : { src = filteredSource ; } ;
} ;
} ;
stdenv =
if pkgs . stdenv . isLinux
then pkgs . stdenv
else pkgs . clangStdenv ;
rustFlagsEnv =
if stdenv . isLinux
then '' $R U S T F L A G S - C l i n k - a r g = - f u s e - l d = l l d - C t a r g e t - c p u = n a t i v e - C l i n k - a r g = - W l , - - n o - r o s e g m e n t ''
else " $ R U S T F L A G S " ;
rustToolchain = pkgs . pkgsBuildHost . rust-bin . fromRustupToolchainFile ./rust-toolchain.toml ;
craneLib = ( crane . mkLib pkgs ) . overrideToolchain rustToolchain ;
commonArgs =
{
inherit stdenv ;
src = filteredSource ;
# disable fetching and building of tree-sitter grammars in the helix-term build.rs
HELIX_DISABLE_AUTO_GRAMMAR_BUILD = " 1 " ;
buildInputs = [ stdenv . cc . cc . lib ] ;
# disable tests
doCheck = false ;
meta . mainProgram = " h x " ;
}
// craneLib . crateNameFromCargoToml { cargoToml = ./helix-term/Cargo.toml ; } ;
cargoArtifacts = craneLib . buildDepsOnly commonArgs ;
in {
packages = {
helix-unwrapped = craneLib . buildPackage ( commonArgs
// {
inherit cargoArtifacts ;
} ) ;
helix = makeOverridableHelix self . packages . ${ system } . helix-unwrapped { } ;
default = self . packages . ${ system } . helix ;
} ;
packages . helix-unwrapped = config . nci . outputs . " h e l i x - t e r m " . packages . release ;
packages . helix-unwrapped-dev = config . nci . outputs . " h e l i x - t e r m " . packages . dev ;
packages . helix = makeOverridableHelix config . packages . helix-unwrapped { } ;
packages . helix-dev = makeOverridableHelix config . packages . helix-unwrapped-dev { } ;
packages . default = config . packages . helix ;
checks = {
# Build the crate itself
inherit ( self . packages . ${ system } ) helix ;
overlayAttrs = {
inherit ( config . packages ) helix ;
} ;
clippy = craneLib . cargoClippy ( commonArgs
// {
inherit cargoArtifacts ;
cargoClippyExtraArgs = " - - a l l - t a r g e t s - - - - d e n y w a r n i n g s " ;
} ) ;
devShells . default = config . nci . outputs . " h e l i x - p r o j e c t " . devShell . overrideAttrs ( old : {
nativeBuildInputs =
( old . nativeBuildInputs or [ ] )
++ ( with pkgs ; [ lld_13 cargo-flamegraph rust-analyzer ] )
++ ( lib . optional ( stdenv . isx86_64 && stdenv . isLinux ) pkgs . cargo-tarpaulin )
++ ( lib . optional stdenv . isLinux pkgs . lldb )
++ ( lib . optional stdenv . isDarwin pkgs . darwin . apple_sdk . frameworks . CoreFoundation ) ;
shellHook = ''
export HELIX_RUNTIME = " $ P W D / r u n t i m e "
export RUST_BACKTRACE = " 1 "
export RUSTFLAGS = " ${ rustFlagsEnv } "
'' ;
} ) ;
fmt = craneLib . cargoFmt commonArgs ;
doc = craneLib . cargoDoc ( commonArgs
// {
inherit cargoArtifacts ;
} ) ;
test = craneLib . cargoTest ( commonArgs
// {
inherit cargoArtifacts ;
} ) ;
} ;
devShells . default = pkgs . mkShell {
inputsFrom = builtins . attrValues self . checks . ${ system } ;
nativeBuildInputs = with pkgs ;
[ lld_13 cargo-flamegraph rust-analyzer ]
++ ( lib . optional ( stdenv . isx86_64 && stdenv . isLinux ) pkgs . cargo-tarpaulin )
++ ( lib . optional stdenv . isLinux pkgs . lldb )
++ ( lib . optional stdenv . isDarwin pkgs . darwin . apple_sdk . frameworks . CoreFoundation ) ;
shellHook = ''
export HELIX_RUNTIME = " $ P W D / r u n t i m e "
export RUST_BACKTRACE = " 1 "
export RUSTFLAGS = " ${ rustFlagsEnv } "
'' ;
} ;
} )
// {
overlays . default = final : prev : {
inherit ( self . packages . ${ final . system } ) helix ;
} ;
} ;