From e238cb522f7168fbc997101d00e6e2cc0d3e2ff9 Mon Sep 17 00:00:00 2001 From: diamondburned Date: Sun, 20 Mar 2022 01:48:32 -0700 Subject: [PATCH] Migrate to Go Modules --- default.nix | 10 ++-------- go.mod | 7 +++++++ go.sum | 4 ++++ src/nixos-shell/main.go => main.go | 23 ++++++++++++----------- result | 1 + src/github.com/jessevdk/go-flags | 1 - 6 files changed, 26 insertions(+), 20 deletions(-) create mode 100644 go.mod create mode 100644 go.sum rename src/nixos-shell/main.go => main.go (98%) create mode 120000 result delete mode 160000 src/github.com/jessevdk/go-flags diff --git a/default.nix b/default.nix index 0327bb9..60e5698 100644 --- a/default.nix +++ b/default.nix @@ -4,14 +4,8 @@ with import nixpkgs { inherit system; }; -stdenv.mkDerivation { +buildGoModule { name = "nixos-shell"; src = ./.; - buildInputs = [ go ]; - phases = [ "buildPhase" ]; - buildPhase = - '' - mkdir -p $out/bin - GOPATH=$src go build -o $out/bin/nixos-shell nixos-shell - ''; + vendorSha256 = "0gjj1zn29vyx704y91g77zrs770y2rakksnn9dhg8r6na94njh5a"; } diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..add6cc0 --- /dev/null +++ b/go.mod @@ -0,0 +1,7 @@ +module github.com/chrisfarms/nixos-shell + +go 1.17 + +require github.com/jessevdk/go-flags v1.5.0 + +require golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4 // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..df31363 --- /dev/null +++ b/go.sum @@ -0,0 +1,4 @@ +github.com/jessevdk/go-flags v1.5.0 h1:1jKYvbxEjfUl0fmqTCOfonvskHHXMjBySTLW4y9LFvc= +github.com/jessevdk/go-flags v1.5.0/go.mod h1:Fw0T6WPc1dYxT4mKEZRfG5kJhaTDP9pj1c2EWnYs/m4= +golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4 h1:EZ2mChiOa8udjfp6rRmswTbtZN/QzUQp4ptM4rnjHvc= +golang.org/x/sys v0.0.0-20210320140829-1e4c9ba3b0c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/src/nixos-shell/main.go b/main.go similarity index 98% rename from src/nixos-shell/main.go rename to main.go index cbd8766..8187902 100644 --- a/src/nixos-shell/main.go +++ b/main.go @@ -2,29 +2,30 @@ package main import ( "crypto/rand" + "encoding/base32" "fmt" - "github.com/jessevdk/go-flags" + "io/ioutil" "os" "os/exec" "os/signal" "path" "path/filepath" - "strings" "strconv" - "io/ioutil" + "strings" "syscall" "time" - "encoding/base32" + + "github.com/jessevdk/go-flags" ) // Generate a random id for the container name. // This name can't be too long as it is used as -// an interface name as well which will explode if +// an interface name as well which will explode if // is larger than 6 bytes for some reason. // Clashes are possible here so this checks against // known container names to ensure it's unique func randomName() (string, error) { - for i := 0; i<25; i++ { + for i := 0; i < 25; i++ { b := make([]byte, 6) _, err := rand.Read(b) if err != nil { @@ -56,7 +57,7 @@ type Cmd struct { Timeout int `short:"t" description:"timeout in seconds to wait for container boot" default:"90"` Ports []string `short:"p" long:"port" description:"expose a container port to the host. example '8080:80' allows access to container port 80 via host port 8080"` sigint chan bool - netenv map[string]string + netenv map[string]string } // logging @@ -116,7 +117,7 @@ func (cmd *Cmd) Create(confpath string) (keyPath string, err error) { '' cd /src ''; - `, confpath, pub, ) + `, confpath, pub) err = cmd.container(false, "create", cmd.Id, "--config", module) if err != nil { return "", err @@ -192,7 +193,7 @@ func (cmd *Cmd) keygen() (private string, public string, err error) { return } keyPath := path.Join(home, "id_rsa") - args := []string{ "-t", "rsa", "-N", "", "-f", keyPath } + args := []string{"-t", "rsa", "-N", "", "-f", keyPath} cmd.debug(exe, args) c := exec.Command(exe, args...) if cmd.Verbose { @@ -204,7 +205,7 @@ func (cmd *Cmd) keygen() (private string, public string, err error) { if err != nil { return } - return keyPath, keyPath+".pub", nil + return keyPath, keyPath + ".pub", nil } // wrapper around ssh @@ -467,7 +468,7 @@ func (cmd *Cmd) Execute() error { fmt.Fprintf(os.Stderr, "failed to destroy container %s\n", cmd.Id) } }() - key, err := cmd.Create(confpath); + key, err := cmd.Create(confpath) if err != nil { return err } diff --git a/result b/result new file mode 120000 index 0000000..ff32947 --- /dev/null +++ b/result @@ -0,0 +1 @@ +/nix/store/gza2bw1c2lz58qxxsdx6f79njwkpjshj-nixos-shell \ No newline at end of file diff --git a/src/github.com/jessevdk/go-flags b/src/github.com/jessevdk/go-flags deleted file mode 160000 index 1f8fc78..0000000 --- a/src/github.com/jessevdk/go-flags +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 1f8fc78104c465b25629ed0fa9bbd4dffb39dd8e