1+ from collections .abc import Mapping
12from enum import Enum
23from pathlib import Path
34
@@ -22,6 +23,19 @@ class AuthBackendConfig(str, Enum):
2223 none = "none"
2324
2425
26+ # note that serialization isn't correct, as there is no way to *rename* the field `nix_type` to `_type`,
27+ # one must always specify `by_alias = True`, such as `model_dump(by_alias = True)`, relevant issue:
28+ # https://github.com/pydantic/pydantic/issues/8379
29+ class Interpolate (BaseModel ):
30+ model_config = ConfigDict (populate_by_name = True )
31+
32+ nix_type : str = Field (alias = "_type" )
33+ value : str
34+
35+ def __init__ (self , value : str ) -> None :
36+ super ().__init__ (nix_type = "interpolate" , value = value )
37+
38+
2539class CachixConfig (BaseModel ):
2640 name : str
2741
@@ -42,10 +56,16 @@ def auth_token(self) -> str:
4256
4357 # TODO why did the original implementation return an empty env if both files were missing?
4458 @property
45- def environment (self ) -> dict [str , str ]:
59+ def environment (self ) -> Mapping [str , str | Interpolate ]:
4660 environment = {}
47- environment ["CACHIX_SIGNING_KEY" ] = util .Secret (self .signing_key_file )
48- environment ["CACHIX_AUTH_TOKEN" ] = util .Secret (self .auth_token_file )
61+ if self .signing_key_file is not None :
62+ environment ["CACHIX_SIGNING_KEY" ] = Interpolate (
63+ f"%(secret:{ self .signing_key_file } )s"
64+ )
65+ if self .auth_token_file is not None :
66+ environment ["CACHIX_AUTH_TOKEN" ] = Interpolate (
67+ f"%(secret:{ self .auth_token_file } )s"
68+ )
4969 return environment
5070
5171 class Config :
@@ -133,19 +153,9 @@ def oauth_secret(self) -> str:
133153 return read_secret_file (self .oauth_secret_file )
134154
135155
136- # note that serialization isn't correct, as there is no way to *rename* the field `nix_type` to `_type`,
137- # one must always specify `by_alias = True`, such as `model_dump(by_alias = True)`, relevant issue:
138- # https://github.com/pydantic/pydantic/issues/8379
139- class Interpolate (BaseModel ):
140- model_config = ConfigDict (populate_by_name = True )
141-
142- nix_type : str = Field (alias = "_type" )
143- value : str
144-
145-
146156class PostBuildStep (BaseModel ):
147157 name : str
148- environment : dict [str , str | Interpolate ]
158+ environment : Mapping [str , str | Interpolate ]
149159 command : list [str | Interpolate ]
150160
151161 def to_buildstep (self ) -> steps .BuildStep :
@@ -156,7 +166,7 @@ def maybe_interpolate(value: str | Interpolate) -> str | util.Interpolate:
156166
157167 return steps .ShellCommand (
158168 name = self .name ,
159- env = {k : maybe_interpolate (k ) for k in self .environment },
169+ env = {k : maybe_interpolate (self . environment [ k ] ) for k in self .environment },
160170 command = [maybe_interpolate (x ) for x in self .command ],
161171 )
162172
0 commit comments