Skip to content

Instantly share code, notes, and snippets.

@benley
Created December 28, 2015 21:05
Show Gist options
  • Save benley/1a6f24845cee0e54f035 to your computer and use it in GitHub Desktop.
Save benley/1a6f24845cee0e54f035 to your computer and use it in GitHub Desktop.
import subprocess
from apache.aurora.client.binding_helper import (BindingHelper,
CachingBindingHelper)
from apache.aurora.client.config import GlobalHookRegistry
from pystachio.matcher import Any, Matcher
from twitter.common import log
class NixHelper(CachingBindingHelper):
@property
def name(self):
return 'Nix'
@property
def matcher(self):
return Matcher('Nix.*')[Any]
def uncached_bind(self, config, match, env, binding_dict):
package = match[1]
ref = Ref.from_address('%s[%s]' % match)
nix_attrib = nix_packages[package]
store_path = self._nix_realise(nix_attrib)
binding = {ref: store_path}
config.bind(binding)
return binding
def _nix_realise(self, attribute):
log.info('Assembling: %s', attribute)
store_path = subprocess.check_output(
['nix-build', '-A', attribute, '--no-out-link']).strip()
log.debug('Store path: %s', store_path)
return store_path
BindingHelper.register(NixHelper())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment