tangled
alpha
login
or
join now
pyrox.dev
/
nixpkgs
0
fork
atom
lol
0
fork
atom
overview
issues
pulls
pipelines
Reusing go libs in deis build
Kamil Chmielewski
9 years ago
81f3092e
5c2628a7
+66
-43
5 changed files
expand all
collapse all
unified
split
pkgs
development
go-modules
generic
default.nix
libs.json
tools
deis
default.nix
deps.json
tools
misc
gawp
default.nix
+33
-7
pkgs/development/go-modules/generic/default.nix
···
1
1
-
{ go, govers, parallel, lib }:
1
1
+
{ go, govers, parallel, lib, fetchgit }:
2
2
3
3
{ name, buildInputs ? [], nativeBuildInputs ? [], passthru ? {}, preFixup ? ""
4
4
···
16
16
17
17
# Extra sources to include in the gopath
18
18
, extraSrcs ? [ ]
19
19
+
20
20
+
# go2nix dependency file
21
21
+
, goDeps ? null
19
22
20
23
, dontRenameImports ? false
21
24
···
27
30
28
31
if disabled then throw "${name} not supported for go ${go.meta.branch}" else
29
32
33
33
+
with builtins;
34
34
+
30
35
let
31
36
args = lib.filterAttrs (name: _: name != "extraSrcs") args';
32
37
···
35
40
removeExpr = refs: lib.flip lib.concatMapStrings refs (ref: ''
36
41
| sed "s,${ref},$(echo "${ref}" | sed "s,$NIX_STORE/[^-]*,$NIX_STORE/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee,"),g" \
37
42
'');
43
43
+
44
44
+
dep2src = goDep:
45
45
+
{
46
46
+
inherit (goDep) goPackagePath;
47
47
+
src = if goDep.fetch.type == "git" then
48
48
+
fetchgit {
49
49
+
inherit (goDep.fetch) url rev sha256;
50
50
+
}
51
51
+
else {};
52
52
+
};
53
53
+
54
54
+
importGodeps = { depsFile, filterPackages ? [] }:
55
55
+
let
56
56
+
deps = lib.importJSON depsFile;
57
57
+
external = filter (d: d ? include) deps;
58
58
+
direct = filter (d: d ? goPackagePath && (length filterPackages == 0 || elem d.goPackagePath filterPackages)) deps;
59
59
+
in
60
60
+
concatLists (map importGodeps (map (d: { depsFile = ./. + d.include; filterPackages = d.packages; }) external)) ++ (map dep2src direct);
61
61
+
62
62
+
goPath = if goDeps != null then importGodeps { depsFile = goDeps; } ++ extraSrcs
63
63
+
else extraSrcs;
38
64
in
39
65
40
66
go.stdenv.mkDerivation (
···
53
79
mkdir -p "go/src/$(dirname "$goPackagePath")"
54
80
mv "$sourceRoot" "go/src/$goPackagePath"
55
81
56
56
-
'' + lib.flip lib.concatMapStrings extraSrcs ({ src, goPackagePath }: ''
57
57
-
mkdir extraSrc
58
58
-
(cd extraSrc; unpackFile "${src}")
82
82
+
'' + lib.flip lib.concatMapStrings goPath ({ src, goPackagePath }: ''
83
83
+
mkdir goPath
84
84
+
(cd goPath; unpackFile "${src}")
59
85
mkdir -p "go/src/$(dirname "${goPackagePath}")"
60
60
-
chmod -R u+w extraSrc/*
61
61
-
mv extraSrc/* "go/src/${goPackagePath}"
62
62
-
rmdir extraSrc
86
86
+
chmod -R u+w goPath/*
87
87
+
mv goPath/* "go/src/${goPackagePath}"
88
88
+
rmdir goPath
63
89
64
90
'') + ''
65
91
export GOPATH=$NIX_BUILD_TOP/go:$GOPATH
+19
-1
pkgs/development/go-modules/libs.json
···
25
25
"rev": "a83829b6f1293c91addabc89d0571c246397bbf4",
26
26
"sha256": "1m4dsmk90sbi17571h6pld44zxz7jc4lrnl4f27dpd1l8g5xvjhh"
27
27
}
28
28
+
},
29
29
+
{
30
30
+
"goPackagePath": "github.com/docopt/docopt-go",
31
31
+
"fetch": {
32
32
+
"type": "git",
33
33
+
"url": "https://github.com/docopt/docopt-go",
34
34
+
"rev": "784ddc588536785e7299f7272f39101f7faccc3f",
35
35
+
"sha256": "13x00cnady5znysfwca3x59dl04m8rvnk2yprgyqqpg2y4v0xmbf"
36
36
+
}
37
37
+
},
38
38
+
{
39
39
+
"goPackagePath": "golang.org/x/crypto",
40
40
+
"fetch": {
41
41
+
"type": "git",
42
42
+
"url": "https://go.googlesource.com/crypto",
43
43
+
"rev": "1f22c0103821b9390939b6776727195525381532",
44
44
+
"sha256": "05ahvn9g9cj7797n8ryfxv2g26v3lx1pza9d9pg97iw0rvar9i1h"
45
45
+
}
28
46
}
29
29
-
]
47
47
+
]
+2
-11
pkgs/development/tools/deis/default.nix
···
1
1
# This file was generated by go2nix.
2
2
-
{ stdenv, lib, goPackages, fetchgit, fetchhg, fetchbzr, fetchsvn }:
2
2
+
{ stdenv, lib, goPackages, fetchgit }:
3
3
4
4
with goPackages;
5
5
···
23
23
sha256 = "1fblg3gf7dh5hhm4ajq7yl7iy6gw8p5xlh4z8kvfy542m1fzr0dc";
24
24
};
25
25
26
26
-
extraSrcs = map ( jsonDep:
27
27
-
{
28
28
-
inherit (jsonDep) goPackagePath;
29
29
-
src = if jsonDep.fetch.type == "git" then
30
30
-
fetchgit {
31
31
-
inherit (jsonDep.fetch) url rev sha256;
32
32
-
}
33
33
-
else {};
34
34
-
}
35
35
-
) (builtins.fromJSON (builtins.readFile ../../go-modules/libs.json));
26
26
+
goDeps = ./deps.json;
36
27
}
+10
pkgs/development/tools/deis/deps.json
···
1
1
+
[
2
2
+
{
3
3
+
"include": "../../../go-modules/libs.json",
4
4
+
"packages": [
5
5
+
"github.com/docopt/docopt-go",
6
6
+
"golang.org/x/crypto",
7
7
+
"gopkg.in/yaml.v2"
8
8
+
]
9
9
+
}
10
10
+
]
+2
-24
pkgs/tools/misc/gawp/default.nix
···
1
1
# This file was generated by go2nix.
2
2
-
{ stdenv, lib, goPackages, fetchgit, fetchhg, fetchbzr, fetchsvn }:
2
2
+
{ stdenv, lib, goPackages, fetchgit }:
3
3
4
4
with builtins;
5
5
with goPackages;
6
6
7
7
-
let
8
8
-
depToSrc = jsonDep:
9
9
-
{
10
10
-
inherit (jsonDep) goPackagePath;
11
11
-
src = if jsonDep.fetch.type == "git" then
12
12
-
fetchgit {
13
13
-
inherit (jsonDep.fetch) url rev sha256;
14
14
-
}
15
15
-
else {};
16
16
-
};
17
17
-
18
18
-
importGodeps = { depsFile, filterPackages ? [] }:
19
19
-
let
20
20
-
deps = lib.importJSON depsFile;
21
21
-
external = filter (d: d ? include) deps;
22
22
-
direct = filter (d: d ? goPackagePath && (length filterPackages == 0 || elem d.goPackagePath filterPackages)) deps;
23
23
-
in
24
24
-
concatLists (map importGodeps (map (d: { depsFile = ./. + d.include; filterPackages = d.packages; }) external)) ++ (map depToSrc direct);
25
25
-
26
26
-
godeps = importGodeps { depsFile = ./deps.json; };
27
27
-
in
28
28
-
29
7
buildGoPackage rec {
30
8
name = "gawp-${version}";
31
9
version = "20160121-${stdenv.lib.strings.substring 0 7 rev}";
···
39
17
sha256 = "0r4bp4w3s9rkmg3cz9jb7d6ngh7vfj31p9kbim6mhilxvmgjk4ly";
40
18
};
41
19
42
42
-
extraSrcs = godeps;
20
20
+
goDeps = ./deps.json;
43
21
}