Jump to content

Gram: Difference between revisions

From Official NixOS Wiki
Smudgebun (talk | contribs)
Installing Extensions: Add troubleshooting steps for possible issues with toolchain installation
Smudgebun (talk | contribs)
m Installing Extensions: corrected link
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
<translate>
[https://gram-editor.com/ Gram] is a hard fork of [[Zed]] removing AI integration and telemetry as well as no user agreement or subscription, among other features. For more on the reasoning for and purpose of the fork see the [https://gram-editor.com/docs/mission/ mission statement]. For general Gram information see [https://gram-editor.com/docs/ the docs].
[https://gram-editor.com/ Gram] is a hard fork of [[Zed]] removing AI integration and telemetry as well as no user agreement or subscription, among other features. For more on the reasoning for and purpose of the fork see the [https://gram-editor.com/docs/mission/ mission statement].


== Installation ==
== Installation ==


Gram is available in <code>nixpkgs</code> as {{nixos:package|gram}}.
Gram is available in <code>nixpkgs</code> as {{nixos:package|gram}}. You can add it to system packages with


== Configuration ==
<syntaxhighlight lang="nix">
environment.systemPackages = with pkgs; [
  gram
];
</syntaxhighlight>
 
== Installing Extensions ==
 
Gram, unlike Zed, builds extensions locally. This makes getting extensions working on NixOS require some configuration. The two main ways are the [[#Adhoc_Method|adhoc method]], or using [[#Nix-Gram-Extensions|nix-gram-extensions]] which currently requires [[Home_Manager|home manager]] or [https://hjem.feel-co.org/ hjem].
 
=== Adhoc Method ===
 
This allows you to use Gram as you'd expect on other distros, able to click Install From URL or Install Local and have Gram compile the extension. This method is definitely more hacky, so if you don't mind managing your extensions with nix, [[#Nix-Gram-Extensions]] is recommended.
 
There are a number of known things needed for Gram to successfully compile extensions itself. Aside from [[#Nix-ld]], which needs to be enabled in your system configuration, everything else can be installed either to system packages, in a devShell, user packages, home manager packages, etc. All examples are primarily for reference, and as such will only demonstrate installation to system packages. If you want to install using any of the previously listed methods, it should hopefully be fairly simple to translate to your method of choosing.
 
The known requirements are the following:
 
* [[#Nix-ld]]
* [[#Clang]]
* [[#Wasm32-Wasip2_Toolchain|#Wasm32-Wasip2 Rust Toolchain]]
* [[#Other_Needed_Packages|#Other Needed Packages]]
 
==== Nix-ld ====
 
[[Nix-ld]] must be enabled on the system. This is because Gram pulls in the [https://github.com/WebAssembly/wasi-sdk wasi-sdk] for portions of the compilation, and the binaries it pulls are made for normal Linux distributions, meaning the linker path they look for doesn't exist without [[Nix-ld]]. Enabling it is as simple as adding the following to your configuration.
 
<syntaxhighlight lang="nix">
{
  programs.nix-ld.enable = true;
}
</syntaxhighlight>


=== Installing Extensions ===
==== Clang ====


Gram, unlike Zed, builds extensions locally. This means it needs a Rust WASI Toolchain and <code>clang</code> available to it while installing them. Currently, the easiest way to do this is using something like [https://github.com/nix-community/fenix nix-community/fenix] (the same should be able to be done with [https://github.com/oxalica/rust-overlay rust-overlay]).
{{nixos:package|clang|Clang}} must be installed and available under the <code>cc</code> alias, which is true as long as the wrapped clang (the ones referred to as {{nixos:package|clang-wrapper}}) is the one installed and it is not being overwritten by {{nixos:package|gcc}}.
 
You can verify if clang is configured correctly in your environment by opening Gram's terminal (<code>ctrl+`</code> or <code>ctrl+shift+p > terminal panel: toggle</code>) and running the following
 
{{Commands|
clang --version
cc --version
}}
 
Both should return with a version of {{nixos:package|clang}}.
 
==== Wasm32-Wasip2 Toolchain ====
 
A valid [https://doc.rust-lang.org/nightly/rustc/platform-support/wasm32-wasip2.html wasm32-wasip2] rust toolchain needs to be installed into your environment. This can be done declaratively with either [https://github.com/nix-community/fenix fenix] or [https://github.com/oxalica/rust-overlay rust-overlay]. Or you can have Gram install the toolchain itself by installing {{nixos:package|rustup}} to your environment. The rustup option is less declarative, but much simpler if that doesn't bother you.
 
If you've installed with fenix or rust-overlay, you can confirm that it's installed correctly by entering Gram's terminal and running
 
{{Commands|
ls $(rustc --print sysroot)/lib/rustlib
}}
 
If in the command's output is a directory named <code>wasm32-wasip2</code>, it should be installed correctly and Gram will be able to detect it. If it's listed as <code>wasm32-unknown-unknown</code>, see [[Gram#Wasm32_Wrong_Target]].
 
===== Rustup =====
 
To configure rustup, just run
 
{{Commands|
rustup default stable
}}
 
As whatever user is using Gram to add the stable toolchain as your default to <code>~/.rustup</code>.
 
===== Fenix =====
 
This example uses the <code>latest</code> branch, but other options are available, just make sure the versions all match across <code>toolchain</code> and <code>target</code> or <code>rustc</code>, <code>cargo</code> and <code>target</code>.


Add <code>fenix</code> to your flake
Add <code>fenix</code> to your flake
</translate>


{{file|flake.nix|nix|
{{file|flake.nix|nix|
Line 28: Line 92:
</nowiki>
</nowiki>
}}
}}
<translate>
The examples all use the stable version attribute set, but others provided by <code>fenix</code> should work.
{{info| Make sure the versions match between <code>${version}.toolchain</code> (or <code>${version}.rustc</code> + <code>${version}.cargo</code>) & <code>targets.wasm32-wasip2.${version}.stable.rust-std</code>
}}
You should be able to copy & paste the <code>let in</code> statement with any of the usage examples below (unless otherwise specified) into a nix module of the appropriate type (<code>homeManager</code>, <code>nixos</code>, <code>devShell</code>). Note that the <code>devShell</code> examples will only work if you launch Gram from in the shell.
==== Let In Statement ====
</translate>


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
{inputs, pkgs, system, ... }:
{inputs, pkgs, system, ... }:
   let
   let
    # full toolchain:
    /*
     extension-toolchain = with inputs.fenix.packages.${system}; combine [
     extension-toolchain = with inputs.fenix.packages.${system}; combine [
      stable.toolchain
# full toolchain (not required):
      targets.wasm32-wasip2.stable.rust-std
    # latest.toolchain
    ];
# minimum required to build:
    */
       latest.rustc
    # minimum required to build:
       latest.cargo
    extension-toolchain = with inputs.fenix.packages.${system}; combine [
# wasm32-wasip2 target (required):
       stable.rustc
       targets.wasm32-wasip2.latest.rust-std
       stable.cargo
       targets.wasm32-wasip2.stable.rust-std
     ];
     ];
   in
   in
</syntaxhighlight>
<translate>
==== HomeManager Packages ====
</translate>
<syntaxhighlight lang="nix">
{
  home.packages = with pkgs; [
    clang
    extension-toolchain
  ];
}
</syntaxhighlight>
<translate>
==== NixOS Packages ====
</translate>
<syntaxhighlight lang="nix">
{
{
   environment.systemPackages = with pkgs; [
   environment.systemPackages = with pkgs; [
Line 85: Line 114:
</syntaxhighlight>
</syntaxhighlight>


==== devShell ====
===== Rust-Overlay =====


<syntaxhighlight lang="nix">
Like the fenix example, this assumes the <code>latest</code> branch, though rust-overlay provides others.
{
  packages = with pkgs; [
    clang
    extension-toolchain
  ];
}
</syntaxhighlight>


<translate>
Add <code>rust-overlay</code> to your flake
==== Flake Parts devShell ====


If using flake parts, devShells need to have their inputs passed to them by <code>perSystem</code> rather than as a top-level attribute. The file paths are only examples and can be replaced to fit the structure of your project.
{{file|flake.nix|nix|
</translate>
 
{{file|default.nix|nix|
<nowiki>
<nowiki>
{ inputs, ... }:
{
{
   perSystem = { config, pkgs, system, flake, ... }: {
   inputs = {
    devShells.gram = pkgs.callPackage nix/shells/default { fenix = inputs.fenix.packages.${system}; };
    fenix = {
      url = "github:nix-community/fenix";
      inputs.nixpkgs.follows = "nixpkgs";
     };
     };
    nixpkgs.url = "nixpkgs/nixos-unstable"; # or any other branch
   };
   };
}
}
Line 114: Line 134:
}}
}}


{{file|nix/shells/default/default.nix|nix|
<syntaxhighlight lang="nix">
<nowiki>
{ inputs, pkgs, ... }:
{ pkgs, fenix, }:
{
let
  nixpkgs.overlays = [ inputs.rust-overlay.overlays.default ];
# 1. full toolchain:
   environment.systemPackages = with pkgs; [
   /*
# full toolchain (not required):
  extension-toolchain = with fenix; combine [
     # (rust-bin.stable.latest.default.override { targets = [ "wasm32-wasip2" ]; })
    stable.toolchain
# minimum required to build:
     targets.wasm32-wasip2.stable.rust-std
    (rust-bin.stable.latest.minimal.override { targets = [ "wasm32-wasip2" ]; })
  ];
  */
# 2. minimum required to build:
  extension-toolchain = with fenix; combine [
    stable.rustc
    stable.cargo
    targets.wasm32-wasip2.stable.rust-std
  ];
in
pkgs.mkShell {
  packages = with pkgs; [
    extension-toolchain
    clang
   ];
   ];
}
}
</nowiki>
}}


==== Troubleshooting Extension Install ====
</syntaxhighlight>
 
==== Other Needed Packages ====
 
* {{nixos:package|git}}
 
=== Nix-Gram-Extensions ===
 
<code>nix-gram-extensions</code> is a project to bring declarative management of Gram extensions to Nix using custom builders and integration with [[Home_Manager|home manager]] and [https://hjem.feel-co.org/ hjem]. It is hosted on [https://codeberg.org/niklaskorz/nix-gram-extensions codeberg] and [https://tangled.org/niklaskorz.eu/nix-gram-extensions tangled]. If you want to install it to your system, it has a detailed section on installation in its [https://codeberg.org/niklaskorz/nix-gram-extensions#installation README]. More information can be found at its [https://discourse.nixos.org/t/gram-extensions-the-nix-way/79024 discourse announcement].
 
=== More About Extensions ===


If you get the error <code>failed to run `rustup target add`: no such file or directory</code>, enter Gram's terminal and run
* [https://discourse.nixos.org/t/fail-to-add-extensions-to-gram/78466 NixOS Discourse: Fail To Add Extensions To Gram]


<syntaxhighlight lang="shell">
== Troubleshooting ==
ls $(rustc --print sysroot)/lib/rustlib
</syntaxhighlight>


If there is no directory named <code>wasm32-wasip2</code>, and there is one named something like <code>wasm32-unknown-unknown</code>, this likely means fenix has installed the target weirdly. On fenix this has been fixable by changing your version, for instance to <code>latest</code>.
=== Extensions ===


<translate>
==== Wasm32 Wrong Target ====
==== More About Extensions ====


* [https://discourse.nixos.org/t/fail-to-add-extensions-to-gram/78466/2 NixOS Discourse: Fail To Add Extensions To Gram]
If the wasm32 target is listed as <code>wasm32-unknown-unknown</code>, Gram will be unable to detect it and if rustup isn't installed it will error with <code>failed to run `rustup target add`: no such file or directory</code>, because when it doesn't detect an installed valid toolchain, it tries to install one with [https://doc.rust-lang.org/stable/book/ch01-01-installation.html?highlight=rustup#installing-rustup-on-linux-or-macos rustup]. This has happened on fenix's stable branch and was fixed by changing to the <code>latest</code> branch.
* [[Talk:Gram#Using_Rustup_for_Building_Extensions]]
</translate>


[[Category:Applications]] [[Category:Text Editor]]
[[Category:Applications]] [[Category:Text Editor]]

Latest revision as of 20:22, 8 August 2026

Gram is a hard fork of Zed removing AI integration and telemetry as well as no user agreement or subscription, among other features. For more on the reasoning for and purpose of the fork see the mission statement. For general Gram information see the docs.

Installation

Gram is available in nixpkgs as gram. You can add it to system packages with

environment.systemPackages = with pkgs; [
  gram
];

Installing Extensions

Gram, unlike Zed, builds extensions locally. This makes getting extensions working on NixOS require some configuration. The two main ways are the adhoc method, or using nix-gram-extensions which currently requires home manager or hjem.

Adhoc Method

This allows you to use Gram as you'd expect on other distros, able to click Install From URL or Install Local and have Gram compile the extension. This method is definitely more hacky, so if you don't mind managing your extensions with nix, #Nix-Gram-Extensions is recommended.

There are a number of known things needed for Gram to successfully compile extensions itself. Aside from #Nix-ld, which needs to be enabled in your system configuration, everything else can be installed either to system packages, in a devShell, user packages, home manager packages, etc. All examples are primarily for reference, and as such will only demonstrate installation to system packages. If you want to install using any of the previously listed methods, it should hopefully be fairly simple to translate to your method of choosing.

The known requirements are the following:

Nix-ld

Nix-ld must be enabled on the system. This is because Gram pulls in the wasi-sdk for portions of the compilation, and the binaries it pulls are made for normal Linux distributions, meaning the linker path they look for doesn't exist without Nix-ld. Enabling it is as simple as adding the following to your configuration.

{
  programs.nix-ld.enable = true;
}

Clang

Clang must be installed and available under the cc alias, which is true as long as the wrapped clang (the ones referred to as clang-wrapper) is the one installed and it is not being overwritten by gcc.

You can verify if clang is configured correctly in your environment by opening Gram's terminal (ctrl+` or ctrl+shift+p > terminal panel: toggle) and running the following

clang --version
cc --version

Both should return with a version of clang.

Wasm32-Wasip2 Toolchain

A valid wasm32-wasip2 rust toolchain needs to be installed into your environment. This can be done declaratively with either fenix or rust-overlay. Or you can have Gram install the toolchain itself by installing rustup to your environment. The rustup option is less declarative, but much simpler if that doesn't bother you.

If you've installed with fenix or rust-overlay, you can confirm that it's installed correctly by entering Gram's terminal and running

ls $(rustc --print sysroot)/lib/rustlib

If in the command's output is a directory named wasm32-wasip2, it should be installed correctly and Gram will be able to detect it. If it's listed as wasm32-unknown-unknown, see Gram#Wasm32_Wrong_Target.

Rustup

To configure rustup, just run

rustup default stable

As whatever user is using Gram to add the stable toolchain as your default to ~/.rustup.

Fenix

This example uses the latest branch, but other options are available, just make sure the versions all match across toolchain and target or rustc, cargo and target.

Add fenix to your flake

❄︎ flake.nix
{
  inputs = {
    fenix = {
      url = "github:nix-community/fenix";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    nixpkgs.url = "nixpkgs/nixos-unstable"; # or any other branch
  };
}
{inputs, pkgs, system, ... }:
  let
    extension-toolchain = with inputs.fenix.packages.${system}; combine [
# full toolchain (not required):
    # latest.toolchain
# minimum required to build:
      latest.rustc
      latest.cargo
# wasm32-wasip2 target (required):
      targets.wasm32-wasip2.latest.rust-std
    ];
  in
{
  environment.systemPackages = with pkgs; [
    clang
    extension-toolchain
  ];
}
Rust-Overlay

Like the fenix example, this assumes the latest branch, though rust-overlay provides others.

Add rust-overlay to your flake

❄︎ flake.nix
{
  inputs = {
    fenix = {
      url = "github:nix-community/fenix";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    nixpkgs.url = "nixpkgs/nixos-unstable"; # or any other branch
  };
}
{ inputs, pkgs, ... }:
{
  nixpkgs.overlays = [ inputs.rust-overlay.overlays.default ];
  environment.systemPackages = with pkgs; [
# full toolchain (not required):
    # (rust-bin.stable.latest.default.override { targets = [ "wasm32-wasip2" ]; })
# minimum required to build:
    (rust-bin.stable.latest.minimal.override { targets = [ "wasm32-wasip2" ]; })
  ];
}

Other Needed Packages

Nix-Gram-Extensions

nix-gram-extensions is a project to bring declarative management of Gram extensions to Nix using custom builders and integration with home manager and hjem. It is hosted on codeberg and tangled. If you want to install it to your system, it has a detailed section on installation in its README. More information can be found at its discourse announcement.

More About Extensions

Troubleshooting

Extensions

Wasm32 Wrong Target

If the wasm32 target is listed as wasm32-unknown-unknown, Gram will be unable to detect it and if rustup isn't installed it will error with failed to run `rustup target add`: no such file or directory, because when it doesn't detect an installed valid toolchain, it tries to install one with rustup. This has happened on fenix's stable branch and was fixed by changing to the latest branch.