Gram: Difference between revisions

Smudgebun (talk | contribs)
Installing Extensions: Added a See Also section linking to the NixOS Discourse discussion
Tags: Mobile edit Mobile web edit Advanced mobile edit
Smudgebun (talk | contribs)
m Installing Extensions: Minor rephrase
 
(11 intermediate revisions by 2 users not shown)
Line 1: Line 1:
[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].
[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].


== 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 installing extensions on NixOS require some setup. There are multiple ways to handle extensions, in no particular order:
 
* [[#System_Method|System Method]]: if you don't mind modifying your system configuration, requires [[Nix-ld]].
* [[#Nix-Gram-Extensions|Nix-Gram-Extensions]]: if you want to manage extensions with [[Home_Manager|home manager]] or [https://hjem.feel-co.org/ hjem]
* [[#Temp_FHS_Environment|Temp FHS Environment]]: if you don't want to modify your system. Includes full copy-pastable example.
 
=== System 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 a bit hacky, and requires some setup.
 
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 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]]
* [[#Rust_Wasm32-Wasip2|#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>
 
==== Clang ====
 
{{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}}.
 
==== Rust Wasm32-Wasip2 ====
 
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 [[#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
 
{{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|Wasm32 Wrong Target]].
 
===== Rustup =====
 
To configure {{nixos:package|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>.


=== Installing Extensions ===
===== Fenix =====


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]).
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>targets</code> or <code>rustc</code>, <code>cargo</code> and <code>targets</code>.


Add <code>fenix</code> to your flake
Add [https://github.com/nix-community/fenix fenix] to your flake


{{file|flake.nix|nix|
{{file|flake.nix|nix|
Line 26: Line 100:
</nowiki>
</nowiki>
}}
}}
The examples all use the stable version attribute set, but any 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 ====


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


==== NixOS Packages ====
===== Rust-Overlay =====
 
Like the fenix example, this assumes the <code>latest</code> branch, though rust-overlay provides others.
 
Add [https://github.com/oxalica/rust-overlay rust-overlay] to your flake
 
{{file|flake.nix|nix|
<nowiki>
{
  inputs = {
    fenix = {
      url = "github:nix-community/fenix";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    nixpkgs.url = "nixpkgs/nixos-unstable"; # or any other branch
  };
}
</nowiki>
}}


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
{ inputs, pkgs, ... }:
{
{
  nixpkgs.overlays = [ inputs.rust-overlay.overlays.default ];
   environment.systemPackages = with pkgs; [
   environment.systemPackages = with pkgs; [
     clang
# full toolchain (not required):
     extension-toolchain
     # (rust-bin.stable.latest.default.override { targets = [ "wasm32-wasip2" ]; })
# minimum required to build:
     (rust-bin.stable.latest.minimal.override { targets = [ "wasm32-wasip2" ]; })
   ];
   ];
}
}
</syntaxhighlight>
</syntaxhighlight>


==== devShell ====
==== Other Needed Packages ====
 
* {{nixos:package|git}}
 
=== 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|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].


<syntaxhighlight lang="nix">
=== Temp FHS Environment ===
{
  packages = with pkgs; [
    clang
    extension-toolchain
  ];
}
</syntaxhighlight>


==== Flake Parts devShell ====
If you do not want to or cannot enable [[Nix-ld]], you can make a temporary FHS Environment and run Gram in there to build extensions. Provided below are an example <code>flake.nix</code> and <code>shell.nix</code>. Just add these files to a directory, enter it and run <code>nix develop</code>. Then, once you're dropped into the environment's shell, run <code>gram</code> and install your extensions as you would on any other distro. Once they're built, you can run Gram outside of that environment too and they should just work.


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.
And of course, if you prefer [[#Fenix]] or [[#Rustup]], you can modify this example to use them instead of [[#Rust-Overlay]].


{{file|default.nix|nix|
{{file|flake.nix|nix|
<nowiki>
<nowiki>
{ inputs, ... }:
{
{
   perSystem = { config, pkgs, system, flake, ... }: {
   description = "Gram extensions flake";
     devShells.gram = pkgs.callPackage nix/shells/default { fenix = inputs.fenix.packages.${system}; };
 
     };
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
    rust-overlay.url = "github:oxalica/rust-overlay";
  };
 
  outputs = {self, nixpkgs, rust-overlay}:
  let
    systems = nixpkgs.lib.platforms.linux ++ nixpkgs.lib.platforms.darwin;
    forAllSystems = nixpkgs.lib.genAttrs systems;
  in
  {
     devShells = forAllSystems (system:
    let
      overlays = [ (import rust-overlay) ];
      pkgs = import nixpkgs {
        inherit system overlays;
      };
    in
    {
        default = pkgs.callPackage ./shell.nix { };
     });
   };
   };
}
}
Line 104: Line 201:
}}
}}


{{file|nix/shells/default/default.nix|nix|
{{file|shell.nix|nix|
<nowiki>
<nowiki>
{ pkgs, fenix, }:
{ pkgs }:
let
 
# 1. full toolchain:
(pkgs.buildFHSEnv {
   /*
   name = "gram";
  extension-toolchain = with fenix; combine [
   targetPkgs = pkgs: (with pkgs; [
    stable.toolchain
     gram # (not needed if already installed to environment)
    targets.wasm32-wasip2.stable.rust-std
   ];
  */
# 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
     clang
   ];
    (rust-bin.stable.latest.minimal.override { targets = [ "wasm32-wasip2" ]; })
}
    git
   ]);
}).env
</nowiki>
</nowiki>
}}
}}


==== See Also ====
=== More About Extensions ===
 
* [https://discourse.nixos.org/t/fail-to-add-extensions-to-gram/78466 NixOS Discourse: Fail To Add Extensions To Gram]
 
== Troubleshooting ==
 
=== Extensions ===
 
==== Wasm32 Wrong Target ====
 
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.


* [https://discourse.nixos.org/t/fail-to-add-extensions-to-gram/78466/2 NixOS Discourse: Fail To Add Extensions To Gram]
[[Category:Applications]] [[Category:Text Editor]]