- configs = [read_config(filename) for filename in args.channels_file]
- for config in configs:
- for section in config.sections():
- if 'alias_of' in config[section]:
- assert 'git_repo' not in config[section]
- continue
- tarball = fetch_channel(v, section, config[section])
- if section in exprs:
- raise Exception('Duplicate channel "%s"' % section)
- exprs[section] = (
- 'f: f { name = "%s"; channelName = "%%s"; src = builtins.storePath "%s"; }' %
- (config[section]['release_name'], tarball))
-
- for config in configs:
- for section in config.sections():
- if 'alias_of' in config[section]:
- if section in exprs:
- raise Exception('Duplicate channel "%s"' % section)
- exprs[section] = exprs[str(config[section]['alias_of'])]
-
- command = [
- 'nix-env',
- '--profile',
- '/nix/var/nix/profiles/per-user/%s/channels' %
- getpass.getuser(),
- '--show-trace',
- '--file',
- '<nix/unpack-channel.nix>',
- '--install',
- '--from-expression'] + [exprs[name] % name for name in sorted(exprs.keys())]
- if args.dry_run:
- print(' '.join(map(shlex.quote, command)))
- else:
- v.status('Installing channels with nix-env')
- process = subprocess.run(command)
- v.result(process.returncode == 0)
+ profile_manifest = os.path.join(args.profile, "manifest.nix")
+ search_paths: List[str] = [
+ "-I", "pinch_profile=" + args.profile,
+ "-I", "pinch_profile_manifest=" + os.readlink(profile_manifest)
+ ] if os.path.exists(profile_manifest) else []
+ config = {
+ section: read_pinned_config_section(section, conf) for section,
+ conf in read_config_files(
+ args.channels_file).items()}
+ alias, nonalias = partition_dict(
+ lambda k, v: isinstance(v[0], AliasSearchPath), config)
+
+ for section, (sp, pin) in sorted(nonalias.items()):
+ assert not isinstance(sp, AliasSearchPath) # mypy can't see through
+ assert not isinstance(pin, AliasPin) # partition_dict()
+ tarball = sp.fetch(v, pin)
+ search_paths.extend(
+ ["-I", f"pinch_tarball_for_{pin.release_name}={tarball}"])
+ exprs[section] = (
+ f'f: f {{ name = "{pin.release_name}"; channelName = "%s"; '
+ f'src = builtins.storePath "{tarball}"; }}')
+
+ for section, (sp, pin) in alias.items():
+ assert isinstance(sp, AliasSearchPath) # For mypy
+ exprs[section] = exprs[sp.alias_of]
+
+ with tempfile.NamedTemporaryFile() as unpack_channel_nix:
+ unpack_channel_nix.write(b'''
+ { name, channelName, src, }:
+ derivation {
+ inherit name channelName src;
+ builder = "builtin:unpack-channel";
+ system = "builtin";
+ preferLocalBuild = true;
+ }
+ ''')
+ unpack_channel_nix.flush()
+
+ command = [
+ 'nix-env',
+ '--profile',
+ args.profile,
+ '--show-trace',
+ '--file',
+ unpack_channel_nix.name,
+ '--install',
+ '--remove-all',
+ ] + search_paths + ['--from-expression'] + [
+ exprs[name] % name for name in sorted(exprs.keys())]
+ if args.dry_run:
+ print(' '.join(map(shlex.quote, command)))
+ else:
+ v.status('Installing channels with nix-env')
+ process = subprocess.run(command)
+ v.result(process.returncode == 0)