Download go modules Nix OS - go

I'm downloading a program from github and trying to build it. The program is written in go and uses external modules. After running the nix script, I get an error suggesting that I use the go get command. How can I get modules from a nix script?
My nix script:
buildGoModule rec{
name = "HH";
src = fetchGit{
url = "git#github.com:q/q.git";
};
vendorSha256 = "";
}
Error:
hh imports
github.com/google/uuid: no required module provides package github.com/google/uuid; to add it:
go get github.com/google/uuid

Related

Trouble with go get install for mcumgr

I am trying to install MCUMgr on MACos. Here is a link for mcumgr: https://docs.zephyrproject.org/latest/services/device_mgmt/mcumgr.html
I install the Go Programming Language and enter this command:
go install github.com/apache/mynewt-mcumgr-cli/mcumgr#latest
Upon doing this I get the following error:
go/pkg/mod/golang.org/x/sys#v0.0.0-20200223170610-d5e6a3e2c0ae/unix/zsyscall_darwin_amd64.go:28:3: //go:linkname must refer to declared function or variable
I then googled and found the following from stackoverflow: Go 1.18 build error on Mac: "unix/syscall_darwin.1_13.go:25:3: //go:linkname must refer to declared function or variable"
This gives me the following error:
go: golang.org/x/sys: unrecognized import path "golang.org/x": parse https://golang.org/x?go-get=1: no go-import meta tags ()
I am stuck right now on how to install MCUMgr for MACos and wondering if someone has previously had the same issues?
I used go 1.17 instead and used:
go get github.com/apache/mynewt-mcumgr-cli/mcumgr
Then into the bin folder where it is installed use sudo ./mcumgr to run.

install ctan package ragged2e for latex on nixos

tldr: I need to know how to install the ragged2e package on nixos.
I have a latex project that uses the package ragged2e (here it is on ctan). More concrete, it contains the line \usepackage{ragged2e}. I want to build this project on my nixos machine.
I am very new to nix and nixos. I did read the texlive section of the nixos manual (although I didn't understand the last part about "custom packages").
My nixos config contains the following line:
environment.systemPackages = with pkgs; [
# ... some other packages
texlive.combine {
inherit (texlive) scheme-basic latexmk etoolbox babel-german;
}
];
Unfortunatelly the package ragged2e doesn't seem to be available on nixos: The following doesn't provide any results:
$ nix repl
nix-repl> :l <nixpkgs>
nix-repl> texlive.ragged<TAB>
So now I don't know how to install the ragged2e package.

Protobuf timestamp not found

Relatively new to GRPC and getting an error in my proto file that I cannot seem to make sense of. I would like to send a time in a message using the "google.protobuf.Timestamp". I cannot seem to import it. What am I doing wrong?
syntax = "proto3";
import "google/protobuf/timestamp.proto";
service ProfileService {
rpc ConstructProfileStructFromUser (ConstructProfileStructFromUserRequest) returns (ConstructProfileStructFromUserResponse);
}
message ConstructProfileStructFromUserRequest {
string transactionID = 1;
string User = 2;
}
message ConstructProfileStructFromUserResponse {
string UID = 1;
string ContactEmail = 2;
google.protobuf.Timestamp DateOfBirth = 3;
}
Both in my IDE and my compiler (using the below command) then I get the error
google/protobuf/timestamp.proto: File not found.
profile.proto: Import "google/protobuf/timestamp.proto" was not found or had errors.
profile.proto:21:5: "google.protobuf.Timestamp" is not defined.
Command to run:
protoc -I profile/ profile/profile.proto --go_out=plugins=grpc:profile
Protoc --version
libprotoc 3.0.0
I had this issue after installing the protoc compiler using the apt package manager (Ubuntu) and it put the protoc compiler somewhere like /usr/local/bin.
It seems by default protoc expects imports to be present in an include path relative to the protoc installation directory. For example:
protoc location: /usr/local/bin/protoc
include location: /usr/local/bin/include/*
Install pre-compiled binaries (any OS)
Downloading a pre-compiled binary as indicated below will have the needed include directory.
Instructions from grpc.io/docs/protoc-installation
Manually download from github.com/google/protobuf/releases the zip file corresponding to your operating system and computer architecture (protoc--.zip), or fetch the file using commands such as the following:
PB_REL="https://github.com/protocolbuffers/protobuf/releases"
curl -LO $PB_REL/download/v3.15.8/protoc-3.15.8-linux-x86_64.zip
Unzip the file under $HOME/.local or a directory of your choice. For example:
unzip protoc-3.15.8-linux-x86_64.zip -d $HOME/.local
Update your environment’s path variable to include the path to the protoc executable. For example:
export PATH="$PATH:$HOME/.local/bin"
If you installed protoc with your package manager, you only have to install the libprotobuf-dev (Ubuntu) or protobuf-devel (Fedora) package.
In general, you can find the containing package of a file on Ubuntu with
apt-file find google/protobuf/timestamp.proto
or on Fedora
dnf repoquery --file "**/google/protobuf/timestamp.proto" (this is how I found the package I needed). Other package managers probably have similar commands.
My problem was quite simple...
I didn't have the timestamp.proto downloaded locally and as a result it couldn't find it.
I cloned:
https://github.com/protocolbuffers/protobuf/tree/master/src/google/protobuf
And then when I run my compiler I have to give it the location to locate the timestamp.proto files.
For me it was...
protoc -I profile/ -I MY_CLONED_REPO_LOCATION/protobuf/src profile/profile.proto --go_out=plugins=grpc:profile
Once it knew where it had the path to the source then it could find it with no issues.
I had same problem with protoc 3.0.0 installed from ubuntu repo. I have found another solution, without reinstalling protobuf as #SwiftD suggested, using --proto_path protoc option.
In your .proto import should look like (i.e. without path):
syntax = "proto3";
import "timestamp.proto"
Then in the protoc invocation you pass absolute path to your package directory containing timestamp.proto (I use github.com/golang/protobuf/ptypes/timestamp) using --proto_path option.
protoc kcproto.proto --go_out=./ --proto_path=/home/my_home_dir_name/go/src/github.com/golang/protobuf/ptypes/timestamp --proto_path=./
replace /home/my_home_dir_name/ with your go package directory
For mac, I run this in the terminal
PROTOC_ZIP=protoc-3.14.0-osx-x86_64.zip
curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v3.14.0/$PROTOC_ZIP
sudo unzip -o $PROTOC_ZIP -d /usr/local bin/protoc
sudo unzip -o $PROTOC_ZIP -d /usr/local 'include/*'
rm -f $PROTOC_ZIP
Note that you can change the version protoc-3.14.0 to whatever your need, for example protoc-3.x.x
Docs: http://google.github.io/proto-lens/installing-protoc.html
If you download from https://github.com/protocolbuffers/protobuf/releases, in the download directory there is an include directory, where all the google defined types (such as google/protobuf/timestamp.proto) live.
You can pass in an extra parameter --proto_path=/path/to/include to your protoc command, and it should work.
Go to the VSCode proto 3 extension settings and paste "protocol" at the end of the file:
"protoc": {
"options": [
"--proto_path=proto",
]
}
}
I had the same problem with
import "google/protobuf/timestamp.proto";
I'm on a fedora and installed protocol buffer compiler using the package manager dnf .
solution : delete your current protoc using then package manger .
on fedora:
sudo dnf remove protobuf-compiler
then follow the instruction to Install pre-compiled binaries (any OS) :
find the appropriate version of compiler herer https://github.com/protocolbuffers/protobuf/releases
unzip it in somewhere in your PATH . for example you can do something like this : $ unzip protoc-3.15.8-linux-x86_64.zip -d $HOME/.local
DONE !
What I ended up doing in same situation was to include
message google {
message protobuf {
message Timestamp {
int64 seconds = 1;
int32 nanos = 2;
}
}
}
In my proto-file. That was enough for it to be recognized as well known type, so in python I get the addition API described at https://developers.google.com/protocol-buffers/docs/reference/python-generated#timestamp.
The main advantage is that we all can keep using the system install of protoc and don't have to install from source.

