fork/helix

git clone https://git.julia.blue/fork/helix

Yusuf Bera Ertanbuild(nix): update flake dependencies, remove deprecated code from flakec3c87741

23.05
5.4 KiB169 linesraw
1{
2  description = "A post-modern text editor.";
3
4  inputs = {
5    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
6    rust-overlay = {
7      url = "github:oxalica/rust-overlay";
8      inputs.nixpkgs.follows = "nixpkgs";
9    };
10    nci = {
11      url = "github:yusdacra/nix-cargo-integration";
12      inputs.nixpkgs.follows = "nixpkgs";
13      inputs.rust-overlay.follows = "rust-overlay";
14    };
15    parts.url = "github:hercules-ci/flake-parts";
16  };
17
18  outputs = inp: let
19    mkRootPath = rel:
20      builtins.path {
21        path = "${toString ./.}/${rel}";
22        name = rel;
23      };
24    filteredSource = let
25      pathsToIgnore = [
26        ".envrc"
27        ".ignore"
28        ".github"
29        ".gitignore"
30        "logo.svg"
31        "logo_dark.svg"
32        "logo_light.svg"
33        "rust-toolchain.toml"
34        "rustfmt.toml"
35        "runtime"
36        "screenshot.png"
37        "book"
38        "contrib"
39        "docs"
40        "README.md"
41        "CHANGELOG.md"
42        "shell.nix"
43        "default.nix"
44        "grammars.nix"
45        "flake.nix"
46        "flake.lock"
47      ];
48      ignorePaths = path: type: let
49        inherit (inp.nixpkgs) lib;
50        # split the nix store path into its components
51        components = lib.splitString "/" path;
52        # drop off the `/nix/hash-source` section from the path
53        relPathComponents = lib.drop 4 components;
54        # reassemble the path components
55        relPath = lib.concatStringsSep "/" relPathComponents;
56      in
57        lib.all (p: ! (lib.hasPrefix p relPath)) pathsToIgnore;
58    in
59      builtins.path {
60        name = "helix-source";
61        path = toString ./.;
62        # filter out unnecessary paths
63        filter = ignorePaths;
64      };
65  in
66    inp.parts.lib.mkFlake {inputs = inp;} {
67      imports = [inp.nci.flakeModule];
68      systems = [
69        "x86_64-linux"
70        "x86_64-darwin"
71        "aarch64-linux"
72        "aarch64-darwin"
73        "i686-linux"
74      ];
75      perSystem = {
76        config,
77        pkgs,
78        lib,
79        ...
80      }: let
81        makeOverridableHelix = old: config: let
82          grammars = pkgs.callPackage ./grammars.nix config;
83          runtimeDir = pkgs.runCommand "helix-runtime" {} ''
84            mkdir -p $out
85            ln -s ${mkRootPath "runtime"}/* $out
86            rm -r $out/grammars
87            ln -s ${grammars} $out/grammars
88          '';
89          helix-wrapped =
90            pkgs.runCommand
91            old.name
92            {
93              inherit (old) pname version;
94              meta = old.meta or {};
95              passthru =
96                (old.passthru or {})
97                // {
98                  unwrapped = old;
99                };
100              nativeBuildInputs = [pkgs.makeWrapper];
101              makeWrapperArgs = config.makeWrapperArgs or [];
102            }
103            ''
104              cp -rs --no-preserve=mode,ownership ${old} $out
105              wrapProgram "$out/bin/hx" ''${makeWrapperArgs[@]} --set HELIX_RUNTIME "${runtimeDir}"
106            '';
107        in
108          helix-wrapped
109          // {
110            override = makeOverridableHelix old;
111            passthru =
112              helix-wrapped.passthru
113              // {
114                wrapper = old: makeOverridableHelix old config;
115              };
116          };
117        stdenv =
118          if pkgs.stdenv.isLinux
119          then pkgs.stdenv
120          else pkgs.clangStdenv;
121        rustFlagsEnv =
122          if stdenv.isLinux
123          then ''$RUSTFLAGS -C link-arg=-fuse-ld=lld -C target-cpu=native -Clink-arg=-Wl,--no-rosegment''
124          else "$RUSTFLAGS";
125      in {
126        nci.projects."helix-project".relPath = "";
127        nci.crates."helix-term" = {
128          overrides = {
129            add-meta.override = _: {meta.mainProgram = "hx";};
130            add-inputs.overrideAttrs = prev: {
131              buildInputs = (prev.buildInputs or []) ++ [stdenv.cc.cc.lib];
132            };
133            disable-grammar-builds = {
134              # disable fetching and building of tree-sitter grammars in the helix-term build.rs
135              HELIX_DISABLE_AUTO_GRAMMAR_BUILD = "1";
136            };
137            disable-tests = {checkPhase = ":";};
138            set-stdenv.override = _: {inherit stdenv;};
139            set-filtered-src.override = _: {src = filteredSource;};
140          };
141        };
142
143        packages.helix-unwrapped = config.nci.outputs."helix-term".packages.release;
144        packages.helix-unwrapped-dev = config.nci.outputs."helix-term".packages.dev;
145        packages.helix = makeOverridableHelix config.packages.helix-unwrapped {};
146        packages.helix-dev = makeOverridableHelix config.packages.helix-unwrapped-dev {};
147        packages.default = config.packages.helix;
148
149        devShells.default = config.nci.outputs."helix-project".devShell.overrideAttrs (old: {
150          nativeBuildInputs =
151            (old.nativeBuildInputs or [])
152            ++ (with pkgs; [lld_13 cargo-flamegraph rust-analyzer])
153            ++ (lib.optional (stdenv.isx86_64 && stdenv.isLinux) pkgs.cargo-tarpaulin)
154            ++ (lib.optional stdenv.isLinux pkgs.lldb)
155            ++ (lib.optional stdenv.isDarwin pkgs.darwin.apple_sdk.frameworks.CoreFoundation);
156          shellHook = ''
157            export HELIX_RUNTIME="$PWD/runtime"
158            export RUST_BACKTRACE="1"
159            export RUSTFLAGS="${rustFlagsEnv}"
160          '';
161        });
162      };
163    };
164
165  nixConfig = {
166    extra-substituters = ["https://helix.cachix.org"];
167    extra-trusted-public-keys = ["helix.cachix.org-1:ejp9KQpR1FBI2onstMQ34yogDm4OgU2ru6lIwPvuCVs="];
168  };
169}