Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'flake.nix')
| -rw-r--r-- | flake.nix | 219 |
1 files changed, 152 insertions, 67 deletions
@@ -7,87 +7,172 @@ url = "github:oxalica/rust-overlay"; inputs.nixpkgs.follows = "nixpkgs"; }; + nci = { + url = "github:yusdacra/nix-cargo-integration"; + inputs.nixpkgs.follows = "nixpkgs"; + inputs.rust-overlay.follows = "rust-overlay"; + }; }; outputs = { self, nixpkgs, - rust-overlay, + nci, ... }: let - inherit (nixpkgs) lib; - eachSystem = lib.genAttrs lib.systems.flakeExposed; - pkgsFor = eachSystem (system: - import nixpkgs { - localSystem.system = system; - overlays = [(import rust-overlay) self.overlays.helix]; - }); - gitRev = self.rev or self.dirtyRev or null; - in { - packages = eachSystem (system: { - inherit (pkgsFor.${system}) helix; - /* - The default Helix build. Uses the latest stable Rust toolchain, and unstable - nixpkgs. - - The build inputs can be overridden with the following: - - packages.${system}.default.override { rustPlatform = newPlatform; }; - - Overriding a derivation attribute can be done as well: - - packages.${system}.default.overrideAttrs { buildType = "debug"; }; - */ - default = self.packages.${system}.helix; - }); - checks = - lib.mapAttrs (system: pkgs: let - # Get Helix's MSRV toolchain to build with by default. - msrvToolchain = pkgs.pkgsBuildHost.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; - msrvPlatform = pkgs.makeRustPlatform { - cargo = msrvToolchain; - rustc = msrvToolchain; + lib = nixpkgs.lib; + ncl = nci.lib.nci-lib; + mkRootPath = rel: + builtins.path { + path = "${toString ./.}/${rel}"; + name = rel; + }; + filteredSource = let + pathsToIgnore = [ + ".envrc" + ".ignore" + ".github" + "runtime" + "screenshot.png" + "book" + "contrib" + "docs" + "README.md" + "CHANGELOG.md" + "shell.nix" + "default.nix" + "grammars.nix" + "flake.nix" + "flake.lock" + ]; + ignorePaths = path: type: let + # 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 = "helix-source"; + path = toString ./.; + # filter out unnecessary paths + filter = ignorePaths; + }; + outputs = nci.lib.makeOutputs { + root = ./.; + config = common: { + outputs = { + # rename helix-term to helix since it's our main package + rename = {"helix-term" = "helix";}; + # Set default app to hx (binary is from helix-term release build) + # Set default package to helix-term release build + defaults = { + app = "hx"; + package = "helix"; + }; }; - in { - helix = self.packages.${system}.helix.override { - rustPlatform = msrvPlatform; + cCompiler.package = with common.pkgs; + if stdenv.isLinux + then gcc + else clang; + shell = { + packages = with common.pkgs; + [lld_13 cargo-flamegraph rust-analyzer] + ++ (lib.optional (stdenv.isx86_64 && stdenv.isLinux) cargo-tarpaulin) + ++ (lib.optional stdenv.isLinux lldb); + env = [ + { + name = "HELIX_RUNTIME"; + eval = "$PWD/runtime"; + } + { + name = "RUST_BACKTRACE"; + value = "1"; + } + { + name = "RUSTFLAGS"; + value = + if common.pkgs.stdenv.isLinux + then "-C link-arg=-fuse-ld=lld -C target-cpu=native -Clink-arg=-Wl,--no-rosegment" + else ""; + } + ]; }; - }) - pkgsFor; + }; + pkgConfig = common: { + helix-term = { + # Wrap helix with runtime + wrapper = _: old: let + inherit (common) pkgs; + 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 = + common.internal.pkgsSet.utils.wrapDerivation old + { + nativeBuildInputs = [pkgs.makeWrapper]; + makeWrapperArgs = config.makeWrapperArgs or []; + } + '' + rm -rf $out/bin + mkdir -p $out/bin + ln -sf ${old}/bin/* $out/bin/ + wrapProgram "$out/bin/hx" ''${makeWrapperArgs[@]} --set HELIX_RUNTIME "${runtimeDir}" + ''; + in + helix-wrapped + // {override = makeOverridableHelix old;}; + in + makeOverridableHelix old {}; + overrides.fix-build.overrideAttrs = prev: { + src = filteredSource; - # Devshell behavior is preserved. - devShells = - lib.mapAttrs (system: pkgs: { - default = let - commonRustFlagsEnv = "-C link-arg=-fuse-ld=lld -C target-cpu=native --cfg tokio_unstable"; - platformRustFlagsEnv = lib.optionalString pkgs.stdenv.isLinux "-Clink-arg=-Wl,--no-rosegment"; - in - pkgs.mkShell { - inputsFrom = [self.checks.${system}.helix]; - nativeBuildInputs = with pkgs; - [ - lld - cargo-flamegraph - rust-bin.nightly.latest.rust-analyzer - ] - ++ (lib.optional (stdenv.isx86_64 && stdenv.isLinux) cargo-tarpaulin) - ++ (lib.optional stdenv.isLinux lldb); - shellHook = '' - export RUST_BACKTRACE="1" - export RUSTFLAGS="''${RUSTFLAGS:-""} ${commonRustFlagsEnv} ${platformRustFlagsEnv}" + # disable fetching and building of tree-sitter grammars in the helix-term build.rs + HELIX_DISABLE_AUTO_GRAMMAR_BUILD = "1"; + + buildInputs = ncl.addBuildInputs prev [common.config.cCompiler.package.cc.lib]; + + # link languages and theme toml files since helix-term expects them (for tests) + preConfigure = '' + ${prev.preConfigure or ""} + ${ + lib.concatMapStringsSep + "\n" + (path: "ln -sf ${mkRootPath path} ..") + ["languages.toml" "theme.toml" "base16_theme.toml"] + } ''; - }; - }) - pkgsFor; + checkPhase = ":"; - overlays = { - helix = final: prev: { - helix = final.callPackage ./default.nix {inherit gitRev;}; + meta.mainProgram = "hx"; + }; + }; }; - - default = self.overlays.helix; }; - }; + in + outputs + // { + packages = + lib.mapAttrs + ( + system: packages: + packages + // { + helix-unwrapped = packages.helix.passthru.unwrapped; + helix-unwrapped-dev = packages.helix-dev.passthru.unwrapped; + } + ) + outputs.packages; + }; + nixConfig = { extra-substituters = ["https://helix.cachix.org"]; extra-trusted-public-keys = ["helix.cachix.org-1:ejp9KQpR1FBI2onstMQ34yogDm4OgU2ru6lIwPvuCVs="]; |