How to fix ‘--go_out: protoc-gen-go: The system cannot find the file specified.’ error

I Create a person.proto and I wanna compile this file to *.go .
I installed Package
go get -u github.com/golang/protobuf/protoc-gen-go
After executing the following command
.\protoc.exe --go_out=. person.proto
I get the error below
--go_out: protoc-gen-go: The system cannot find the file specified.
I want to use the buffer protocol, version 2
How can I fix this error?
My proto file:
package communication;
message Person {
required string name = 1;
required int32 id = 2;
optional string email = 3;
enum PhoneType {
MOBILE = 0;
HOME = 1;
WORK = 2;
}
message PhoneNumber {
required string number = 1;
optional PhoneType type = 2 [default = HOME];
}
repeated PhoneNumber phone = 4;
}
Description
Unfortunately, it is said that none of the core developers develop on Windows, hence I solve the problem and add this answer for Windows developers.
However, the possible duplicate link that #Flimzy mentioned doesn't work and I have done all the 6 steps below then surprisingly the problem has solved by step 7. Moreover, by mistake, I was running the command on a VSCode terminal.
Procedure
Download protoc-win32.zip from "https://developers.google.com/protocol-buffers/docs/downloads".
Unzip the file then add the location of the protoc.exe to your PATH environment variable. In addition, it's not that much necessary, you can copy the protoc.exe to the GOPATH.
Change/Navigate the CMD/Powershell path to the file then run protoc.exe --version from the command prompt to verify the procedure.
Verify that your GOPATH environment variable is set.
Run go get -u github.com/golang/protobuf/protoc-gen-go from the CMD/Powershell. This should install the binary to %GOPATH%/bin.
Add the exact %GOPATH%/bin to your PATH environment variable.
Open a new CMD/Powershell, navigate to your .proto file then run protoc --go_out=. *.proto
References:
How to install protoc-gen-go (Go protocol buffer compiler plugin) in windows?
protoc-gen-go: protoc fails to compile in Windows
On windows, I ran the following command to resolve the issue.
go install google.golang.org/protobuf/cmd/protoc-gen-go#latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc#latest
go-zero
Google developer

Error in installing a modified package from local modifed zip file

I found a small bug in a R package. I communicated with the package author to update the code. While waiting for the author action to fix the bug, I am trying to fix the bug on my local version of the package.
I changed the R code, and also updated the MD5 of the associated file. The package is re-zipped, and I use this command to install it:
install.packages("path/to/the/file/modified_package.zip", repos = NULL)
it seems the installation is going well:
Installing package(s) into ‘C:/Users/Me/Documents/R/win-library/2.15’
(as ‘lib’ is unspecified)
package ‘x’ successfully unpacked and MD5 sums checked
However, when I try to load the package, there is an error:
> library(x)
Error in library(x) : ‘x’ is not a valid installed package
Any thoughts?
You can't just zip up the directories; you need to rebuild the package.
There are loads of guides around on how to build R packages. The easiest way (imho) is to use the devtools package.
library(devtools)
build("path/to/the/package")
install.packages("path/to/built/package.tar.gz", repos = NULL, type = "source")
Or
build("path/to/the/package", binary = TRUE)
install.packages("path/to/built/package.zip", repos = NULL, type = "win.binary")
You'll also need Rtools if you are running Windows. Install it with the installr package.
library(installr)
install.Rtools()

Resources