@@ -27,6 +27,21 @@ def _nixpkgs_package_impl(ctx):
27
27
else :
28
28
ctx .template ("BUILD" , Label ("@io_tweag_rules_nixpkgs//nixpkgs:BUILD.pkg" ))
29
29
30
+ if ctx .attr .nix_file and ctx .attr .nix_file_content :
31
+ fail ("Specify one of 'nix_file' or 'nix_file_content', but not both." )
32
+ elif ctx .attr .nix_file :
33
+ ctx .symlink (ctx .attr .nix_file , "default.nix" )
34
+ elif ctx .attr .nix_file_content :
35
+ expr_args = ["-E" , ctx .attr .nix_file_content ]
36
+ else :
37
+ expr_args = ["-E" , "import <nixpkgs> {}" ]
38
+
39
+ expr_args .extend ([
40
+ "-A" , ctx .attr .attribute_path
41
+ if ctx .attr .nix_file or ctx .attr .nix_file_content
42
+ else ctx .attr .attribute_path or ctx .attr .name ,
43
+ ])
44
+
30
45
# If neither repository or path are set, leave empty which will use
31
46
# default value from NIX_PATH.
32
47
path = []
@@ -40,12 +55,6 @@ def _nixpkgs_package_impl(ctx):
40
55
if ctx .attr .path :
41
56
path = ["-I" , "nixpkgs={0}" .format (ctx .attr .path )]
42
57
43
- expr_args = [
44
- "-E" , ctx .attr .expression or "import <nixpkgs> {}" ,
45
- "-A" , ctx .attr .attribute_path
46
- if ctx .attr .expression
47
- else ctx .attr .attribute_path or ctx .attr .name ,
48
- ]
49
58
nix_build = ["nix-build" ] + path + ["--no-out-link" ] + expr_args
50
59
51
60
res = ctx .execute (nix_build , quiet = False )
@@ -58,12 +67,9 @@ def _nixpkgs_package_impl(ctx):
58
67
nixpkgs_package = repository_rule (
59
68
implementation = _nixpkgs_package_impl ,
60
69
attrs = {
61
- "attribute_path" : attr .string (
62
- doc = "Nix attribute to build. Exclusive to expression."
63
- ),
64
- "expression" : attr .string (
65
- doc = "Nix expression to build. Rule name used as attribute if not present." ,
66
- ),
70
+ "attribute_path" : attr .string (),
71
+ "nix_file" : attr .label (allow_single_file = [".nix" ]),
72
+ "nix_file_content" : attr .string (),
67
73
"path" : attr .string (),
68
74
"repository" : attr .label (),
69
75
"build_file" : attr .label (),
0 commit comments