2021-01-19 07:54:51 +01:00
|
|
|
{
|
|
|
|
description = "A post-modern text editor.";
|
|
|
|
|
|
|
|
inputs = {
|
|
|
|
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
2023-07-28 06:30:26 +02:00
|
|
|
flake-utils.url = "github:numtide/flake-utils";
|
2022-03-03 02:45:45 +01:00
|
|
|
rust-overlay = {
|
|
|
|
url = "github:oxalica/rust-overlay";
|
2023-07-28 06:30:26 +02:00
|
|
|
inputs = {
|
|
|
|
nixpkgs.follows = "nixpkgs";
|
|
|
|
flake-utils.follows = "flake-utils";
|
|
|
|
};
|
2022-03-03 02:45:45 +01:00
|
|
|
};
|
2023-07-28 06:30:26 +02:00
|
|
|
crane = {
|
|
|
|
url = "github:ipetkov/crane";
|
2022-06-21 22:59:46 +02:00
|
|
|
inputs.rust-overlay.follows = "rust-overlay";
|
2023-07-28 06:30:26 +02:00
|
|
|
inputs.flake-utils.follows = "flake-utils";
|
|
|
|
inputs.nixpkgs.follows = "nixpkgs";
|
2021-06-13 07:03:42 +02:00
|
|
|
};
|
2021-01-19 07:54:51 +01:00
|
|
|
};
|
|
|
|
|
2023-07-28 06:30:26 +02:00
|
|
|
outputs = {
|
|
|
|
self,
|
|
|
|
nixpkgs,
|
|
|
|
crane,
|
|
|
|
flake-utils,
|
|
|
|
rust-overlay,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
flake-utils.lib.eachDefaultSystem (system: let
|
|
|
|
pkgs = import nixpkgs {
|
|
|
|
inherit system;
|
|
|
|
overlays = [(import rust-overlay)];
|
2022-09-03 00:54:07 +02:00
|
|
|
};
|
2023-07-28 06:30:26 +02:00
|
|
|
mkRootPath = rel:
|
|
|
|
builtins.path {
|
|
|
|
path = "${toString ./.}/${rel}";
|
|
|
|
name = rel;
|
|
|
|
};
|
|
|
|
filteredSource = let
|
|
|
|
pathsToIgnore = [
|
|
|
|
".envrc"
|
|
|
|
".ignore"
|
|
|
|
".github"
|
|
|
|
".gitignore"
|
|
|
|
"logo_dark.svg"
|
|
|
|
"logo_light.svg"
|
|
|
|
"rust-toolchain.toml"
|
|
|
|
"rustfmt.toml"
|
|
|
|
"runtime"
|
|
|
|
"screenshot.png"
|
|
|
|
"book"
|
|
|
|
"docs"
|
|
|
|
"README.md"
|
|
|
|
"CHANGELOG.md"
|
|
|
|
"shell.nix"
|
|
|
|
"default.nix"
|
|
|
|
"grammars.nix"
|
|
|
|
"flake.nix"
|
|
|
|
"flake.lock"
|
|
|
|
];
|
|
|
|
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;
|
2023-02-25 04:27:13 +01:00
|
|
|
in
|
2023-07-28 06:30:26 +02:00
|
|
|
lib.all (p: ! (lib.hasPrefix p relPath)) pathsToIgnore;
|
|
|
|
in
|
|
|
|
builtins.path {
|
|
|
|
name = "helix-source";
|
|
|
|
path = toString ./.;
|
|
|
|
# filter out unnecessary paths
|
|
|
|
filter = ignorePaths;
|
|
|
|
};
|
|
|
|
makeOverridableHelix = old: config: let
|
|
|
|
grammars = pkgs.callPackage ./grammars.nix config;
|
|
|
|
runtimeDir = pkgs.runCommand "helix-runtime" {} ''
|
|
|
|
mkdir -p $out
|
|
|
|
ln -s ${mkRootPath "runtime"}/* $out
|
|
|
|
rm -r $out/grammars
|
|
|
|
ln -s ${grammars} $out/grammars
|
|
|
|
'';
|
|
|
|
helix-wrapped =
|
|
|
|
pkgs.runCommand
|
|
|
|
old.name
|
|
|
|
{
|
|
|
|
inherit (old) pname version;
|
|
|
|
meta = old.meta or {};
|
2023-02-25 04:27:13 +01:00
|
|
|
passthru =
|
2023-07-28 06:30:26 +02:00
|
|
|
(old.passthru or {})
|
2023-02-17 07:17:38 +01:00
|
|
|
// {
|
2023-07-28 06:30:26 +02:00
|
|
|
unwrapped = old;
|
2023-02-17 07:17:38 +01:00
|
|
|
};
|
2023-07-28 06:30:26 +02:00
|
|
|
nativeBuildInputs = [pkgs.makeWrapper];
|
|
|
|
makeWrapperArgs = config.makeWrapperArgs or [];
|
|
|
|
}
|
|
|
|
''
|
|
|
|
cp -rs --no-preserve=mode,ownership ${old} $out
|
|
|
|
wrapProgram "$out/bin/hx" ''${makeWrapperArgs[@]} --set HELIX_RUNTIME "${runtimeDir}"
|
|
|
|
'';
|
|
|
|
in
|
|
|
|
helix-wrapped
|
|
|
|
// {
|
|
|
|
override = makeOverridableHelix old;
|
|
|
|
passthru =
|
|
|
|
helix-wrapped.passthru
|
|
|
|
// {
|
|
|
|
wrapper = old: makeOverridableHelix old config;
|
2023-02-25 04:27:13 +01:00
|
|
|
};
|
2022-01-13 01:40:07 +01:00
|
|
|
};
|
2023-07-28 06:30:26 +02:00
|
|
|
stdenv =
|
|
|
|
if pkgs.stdenv.isLinux
|
|
|
|
then pkgs.stdenv
|
|
|
|
else pkgs.clangStdenv;
|
|
|
|
rustFlagsEnv =
|
|
|
|
if stdenv.isLinux
|
|
|
|
then ''$RUSTFLAGS -C link-arg=-fuse-ld=lld -C target-cpu=native -Clink-arg=-Wl,--no-rosegment''
|
|
|
|
else "$RUSTFLAGS";
|
|
|
|
rustToolchain = pkgs.pkgsBuildHost.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
|
2023-09-01 01:57:38 +02:00
|
|
|
craneLibMSRV = (crane.mkLib pkgs).overrideToolchain rustToolchain;
|
|
|
|
craneLibStable = (crane.mkLib pkgs).overrideToolchain pkgs.pkgsBuildHost.rust-bin.stable.latest.default;
|
2023-07-28 06:30:26 +02:00
|
|
|
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 = "hx";
|
|
|
|
}
|
2023-09-01 01:57:38 +02:00
|
|
|
// craneLibMSRV.crateNameFromCargoToml {cargoToml = ./helix-term/Cargo.toml;};
|
|
|
|
cargoArtifacts = craneLibMSRV.buildDepsOnly commonArgs;
|
2023-07-28 06:30:26 +02:00
|
|
|
in {
|
|
|
|
packages = {
|
2023-09-01 01:57:38 +02:00
|
|
|
helix-unwrapped = craneLibStable.buildPackage (commonArgs
|
2023-07-28 06:30:26 +02:00
|
|
|
// {
|
2023-09-01 01:57:38 +02:00
|
|
|
cargoArtifacts = craneLibStable.buildDepsOnly commonArgs;
|
2023-08-29 09:22:03 +02:00
|
|
|
postInstall = ''
|
|
|
|
mkdir -p $out/share/applications $out/share/icons/hicolor/scalable/apps $out/share/icons/hicolor/256x256/apps
|
|
|
|
cp contrib/Helix.desktop $out/share/applications
|
|
|
|
cp logo.svg $out/share/icons/hicolor/scalable/apps/helix.svg
|
|
|
|
cp contrib/helix.png $out/share/icons/hicolor/256x256/apps
|
|
|
|
'';
|
2023-07-28 06:30:26 +02:00
|
|
|
});
|
|
|
|
helix = makeOverridableHelix self.packages.${system}.helix-unwrapped {};
|
|
|
|
default = self.packages.${system}.helix;
|
|
|
|
};
|
2023-02-25 04:27:13 +01:00
|
|
|
|
2023-07-28 06:30:26 +02:00
|
|
|
checks = {
|
|
|
|
# Build the crate itself
|
|
|
|
inherit (self.packages.${system}) helix;
|
2023-02-25 04:27:13 +01:00
|
|
|
|
2023-09-01 01:57:38 +02:00
|
|
|
clippy = craneLibMSRV.cargoClippy (commonArgs
|
2023-07-28 06:30:26 +02:00
|
|
|
// {
|
|
|
|
inherit cargoArtifacts;
|
|
|
|
cargoClippyExtraArgs = "--all-targets -- --deny warnings";
|
|
|
|
});
|
2023-05-19 15:21:05 +02:00
|
|
|
|
2023-09-01 01:57:38 +02:00
|
|
|
fmt = craneLibMSRV.cargoFmt commonArgs;
|
2023-07-28 06:30:26 +02:00
|
|
|
|
2023-09-01 01:57:38 +02:00
|
|
|
doc = craneLibMSRV.cargoDoc (commonArgs
|
2023-07-28 06:30:26 +02:00
|
|
|
// {
|
|
|
|
inherit cargoArtifacts;
|
|
|
|
});
|
|
|
|
|
2023-09-01 01:57:38 +02:00
|
|
|
test = craneLibMSRV.cargoTest (commonArgs
|
2023-07-28 06:30:26 +02:00
|
|
|
// {
|
|
|
|
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="$PWD/runtime"
|
|
|
|
export RUST_BACKTRACE="1"
|
|
|
|
export RUSTFLAGS="${rustFlagsEnv}"
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
})
|
|
|
|
// {
|
|
|
|
overlays.default = final: prev: {
|
|
|
|
inherit (self.packages.${final.system}) helix;
|
2021-06-09 23:56:11 +02:00
|
|
|
};
|
2022-09-03 00:54:07 +02:00
|
|
|
};
|
2022-07-09 18:09:37 +02:00
|
|
|
|
|
|
|
nixConfig = {
|
|
|
|
extra-substituters = ["https://helix.cachix.org"];
|
|
|
|
extra-trusted-public-keys = ["helix.cachix.org-1:ejp9KQpR1FBI2onstMQ34yogDm4OgU2ru6lIwPvuCVs="];
|
|
|
|
};
|
2021-01-19 07:54:51 +01:00
|
|
|
}
|