Created
January 23, 2022 12:02
-
-
Save superherointj/b66ac8c2a1302a7e0fb0ed7c4a87215d to your computer and use it in GitHub Desktop.
Nix Demo for Go Project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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; }; | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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