Skip to content

Instantly share code, notes, and snippets.

@superherointj
Created January 23, 2022 12:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save superherointj/b66ac8c2a1302a7e0fb0ed7c4a87215d to your computer and use it in GitHub Desktop.
Save superherointj/b66ac8c2a1302a7e0fb0ed7c4a87215d to your computer and use it in GitHub Desktop.
Nix Demo for Go Project
# IMPORTANT: You have to install `direnv`!
#
# To enable direnv, `.bashrc` (or bash_profile? unsure) should have:
# eval "$(direnv hook bash)"
#
# To enable flake on DirEnv, add to `.config/direnv/lib/use_flake.sh`:
# use_flake() {
# watch_file flake.nix
# watch_file flake.lock
# $(nix print-dev-env --profile "$(direnv_layout_dir)/flake-profile")"
# }
#####################
use flake
# This is also for `nix build`
# Sample of packaging a Go application in Nix.
########
{ lib, buildGoPackage }:
buildGoPackage rec {
pname = "demo1";
version = "1.0.0";
subPackages = [ "." ];
# goPackagePath = "gitlab.com/gitlab-org/gitlab-runner";
# commonPackagePath = "${goPackagePath}/common";
ldflags = [
"-X ${commonPackagePath}.NAME=${pname}"
"-X ${commonPackagePath}.VERSION=${version}"
"-X ${commonPackagePath}.REVISION=v${version}"
];
src = ./.;
# postInstall = ''
# install -d $out/bin/helper-images
# '';
meta = with lib; {
description = "A demo";
license = licenses.mit;
homepage = "";
platforms = platforms.unix ++ platforms.darwin;
maintainers = with maintainers; [ ];
};
}
# This enables `nix build` + other things.
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let pkgs = nixpkgs.legacyPackages.${system};
in rec {
packages.demo1 = pkgs.callPackage ./default.nix { };
defaultPackage = packages.demo1;
devShell = import ./shell.nix { inherit pkgs; };
});
}
# Enables: `nix-shell`
######
{ pkgs ? import <nixpkgs> { } }:
with pkgs;
mkShell {
buildInputs = [
go
gox
gotools
gopls
go-outline
gocode
gopkgs
gocode-gomod
godef
golint
];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment