diff options
author | Yusuf Bera Ertan | 2022-06-06 19:24:52 +0000 |
---|---|---|
committer | GitHub | 2022-06-06 19:24:52 +0000 |
commit | bb83ea83938b7098cc1c1823c791d3b05dd5399f (patch) | |
tree | c084d46a8d7e8951ceed0f763f8b7deb29144cf3 | |
parent | f0d1c855539cfeb8e66c3602a971857f8c20be0f (diff) |
chore(nix): format nix files with alejandra, update deps, minor code refactors (#2683)
-rw-r--r-- | flake.lock | 65 | ||||
-rw-r--r-- | flake.nix | 99 | ||||
-rw-r--r-- | grammars.nix | 96 | ||||
-rw-r--r-- | shell.nix | 11 |
4 files changed, 149 insertions, 122 deletions
@@ -3,11 +3,11 @@ "crane": { "flake": false, "locked": { - "lastModified": 1644785799, - "narHash": "sha256-VpAJO1L0XeBvtCuNGK4IDKp6ENHIpTrlaZT7yfBCvwo=", + "lastModified": 1654444508, + "narHash": "sha256-4OBvQ4V7jyt7afs6iKUvRzJ1u/9eYnKzVQbeQdiamuY=", "owner": "ipetkov", "repo": "crane", - "rev": "fc7a94f841347c88f2cb44217b2a3faa93e2a0b2", + "rev": "db5482bf225acc3160899124a1df5a617cfa27b5", "type": "github" }, "original": { @@ -17,19 +17,13 @@ } }, "devshell": { - "inputs": { - "flake-utils": "flake-utils", - "nixpkgs": [ - "nixCargoIntegration", - "nixpkgs" - ] - }, + "flake": false, "locked": { - "lastModified": 1652959711, - "narHash": "sha256-wpQhlE/NocxlU3jLiMoF1KYHOEFD5MEFJZkyXXVVef8=", + "lastModified": 1653917170, + "narHash": "sha256-FyxOnEE/V4PNEcMU62ikY4FfYPo349MOhMM97HS0XEo=", "owner": "numtide", "repo": "devshell", - "rev": "a5327cd01e58d2848c73062f2661278ad615748f", + "rev": "fc7a3e3adde9bbcab68af6d1e3c6eb738e296a92", "type": "github" }, "original": { @@ -45,6 +39,10 @@ "nixpkgs" ], "crane": "crane", + "devshell": [ + "nixCargoIntegration", + "devshell" + ], "flake-utils-pre-commit": [ "nixCargoIntegration", "nixpkgs" @@ -75,11 +73,11 @@ ] }, "locked": { - "lastModified": 1653135531, - "narHash": "sha256-pYwJrEQrG8BgeVcI+lveK3KbOBDx9MT28HxV09v+jgI=", + "lastModified": 1654451959, + "narHash": "sha256-yWztC96o8Dw65jDbmNUxV1i61T3uLqvqhC3ziwnB/Fk=", "owner": "nix-community", "repo": "dream2nix", - "rev": "4b3dfb101fd2fdbe25bd128072f138276aa4bc82", + "rev": "90b353682ef927bd39b59085e0dc6b7454888de7", "type": "github" }, "original": { @@ -90,21 +88,6 @@ }, "flake-utils": { "locked": { - "lastModified": 1642700792, - "narHash": "sha256-XqHrk7hFb+zBvRg6Ghl+AZDq03ov6OshJLiSWOoX5es=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "846b2ae0fc4cc943637d3d1def4454213e203cba", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "flake-utils_2": { - "locked": { "lastModified": 1637014545, "narHash": "sha256-26IZAc5yzlD9FlDT54io1oqG/bBoyka+FJk5guaX4x4=", "owner": "numtide", @@ -130,11 +113,11 @@ ] }, "locked": { - "lastModified": 1653286465, - "narHash": "sha256-CEI2prA74sy9SgAJKdDpyAMv1nnp91c8e5Fw9QbtR/Q=", + "lastModified": 1654531591, + "narHash": "sha256-DtDAwkl2Pn8w1BW1z2OssT/bWjVhMZQBBpr2uDY7tHY=", "owner": "yusdacra", "repo": "nix-cargo-integration", - "rev": "95efd76ab68b20aba45b7d647460319b88c2a4c0", + "rev": "c935099d6851d0ff94098e9a12f42147524f0c5b", "type": "github" }, "original": { @@ -145,11 +128,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1653060744, - "narHash": "sha256-kfRusllRumpt33J1hPV+CeCCylCXEU7e0gn2/cIM7cY=", + "lastModified": 1654230545, + "narHash": "sha256-8Vlwf0x8ow6pPOK2a04bT+pxIeRnM1+O0Xv9/CuDzRs=", "owner": "nixos", "repo": "nixpkgs", - "rev": "dfd82985c273aac6eced03625f454b334daae2e8", + "rev": "236cc2971ac72acd90f0ae3a797f9f83098b17ec", "type": "github" }, "original": { @@ -168,17 +151,17 @@ }, "rust-overlay": { "inputs": { - "flake-utils": "flake-utils_2", + "flake-utils": "flake-utils", "nixpkgs": [ "nixpkgs" ] }, "locked": { - "lastModified": 1653273659, - "narHash": "sha256-dHXYaNL1axhZZyiZXxt1WKhvZrYXq7bjCs3y5VjgyGI=", + "lastModified": 1654483484, + "narHash": "sha256-Ki/sMgrUEj+31P3YMzZZp5Nea7+MQVVTdaRWQVS1PL4=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "0fa3e01da1ce98e3b40063b8e2678095943402b1", + "rev": "6bc59b9c4ad1cc1089219e935aa727a96d948c5d", "type": "github" }, "original": { @@ -14,10 +14,14 @@ }; }; - outputs = inputs@{ nixCargoIntegration, ... }: + outputs = inputs @ { + nixpkgs, + nixCargoIntegration, + ... + }: nixCargoIntegration.lib.makeOutputs { root = ./.; - renameOutputs = { "helix-term" = "helix"; }; + renameOutputs = {"helix-term" = "helix";}; # Set default app to hx (binary is from helix-term release build) # Set default package to helix-term release build defaultOutputs = { @@ -25,41 +29,70 @@ package = "helix"; }; overrides = { - cCompiler = common: if common.pkgs.stdenv.isLinux then common.pkgs.gcc else common.pkgs.clang; + cCompiler = common: + with common.pkgs; + if stdenv.isLinux + then gcc + else clang; crateOverrides = common: _: { - helix-term = prev: - let - inherit (common) pkgs; - grammars = pkgs.callPackage ./grammars.nix { }; - runtimeDir = pkgs.runCommand "helix-runtime" { } '' - mkdir -p $out - ln -s ${common.root}/runtime/* $out - rm -r $out/grammars - ln -s ${grammars} $out/grammars - ''; - in - { - # disable fetching and building of tree-sitter grammars in the helix-term build.rs - HELIX_DISABLE_AUTO_GRAMMAR_BUILD = "1"; - # link languages and theme toml files since helix-term expects them (for tests) - preConfigure = "ln -s ${common.root}/{languages.toml,theme.toml,base16_theme.toml} .."; - buildInputs = (prev.buildInputs or [ ]) ++ [ common.cCompiler.cc.lib ]; - nativeBuildInputs = [ pkgs.makeWrapper ]; + helix-term = prev: let + inherit (common) pkgs; + mkRootPath = rel: + builtins.path { + path = "${common.root}/${rel}"; + name = rel; + }; + grammars = pkgs.callPackage ./grammars.nix {}; + runtimeDir = pkgs.runCommandNoCC "helix-runtime" {} '' + mkdir -p $out + ln -s ${mkRootPath "runtime"}/* $out + rm -r $out/grammars + ln -s ${grammars} $out/grammars + ''; + in { + # disable fetching and building of tree-sitter grammars in the helix-term build.rs + HELIX_DISABLE_AUTO_GRAMMAR_BUILD = "1"; + # link languages and theme toml files since helix-term expects them (for tests) + preConfigure = + pkgs.lib.concatMapStringsSep + "\n" + (path: "ln -sf ${mkRootPath path} ..") + ["languages.toml" "theme.toml" "base16_theme.toml"]; + buildInputs = (prev.buildInputs or []) ++ [common.cCompiler.cc.lib]; + nativeBuildInputs = [pkgs.makeWrapper]; - postFixup = '' - if [ -f "$out/bin/hx" ]; then - wrapProgram "$out/bin/hx" --set HELIX_RUNTIME "${runtimeDir}" - fi - ''; - }; + postFixup = '' + if [ -f "$out/bin/hx" ]; then + wrapProgram "$out/bin/hx" --set HELIX_RUNTIME "${runtimeDir}" + fi + ''; + }; }; shell = common: prev: { - packages = prev.packages ++ (with common.pkgs; [ lld_13 lldb cargo-tarpaulin cargo-flamegraph ]); - env = prev.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 ""; } - ]; + packages = + prev.packages + ++ ( + with common.pkgs; [lld_13 lldb cargo-tarpaulin cargo-flamegraph] + ); + env = + prev.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 ""; + } + ]; }; }; }; diff --git a/grammars.nix b/grammars.nix index ada14aaf..2f50662e 100644 --- a/grammars.nix +++ b/grammars.nix @@ -1,17 +1,23 @@ -{ stdenv, lib, runCommand, yj }: -let +{ + stdenv, + lib, + runCommandLocal, + runCommandNoCC, + yj, +}: let # HACK: nix < 2.6 has a bug in the toml parser, so we convert to JSON # before parsing - languages-json = runCommand "languages-toml-to-json" { } '' + languages-json = runCommandLocal "languages-toml-to-json" {} '' ${yj}/bin/yj -t < ${./languages.toml} > $out ''; - languagesConfig = if lib.versionAtLeast builtins.nixVersion "2.6.0" then - builtins.fromTOML (builtins.readFile ./languages.toml) - else - builtins.fromJSON (builtins.readFile (builtins.toPath languages-json)); - isGitGrammar = (grammar: - builtins.hasAttr "source" grammar && builtins.hasAttr "git" grammar.source - && builtins.hasAttr "rev" grammar.source); + languagesConfig = + if lib.versionAtLeast builtins.nixVersion "2.6.0" + then builtins.fromTOML (builtins.readFile ./languages.toml) + else builtins.fromJSON (builtins.readFile (builtins.toPath languages-json)); + isGitGrammar = grammar: + builtins.hasAttr "source" grammar + && builtins.hasAttr "git" grammar.source + && builtins.hasAttr "rev" grammar.source; isGitHubGrammar = grammar: lib.hasPrefix "https://github.com" grammar.source.git; toGitHubFetcher = url: let match = builtins.match "https://github\.com/([^/]*)/([^/]*)/?" url; @@ -20,33 +26,36 @@ let repo = builtins.elemAt match 1; }; gitGrammars = builtins.filter isGitGrammar languagesConfig.grammar; - buildGrammar = grammar: - let - gh = toGitHubFetcher grammar.source.git; - sourceGit = builtins.fetchTree { - type = "git"; - url = grammar.source.git; - rev = grammar.source.rev; - ref = grammar.source.ref or "HEAD"; - shallow = true; - }; - sourceGitHub = builtins.fetchTree { - type = "github"; - owner = gh.owner; - repo = gh.repo; - inherit (grammar.source) rev; - }; - source = if isGitHubGrammar grammar then sourceGitHub else sourceGit; - in stdenv.mkDerivation rec { + buildGrammar = grammar: let + gh = toGitHubFetcher grammar.source.git; + sourceGit = builtins.fetchTree { + type = "git"; + url = grammar.source.git; + rev = grammar.source.rev; + ref = grammar.source.ref or "HEAD"; + shallow = true; + }; + sourceGitHub = builtins.fetchTree { + type = "github"; + owner = gh.owner; + repo = gh.repo; + inherit (grammar.source) rev; + }; + source = + if isGitHubGrammar grammar + then sourceGitHub + else sourceGit; + in + stdenv.mkDerivation rec { # see https://github.com/NixOS/nixpkgs/blob/fbdd1a7c0bc29af5325e0d7dd70e804a972eb465/pkgs/development/tools/parsing/tree-sitter/grammar.nix pname = "helix-tree-sitter-${grammar.name}"; version = grammar.source.rev; - src = if builtins.hasAttr "subpath" grammar.source then - "${source}/${grammar.source.subpath}" - else - source; + src = + if builtins.hasAttr "subpath" grammar.source + then "${source}/${grammar.source.subpath}" + else source; dontUnpack = true; dontConfigure = true; @@ -93,14 +102,17 @@ let runHook postFixup ''; }; - builtGrammars = builtins.map (grammar: { - inherit (grammar) name; - artifact = buildGrammar grammar; - }) gitGrammars; - grammarLinks = builtins.map (grammar: - "ln -s ${grammar.artifact}/${grammar.name}.so $out/${grammar.name}.so") + builtGrammars = + builtins.map (grammar: { + inherit (grammar) name; + artifact = buildGrammar grammar; + }) + gitGrammars; + grammarLinks = + builtins.map (grammar: "ln -s ${grammar.artifact}/${grammar.name}.so $out/${grammar.name}.so") builtGrammars; -in runCommand "consolidated-helix-grammars" { } '' - mkdir -p $out - ${builtins.concatStringsSep "\n" grammarLinks} -'' +in + runCommandNoCC "consolidated-helix-grammars" {} '' + mkdir -p $out + ${builtins.concatStringsSep "\n" grammarLinks} + '' @@ -1,9 +1,8 @@ # Flake's devShell for non-flake-enabled nix instances let - compat = - builtins.fetchGit { - url = "https://github.com/edolstra/flake-compat.git"; - rev = "b4a34015c698c7793d592d66adbab377907a2be8"; - }; + compat = builtins.fetchGit { + url = "https://github.com/edolstra/flake-compat.git"; + rev = "b4a34015c698c7793d592d66adbab377907a2be8"; + }; in -(import compat { src = ./.; }).shellNix.default + (import compat {src = ./.;}).shellNix.default |