aboutsummaryrefslogtreecommitdiff
path: root/flake.nix
diff options
context:
space:
mode:
Diffstat (limited to 'flake.nix')
-rw-r--r--flake.nix310
1 files changed, 167 insertions, 143 deletions
diff --git a/flake.nix b/flake.nix
index 81f0a05c..fc9d8c44 100644
--- a/flake.nix
+++ b/flake.nix
@@ -3,166 +3,190 @@
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
+ flake-utils.url = "github:numtide/flake-utils";
rust-overlay = {
url = "github:oxalica/rust-overlay";
- inputs.nixpkgs.follows = "nixpkgs";
+ inputs = {
+ nixpkgs.follows = "nixpkgs";
+ flake-utils.follows = "flake-utils";
+ };
};
- nci = {
- url = "github:yusdacra/nix-cargo-integration";
- inputs.nixpkgs.follows = "nixpkgs";
+ crane = {
+ url = "github:ipetkov/crane";
inputs.rust-overlay.follows = "rust-overlay";
+ inputs.flake-utils.follows = "flake-utils";
+ inputs.nixpkgs.follows = "nixpkgs";
};
- parts.url = "github:hercules-ci/flake-parts";
};
- 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 = [
- ".envrc"
- ".ignore"
- ".github"
- ".gitignore"
- "logo.svg"
- "logo_dark.svg"
- "logo_light.svg"
- "rust-toolchain.toml"
- "rustfmt.toml"
- "runtime"
- "screenshot.png"
- "book"
- "contrib"
- "docs"
- "README.md"
- "CHANGELOG.md"
- "shell.nix"
- "default.nix"
- "grammars.nix"
- "flake.nix"
- "flake.lock"
- ];
- 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 = "helix-source";
- path = toString ./.;
- # filter out unnecessary paths
- filter = ignorePaths;
- };
- in
- inp.parts.lib.mkFlake {inputs = inp;} {
- imports = [inp.nci.flakeModule inp.parts.flakeModules.easyOverlay];
- systems = [
- "x86_64-linux"
- "x86_64-darwin"
- "aarch64-linux"
- "aarch64-darwin"
- "i686-linux"
- ];
- perSystem = {
- config,
- pkgs,
- lib,
- ...
- }: let
- 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 {};
- passthru =
- (old.passthru or {})
- // {
- unwrapped = old;
- };
- nativeBuildInputs = [pkgs.makeWrapper];
- makeWrapperArgs = config.makeWrapperArgs or [];
- }
- ''
- cp -rs --no-preserve=mode,ownership ${old} $out
- wrapProgram "$out/bin/hx" ''${makeWrapperArgs[@]} --set HELIX_RUNTIME "${runtimeDir}"
- '';
+ mkRootPath = rel:
+ builtins.path {
+ path = "${toString ./.}/${rel}";
+ name = rel;
+ };
+ filteredSource = let
+ pathsToIgnore = [
+ ".envrc"
+ ".ignore"
+ ".github"
+ ".gitignore"
+ "logo.svg"
+ "logo_dark.svg"
+ "logo_light.svg"
+ "rust-toolchain.toml"
+ "rustfmt.toml"
+ "runtime"
+ "screenshot.png"
+ "book"
+ "contrib"
+ "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;
in
- helix-wrapped
- // {
- override = makeOverridableHelix old;
+ 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 {};
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 ''$RUSTFLAGS -C link-arg=-fuse-ld=lld -C target-cpu=native -Clink-arg=-Wl,--no-rosegment''
- else "$RUSTFLAGS";
- in {
- nci.projects."helix-project".relPath = "";
- nci.crates."helix-term" = {
- overrides = {
- add-meta.override = _: {meta.mainProgram = "hx";};
- 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 "$out/bin/hx" ''${makeWrapperArgs[@]} --set HELIX_RUNTIME "${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 ''$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;
+ 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 = "hx";
+ }
+ // 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."helix-term".packages.release;
- packages.helix-unwrapped-dev = config.nci.outputs."helix-term".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 = "--all-targets -- --deny warnings";
+ });
- devShells.default = config.nci.outputs."helix-project".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="$PWD/runtime"
- 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="$PWD/runtime"
+ export RUST_BACKTRACE="1"
+ export RUSTFLAGS="${rustFlagsEnv}"
+ '';
+ };
+ })
+ // {
+ overlays.default = final: prev: {
+ inherit (self.packages.${final.system}) helix;
};
};