+def update(args: argparse.Namespace) -> None:
+ v = Verification()
+ config = configparser.ConfigParser()
+ config.read_file(open(args.channels_file), args.channels_file)
+ exprs = []
+ for section in config.sections():
+ if 'channel_url' in config[section]:
+ tarball = fetch_with_nix_prefetch_url(
+ v, config[section]['tarball_url'], Digest16(
+ config[section]['tarball_sha256']))
+ else:
+ channel = Channel(**dict(config[section].items()))
+ ensure_git_rev_available(v, channel)
+ tarball = git_get_tarball(v, channel)
+ exprs.append(
+ 'f: f { name = "%s"; channelName = "%s"; src = builtins.storePath "%s"; }' %
+ (config[section]['release_name'], section, tarball))
+ v.status('Installing channels with nix-env')
+ process = subprocess.run(
+ [
+ 'nix-env',
+ '--profile',
+ '/nix/var/nix/profiles/per-user/%s/channels' %
+ getpass.getuser(),
+ '--show-trace',
+ '--file',
+ '<nix/unpack-channel.nix>',
+ '--install',
+ '--from-expression'] +
+ exprs)
+ v.result(process.returncode == 0)
+
+
+def main() -> None:
+ parser = argparse.ArgumentParser(prog='pinch')
+ subparsers = parser.add_subparsers(dest='mode', required=True)
+ parser_pin = subparsers.add_parser('pin')
+ parser_pin.add_argument('channels_file', type=str)
+ parser_pin.set_defaults(func=pin)
+ parser_update = subparsers.add_parser('update')
+ parser_update.add_argument('channels_file', type=str)
+ parser_update.set_defaults(func=update)
+ args = parser.parse_args()
+ args.func(args)
+
+
+main()