-
Notifications
You must be signed in to change notification settings - Fork 6
/
deps.go
53 lines (46 loc) · 950 Bytes
/
deps.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"fmt"
)
const depNixFormat = `
{
goPackagePath = "%s";
fetch = {
type = "%s";
url = "%s";
rev = "%s";
sha256 = "%s";
};
}`
// Dep represents a project dependency
// to write to deps.nix.
type Dep struct {
PackagePath string
VCS string
URL string
Revision string
SHA256 string
}
// toNix converts d into a nix set
// for use in the generated deps.nix.
func (d *Dep) toNix() string {
return fmt.Sprintf(depNixFormat,
d.PackagePath, d.VCS, d.URL,
d.Revision, d.SHA256)
}
const depsFileHeader = `# file generated from Gopkg.lock using dep2nix (https://github.com/nixcloud/dep2nix)
[`
const depsFileFooter = `
]
`
type Deps []*Dep
// toNix converts d into a deps.nix file
// for use with pkgs.buildGoPackage.
func (d Deps) toNix() string {
nix := depsFileHeader
for _, dep := range d {
nix += dep.toNix()
}
nix += depsFileFooter
return nix
}