Skip to content

Commit

Permalink
feat: add --subpackage option to update multiple derivations
Browse files Browse the repository at this point in the history
  • Loading branch information
av-gal committed Dec 17, 2024
1 parent 6f05a35 commit cdd631d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
8 changes: 8 additions & 0 deletions nix_update/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ def parse_args(args: list[str]) -> Options:
help="Path to the directory containing the metadata (e.g. Cargo.toml) referenced by the lockfile",
default=".",
)
parser.add_argument(
"-s",
"--subpackage",
action="append",
help="Attribute for a subpackage that nix-update should try to get hashes for",
default=None,
)

a = parser.parse_args(args)
return Options(
Expand All @@ -116,6 +123,7 @@ def parse_args(args: list[str]) -> Options:
commit=a.commit,
use_update_script=a.use_update_script,
update_script_args=a.update_script_args,
subpackages=a.subpackage,
url=a.url,
write_commit_message=a.write_commit_message,
run=a.run,
Expand Down
1 change: 1 addition & 0 deletions nix_update/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Options:
version_preference: VersionPreference = VersionPreference.STABLE
version_regex: str = "(.*)"
import_path: str = os.getcwd()
subpackages: list[str] | None = None
override_filename: str | None = None
url: str | None = None
commit: bool = False
Expand Down
13 changes: 13 additions & 0 deletions nix_update/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import tomllib
from concurrent.futures import ThreadPoolExecutor
from contextlib import contextmanager
from copy import deepcopy
from os import path
from pathlib import Path

Expand Down Expand Up @@ -479,6 +480,18 @@ def update(opts: Options) -> Package:
if package.hash and update_hash:
update_src_hash(opts, package.filename, package.hash)

if opts.subpackages:
for subpackage in opts.subpackages:
info(f"Updating subpackage {subpackage}")
subpackage_opts = deepcopy(opts)
subpackage_opts.attribute += f".{subpackage}"
# Update escaped package attribute
subpackage_opts.__post_init__()
subpackage_opts.subpackages = None
# Do not update the version number since that's already been done
subpackage_opts.version_preference = VersionPreference.SKIP
update(subpackage_opts)

# if no package.hash was provided we just update the other hashes unconditionally
if update_hash or not package.hash:
if package.go_modules:
Expand Down

0 comments on commit cdd631d

Please sign in to comment.