@@ -15,19 +15,6 @@ nixpkgs_git_repository = repository_rule(
15
15
local = False ,
16
16
)
17
17
18
- def _mk_build_expression (ctx ):
19
- """Generate a nix expression that picks a package from nixpkgs.
20
- """
21
- # If user specified expression only, use expression only: they may
22
- # be picking their attributes in the expression itself already.
23
- if ctx .attr .expression and not ctx .attr .attribute_path :
24
- return ["-E" , ctx .attr .expression ]
25
- # In all other cases we can craft a correct query by using user's
26
- # input with some defaults.
27
- else :
28
- return ["-E" , ctx .attr .expression or "import <nixpkgs> {}" ,
29
- "-A" , ctx .attr .attribute_path or ctx .attr .name ]
30
-
31
18
def _nixpkgs_package_impl (ctx ):
32
19
if ctx .attr .build_file and ctx .attr .build_file_content :
33
20
fail ("Specify one of 'build_file' or 'build_file_content', but not both." )
@@ -39,7 +26,7 @@ def _nixpkgs_package_impl(ctx):
39
26
ctx .template ("BUILD" , Label ("@io_tweag_rules_nixpkgs//nixpkgs:BUILD.pkg" ))
40
27
41
28
# If neither repository or path are set, leave empty which will use
42
- # default value from NIX_PATH
29
+ # default value from NIX_PATH.
43
30
path = []
44
31
if ctx .attr .repository and ctx .attr .path :
45
32
fail ("'repository' and 'path' fields are mutually exclusive." )
@@ -51,8 +38,13 @@ def _nixpkgs_package_impl(ctx):
51
38
if ctx .attr .path :
52
39
path = ["-I" , "nixpkgs={0}" .format (ctx .attr .path )]
53
40
54
- buildExpr = _mk_build_expression (ctx )
55
- buildCmd = ["nix-build" ] + path + ["--no-out-link" ] + buildExpr
41
+ extraArgs = [
42
+ "-E" , ctx .attr .expression or "import <nixpkgs> {}" ,
43
+ "-A" , ctx .attr .attribute_path
44
+ if ctx .attr .expression
45
+ else ctx .attr .attribute_path or ctx .attr .name ,
46
+ ]
47
+ buildCmd = ["nix-build" ] + path + ["--no-out-link" ] + extraArgs
56
48
57
49
res = ctx .execute (buildCmd , quiet = False )
58
50
if res .return_code == 0 :
0 commit comments