Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,56 @@ $ go build -o ~/go/bin/snippets-ls main.go

Don't forget to append `~/go/bin` to your `$PATH`.

### Install via [nix flake](https://nixos.wiki/wiki/Flakes) with [home-manager](https://nix-community.github.io/home-manager/index.html#ch-nix-flakes)

Include the following in the `inputs` of `flake.nix` for `home-manager`:
```nix
inputs = {
# load compatible nixpkgs and home-mananger repos; they need not be 23.05
nixpkgs = { url = "github:nixos/nixpkgs/nixos-23.05"; };
home-manager = {
url = "github:nix-community/home-manager/release-23.05";
inputs.nixpkgs.follows = "nixpkgs";
};
# ...
snippets-ls = {
url = "github:quantonganh/snippets-ls";
inputs.nixpkgs.follows = "nixpkgs";
};
};
```
There are in turn many suitable ways to configure the `outputs` of `flake.nix`. One option is to use an overlay with something like
```nix
outputs = inputs:
with inputs;
let
system = "x86_64-linux"; # or other system as applicable (such as "x86_64-darwin")
pkgs = import nixpkgs {
inherit system;
overlays = [ pkgs_overlay ];
};
# ...
pkgs_overlay = final: prev: {
# ...
external.snippets-ls = snippets-ls.packages.${prev.system}.snippets-ls;
};
in {
homeConfigurations.YOUR-USER-NAME-HERE = home-manager.lib.homeManagerConfiguration {
inherit pkgs;
modules = [ ./home.nix ];
};
};
};
```
The use of this overlay allows you to call this packages with `pkgs.external.snippets-ls`, such the list of packages in `home.nix` can look something like
```nix
home.packages = with pkgs; [
# ...
external.snippets-ls
];
```


## Usage

Create your own snippets follow [VSCode syntax](https://code.visualstudio.com/docs/editor/userdefinedsnippets#_create-your-own-snippets). Alternatively, you can make use of [pre-existing](https://github.com/microsoft/vscode-go/blob/master/snippets/go.json) [sample](https://github.com/rust-lang/vscode-rust/blob/master/snippets/rust.json) for various programming languages.
Expand Down
25 changes: 9 additions & 16 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,40 +1,36 @@
{
description = "Snippet LSP for helix";

# Nixpkgs / NixOS version to use.
# nixpkgs version to use
inputs.nixpkgs.url = "nixpkgs/nixos-21.11";

outputs = { self, nixpkgs }:
let

# to work with older version of flakes
# work with older version of flakes
lastModifiedDate =
self.lastModifiedDate or self.lastModified or "19700101";

# Generate a user-friendly version number.
# user-friendly version number
version = builtins.substring 0 8 lastModifiedDate;

# System types to support.
# system types to support
supportedSystems =
[ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ];

# Helper function to generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'.
# helper function to generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;

# Nixpkgs instantiated for supported system types.
# nixpkgs instantiated for supported system types
nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; });

in {

# Provide some binary packages for selected system types.
# provide some binary packages for selected system types
packages = forAllSystems (system:
let pkgs = nixpkgsFor.${system};
in {
snippets-ls = pkgs.buildGoModule {
pname = "snippets-ls";
inherit version;
# In 'nix develop', we don't need a copy of the source tree
# in the Nix store.
src = ./.;

# This hash locks the dependencies of this package. It is
Expand All @@ -46,15 +42,15 @@
# To begin with it is recommended to set this, but one must
# remeber to bump this hash when your dependencies change.
#vendorSha256 = pkgs.lib.fakeSha256;

vendorSha256 =
"sha256-zH8N6Bw1I+bFxBiXQtRL/Y2UyE4ix/kdlEsEuwPSZXs=";

# rename binary from go-lsp to snippets-ls
postInstall = "mv $out/bin/go-lsp $out/bin/snippets-ls";
};
});

# Add dependencies that are only needed for development
# add dependencies that are only needed for development
devShells = forAllSystems (system:
let pkgs = nixpkgsFor.${system};
in {
Expand All @@ -63,9 +59,6 @@
};
});

# The default package for 'nix build'. This makes sense if the
# flake provides only one package or there is a clear "main"
# package.
defaultPackage =
forAllSystems (system: self.packages.${system}.snippets-ls);
};
Expand Down