From adedcbfd972b6a9bc8f638aa013494bf570a9765 Mon Sep 17 00:00:00 2001 From: "Michael A. Perlin" Date: Thu, 28 Sep 2023 02:05:59 -0500 Subject: [PATCH 1/3] nit flake cleanup and readme update --- README.md | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 25 +++++++++---------------- 2 files changed, 60 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 34f5266..0dfe9b4 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,57 @@ $ 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 some other system + 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. diff --git a/flake.nix b/flake.nix index 8e1fd51..9758ccb 100644 --- a/flake.nix +++ b/flake.nix @@ -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 @@ -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 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 { @@ -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); }; From 9e4d1648cc210bce5e1b15829fea1cee454101f0 Mon Sep 17 00:00:00 2001 From: "Michael A. Perlin" Date: Thu, 28 Sep 2023 02:10:59 -0500 Subject: [PATCH 2/3] nit cleanup --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 0dfe9b4..8fce933 100644 --- a/README.md +++ b/README.md @@ -48,7 +48,7 @@ There are in turn many suitable ways to configure the `outputs` of `flake.nix`. outputs = inputs: with inputs; let - system = "x86_64-linux"; # or some other system + system = "x86_64-linux"; # or other system as applicable (such as "x86_64-darwin") pkgs = import nixpkgs { inherit system; overlays = [ pkgs_overlay ]; @@ -58,7 +58,6 @@ outputs = inputs: # ... external.snippets-ls = snippets-ls.packages.${prev.system}.snippets-ls; }; - in { homeConfigurations.YOUR-USER-NAME-HERE = home-manager.lib.homeManagerConfiguration { inherit pkgs; From 53152d340df6801fc93a212891584207f70a6823 Mon Sep 17 00:00:00 2001 From: "Michael A. Perlin" Date: Thu, 28 Sep 2023 02:12:48 -0500 Subject: [PATCH 3/3] minor comment change --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 9758ccb..bd9bf9a 100644 --- a/flake.nix +++ b/flake.nix @@ -45,7 +45,7 @@ vendorSha256 = "sha256-zH8N6Bw1I+bFxBiXQtRL/Y2UyE4ix/kdlEsEuwPSZXs="; - # rename go-lsp to snippets-ls + # rename binary from go-lsp to snippets-ls postInstall = "mv $out/bin/go-lsp $out/bin/snippets-ls"; }; });