on master help sign in
chore(nix): format nix files with alejandra, update deps, minor code refactors (#2683)
commitbb83ea83938b7098cc1c1823c791d3b05dd5399f authorYusuf Bera Ertan <y.bera003.06@protonmail.com> dateMon 6 Jun 2022, 22:24 (4 years ago) parentf0d1c85
4 files changed+149−122
flake.lock+24−41 flake.nix+66−33 grammars.nix+54−42 shell.nix+5−6
flake.lock+24−41
@@ -3,11 +3,11 @@
33 "crane": {
44 "flake": false,
55 "locked": {
6− "lastModified": 1644785799,
7− "narHash": "sha256-VpAJO1L0XeBvtCuNGK4IDKp6ENHIpTrlaZT7yfBCvwo=",
6+ "lastModified": 1654444508,
7+ "narHash": "sha256-4OBvQ4V7jyt7afs6iKUvRzJ1u/9eYnKzVQbeQdiamuY=",
88 "owner": "ipetkov",
99 "repo": "crane",
10− "rev": "fc7a94f841347c88f2cb44217b2a3faa93e2a0b2",
10+ "rev": "db5482bf225acc3160899124a1df5a617cfa27b5",
1111 "type": "github"
1212 },
1313 "original": {
@@ -17,19 +17,13 @@
1717 }
1818 },
1919 "devshell": {
20− "inputs": {
21− "flake-utils": "flake-utils",
22− "nixpkgs": [
23− "nixCargoIntegration",
24− "nixpkgs"
25− ]
26− },
20+ "flake": false,
2721 "locked": {
28− "lastModified": 1652959711,
29− "narHash": "sha256-wpQhlE/NocxlU3jLiMoF1KYHOEFD5MEFJZkyXXVVef8=",
22+ "lastModified": 1653917170,
23+ "narHash": "sha256-FyxOnEE/V4PNEcMU62ikY4FfYPo349MOhMM97HS0XEo=",
3024 "owner": "numtide",
3125 "repo": "devshell",
32− "rev": "a5327cd01e58d2848c73062f2661278ad615748f",
26+ "rev": "fc7a3e3adde9bbcab68af6d1e3c6eb738e296a92",
3327 "type": "github"
3428 },
3529 "original": {
@@ -45,6 +39,10 @@
4539 "nixpkgs"
4640 ],
4741 "crane": "crane",
42+ "devshell": [
43+ "nixCargoIntegration",
44+ "devshell"
45+ ],
4846 "flake-utils-pre-commit": [
4947 "nixCargoIntegration",
5048 "nixpkgs"
@@ -75,11 +73,11 @@
7573 ]
7674 },
7775 "locked": {
78− "lastModified": 1653135531,
79− "narHash": "sha256-pYwJrEQrG8BgeVcI+lveK3KbOBDx9MT28HxV09v+jgI=",
76+ "lastModified": 1654451959,
77+ "narHash": "sha256-yWztC96o8Dw65jDbmNUxV1i61T3uLqvqhC3ziwnB/Fk=",
8078 "owner": "nix-community",
8179 "repo": "dream2nix",
82− "rev": "4b3dfb101fd2fdbe25bd128072f138276aa4bc82",
80+ "rev": "90b353682ef927bd39b59085e0dc6b7454888de7",
8381 "type": "github"
8482 },
8583 "original": {
@@ -89,21 +87,6 @@
8987 }
9088 },
9189 "flake-utils": {
92− "locked": {
93− "lastModified": 1642700792,
94− "narHash": "sha256-XqHrk7hFb+zBvRg6Ghl+AZDq03ov6OshJLiSWOoX5es=",
95− "owner": "numtide",
96− "repo": "flake-utils",
97− "rev": "846b2ae0fc4cc943637d3d1def4454213e203cba",
98− "type": "github"
99− },
100− "original": {
101− "owner": "numtide",
102− "repo": "flake-utils",
103− "type": "github"
104− }
105− },
106− "flake-utils_2": {
10790 "locked": {
10891 "lastModified": 1637014545,
10992 "narHash": "sha256-26IZAc5yzlD9FlDT54io1oqG/bBoyka+FJk5guaX4x4=",
@@ -130,11 +113,11 @@
130113 ]
131114 },
132115 "locked": {
133− "lastModified": 1653286465,
134− "narHash": "sha256-CEI2prA74sy9SgAJKdDpyAMv1nnp91c8e5Fw9QbtR/Q=",
116+ "lastModified": 1654531591,
117+ "narHash": "sha256-DtDAwkl2Pn8w1BW1z2OssT/bWjVhMZQBBpr2uDY7tHY=",
135118 "owner": "yusdacra",
136119 "repo": "nix-cargo-integration",
137− "rev": "95efd76ab68b20aba45b7d647460319b88c2a4c0",
120+ "rev": "c935099d6851d0ff94098e9a12f42147524f0c5b",
138121 "type": "github"
139122 },
140123 "original": {
@@ -145,11 +128,11 @@
145128 },
146129 "nixpkgs": {
147130 "locked": {
148− "lastModified": 1653060744,
149− "narHash": "sha256-kfRusllRumpt33J1hPV+CeCCylCXEU7e0gn2/cIM7cY=",
131+ "lastModified": 1654230545,
132+ "narHash": "sha256-8Vlwf0x8ow6pPOK2a04bT+pxIeRnM1+O0Xv9/CuDzRs=",
150133 "owner": "nixos",
151134 "repo": "nixpkgs",
152− "rev": "dfd82985c273aac6eced03625f454b334daae2e8",
135+ "rev": "236cc2971ac72acd90f0ae3a797f9f83098b17ec",
153136 "type": "github"
154137 },
155138 "original": {
@@ -168,17 +151,17 @@
168151 },
169152 "rust-overlay": {
170153 "inputs": {
171− "flake-utils": "flake-utils_2",
154+ "flake-utils": "flake-utils",
172155 "nixpkgs": [
173156 "nixpkgs"
174157 ]
175158 },
176159 "locked": {
177− "lastModified": 1653273659,
178− "narHash": "sha256-dHXYaNL1axhZZyiZXxt1WKhvZrYXq7bjCs3y5VjgyGI=",
160+ "lastModified": 1654483484,
161+ "narHash": "sha256-Ki/sMgrUEj+31P3YMzZZp5Nea7+MQVVTdaRWQVS1PL4=",
179162 "owner": "oxalica",
180163 "repo": "rust-overlay",
181− "rev": "0fa3e01da1ce98e3b40063b8e2678095943402b1",
164+ "rev": "6bc59b9c4ad1cc1089219e935aa727a96d948c5d",
182165 "type": "github"
183166 },
184167 "original": {
flake.nix+66−33
@@ -14,10 +14,14 @@
1414 };
1515 };
1616
17− outputs = inputs@{ nixCargoIntegration, ... }:
17+ outputs = inputs @ {
18+ nixpkgs,
19+ nixCargoIntegration,
20+ ...
21+ }:
1822 nixCargoIntegration.lib.makeOutputs {
1923 root = ./.;
20− renameOutputs = { "helix-term" = "helix"; };
24+ renameOutputs = {"helix-term" = "helix";};
2125 # Set default app to hx (binary is from helix-term release build)
2226 # Set default package to helix-term release build
2327 defaultOutputs = {
@@ -25,41 +29,70 @@
2529 package = "helix";
2630 };
2731 overrides = {
28− cCompiler = common: if common.pkgs.stdenv.isLinux then common.pkgs.gcc else common.pkgs.clang;
32+ cCompiler = common:
33+ with common.pkgs;
34+ if stdenv.isLinux
35+ then gcc
36+ else clang;
2937 crateOverrides = common: _: {
30− helix-term = prev:
31− let
32− inherit (common) pkgs;
33− grammars = pkgs.callPackage ./grammars.nix { };
34− runtimeDir = pkgs.runCommand "helix-runtime" { } ''
35− mkdir -p $out
36− ln -s ${common.root}/runtime/* $out
37− rm -r $out/grammars
38− ln -s ${grammars} $out/grammars
39− '';
40− in
41− {
42− # disable fetching and building of tree-sitter grammars in the helix-term build.rs
43− HELIX_DISABLE_AUTO_GRAMMAR_BUILD = "1";
44− # link languages and theme toml files since helix-term expects them (for tests)
45− preConfigure = "ln -s ${common.root}/{languages.toml,theme.toml,base16_theme.toml} ..";
46− buildInputs = (prev.buildInputs or [ ]) ++ [ common.cCompiler.cc.lib ];
47− nativeBuildInputs = [ pkgs.makeWrapper ];
38+ helix-term = prev: let
39+ inherit (common) pkgs;
40+ mkRootPath = rel:
41+ builtins.path {
42+ path = "${common.root}/${rel}";
43+ name = rel;
44+ };
45+ grammars = pkgs.callPackage ./grammars.nix {};
46+ runtimeDir = pkgs.runCommandNoCC "helix-runtime" {} ''
47+ mkdir -p $out
48+ ln -s ${mkRootPath "runtime"}/* $out
49+ rm -r $out/grammars
50+ ln -s ${grammars} $out/grammars
51+ '';
52+ in {
53+ # disable fetching and building of tree-sitter grammars in the helix-term build.rs
54+ HELIX_DISABLE_AUTO_GRAMMAR_BUILD = "1";
55+ # link languages and theme toml files since helix-term expects them (for tests)
56+ preConfigure =
57+ pkgs.lib.concatMapStringsSep
58+ "\n"
59+ (path: "ln -sf ${mkRootPath path} ..")
60+ ["languages.toml" "theme.toml" "base16_theme.toml"];
61+ buildInputs = (prev.buildInputs or []) ++ [common.cCompiler.cc.lib];
62+ nativeBuildInputs = [pkgs.makeWrapper];
4863
49− postFixup = ''
50− if [ -f "$out/bin/hx" ]; then
51− wrapProgram "$out/bin/hx" --set HELIX_RUNTIME "${runtimeDir}"
52− fi
53− '';
54− };
64+ postFixup = ''
65+ if [ -f "$out/bin/hx" ]; then
66+ wrapProgram "$out/bin/hx" --set HELIX_RUNTIME "${runtimeDir}"
67+ fi
68+ '';
69+ };
5570 };
5671 shell = common: prev: {
57− packages = prev.packages ++ (with common.pkgs; [ lld_13 lldb cargo-tarpaulin cargo-flamegraph ]);
58− env = prev.env ++ [
59− { name = "HELIX_RUNTIME"; eval = "$PWD/runtime"; }
60− { name = "RUST_BACKTRACE"; value = "1"; }
61− { 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 ""; }
62− ];
72+ packages =
73+ prev.packages
74+ ++ (
75+ with common.pkgs; [lld_13 lldb cargo-tarpaulin cargo-flamegraph]
76+ );
77+ env =
78+ prev.env
79+ ++ [
80+ {
81+ name = "HELIX_RUNTIME";
82+ eval = "$PWD/runtime";
83+ }
84+ {
85+ name = "RUST_BACKTRACE";
86+ value = "1";
87+ }
88+ {
89+ name = "RUSTFLAGS";
90+ value =
91+ if common.pkgs.stdenv.isLinux
92+ then "-C link-arg=-fuse-ld=lld -C target-cpu=native -Clink-arg=-Wl,--no-rosegment"
93+ else "";
94+ }
95+ ];
6396 };
6497 };
6598 };
grammars.nix+54−42
@@ -1,17 +1,23 @@
1−{ stdenv, lib, runCommand, yj }:
2−let
1+{
2+ stdenv,
3+ lib,
4+ runCommandLocal,
5+ runCommandNoCC,
6+ yj,
7+}: let
38 # HACK: nix < 2.6 has a bug in the toml parser, so we convert to JSON
49 # before parsing
5− languages-json = runCommand "languages-toml-to-json" { } ''
10+ languages-json = runCommandLocal "languages-toml-to-json" {} ''
611 ${yj}/bin/yj -t < ${./languages.toml} > $out
712 '';
8− languagesConfig = if lib.versionAtLeast builtins.nixVersion "2.6.0" then
9− builtins.fromTOML (builtins.readFile ./languages.toml)
10− else
11− builtins.fromJSON (builtins.readFile (builtins.toPath languages-json));
12− isGitGrammar = (grammar:
13− builtins.hasAttr "source" grammar && builtins.hasAttr "git" grammar.source
14− && builtins.hasAttr "rev" grammar.source);
13+ languagesConfig =
14+ if lib.versionAtLeast builtins.nixVersion "2.6.0"
15+ then builtins.fromTOML (builtins.readFile ./languages.toml)
16+ else builtins.fromJSON (builtins.readFile (builtins.toPath languages-json));
17+ isGitGrammar = grammar:
18+ builtins.hasAttr "source" grammar
19+ && builtins.hasAttr "git" grammar.source
20+ && builtins.hasAttr "rev" grammar.source;
1521 isGitHubGrammar = grammar: lib.hasPrefix "https://github.com" grammar.source.git;
1622 toGitHubFetcher = url: let
1723 match = builtins.match "https://github\.com/([^/]*)/([^/]*)/?" url;
@@ -20,33 +26,36 @@ let
2026 repo = builtins.elemAt match 1;
2127 };
2228 gitGrammars = builtins.filter isGitGrammar languagesConfig.grammar;
23− buildGrammar = grammar:
24− let
25− gh = toGitHubFetcher grammar.source.git;
26− sourceGit = builtins.fetchTree {
27− type = "git";
28− url = grammar.source.git;
29− rev = grammar.source.rev;
30− ref = grammar.source.ref or "HEAD";
31− shallow = true;
32− };
33− sourceGitHub = builtins.fetchTree {
34− type = "github";
35− owner = gh.owner;
36− repo = gh.repo;
37− inherit (grammar.source) rev;
38− };
39− source = if isGitHubGrammar grammar then sourceGitHub else sourceGit;
40− in stdenv.mkDerivation rec {
29+ buildGrammar = grammar: let
30+ gh = toGitHubFetcher grammar.source.git;
31+ sourceGit = builtins.fetchTree {
32+ type = "git";
33+ url = grammar.source.git;
34+ rev = grammar.source.rev;
35+ ref = grammar.source.ref or "HEAD";
36+ shallow = true;
37+ };
38+ sourceGitHub = builtins.fetchTree {
39+ type = "github";
40+ owner = gh.owner;
41+ repo = gh.repo;
42+ inherit (grammar.source) rev;
43+ };
44+ source =
45+ if isGitHubGrammar grammar
46+ then sourceGitHub
47+ else sourceGit;
48+ in
49+ stdenv.mkDerivation rec {
4150 # see https://github.com/NixOS/nixpkgs/blob/fbdd1a7c0bc29af5325e0d7dd70e804a972eb465/pkgs/development/tools/parsing/tree-sitter/grammar.nix
4251
4352 pname = "helix-tree-sitter-${grammar.name}";
4453 version = grammar.source.rev;
4554
46− src = if builtins.hasAttr "subpath" grammar.source then
47− "${source}/${grammar.source.subpath}"
48− else
49− source;
55+ src =
56+ if builtins.hasAttr "subpath" grammar.source
57+ then "${source}/${grammar.source.subpath}"
58+ else source;
5059
5160 dontUnpack = true;
5261 dontConfigure = true;
@@ -93,14 +102,17 @@ let
93102 runHook postFixup
94103 '';
95104 };
96− builtGrammars = builtins.map (grammar: {
97− inherit (grammar) name;
98− artifact = buildGrammar grammar;
99− }) gitGrammars;
100− grammarLinks = builtins.map (grammar:
101− "ln -s ${grammar.artifact}/${grammar.name}.so $out/${grammar.name}.so")
105+ builtGrammars =
106+ builtins.map (grammar: {
107+ inherit (grammar) name;
108+ artifact = buildGrammar grammar;
109+ })
110+ gitGrammars;
111+ grammarLinks =
112+ builtins.map (grammar: "ln -s ${grammar.artifact}/${grammar.name}.so $out/${grammar.name}.so")
102113 builtGrammars;
103−in runCommand "consolidated-helix-grammars" { } ''
104− mkdir -p $out
105− ${builtins.concatStringsSep "\n" grammarLinks}
106−''
114+in
115+ runCommandNoCC "consolidated-helix-grammars" {} ''
116+ mkdir -p $out
117+ ${builtins.concatStringsSep "\n" grammarLinks}
118+ ''
shell.nix+5−6
@@ -1,9 +1,8 @@
11# Flake's devShell for non-flake-enabled nix instances
22let
3− compat =
4− builtins.fetchGit {
5− url = "https://github.com/edolstra/flake-compat.git";
6− rev = "b4a34015c698c7793d592d66adbab377907a2be8";
7− };
3+ compat = builtins.fetchGit {
4+ url = "https://github.com/edolstra/flake-compat.git";
5+ rev = "b4a34015c698c7793d592d66adbab377907a2be8";
6+ };
87in
9−(import compat { src = ./.; }).shellNix.default
8+ (import compat {src = ./.;}).shellNix.default