Skip to content

Commit f5ae40b

Browse files
Nix >=2.20 breakage fixes (#98)
1 parent 8194e49 commit f5ae40b

3 files changed

Lines changed: 28 additions & 7 deletions

File tree

src/kup/__main__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,13 +249,15 @@ def reload_packages(load_versions: bool = True) -> None:
249249
if os.path.exists(f'{os.getenv("HOME")}/.nix-profile/manifest.json'):
250250
manifest_file = open(f'{os.getenv("HOME")}/.nix-profile/manifest.json')
251251
manifest = json.loads(manifest_file.read())['elements']
252+
if type(manifest) is list:
253+
manifest = dict(enumerate(manifest))
252254
manifest_file.close()
253255
else:
254-
manifest = []
256+
manifest = {}
255257

256258
pinned_package_cache_reverse = {v: k for k, v in pinned_package_cache.items()}
257259
packages = {}
258-
for idx, m in enumerate(manifest):
260+
for idx, m in manifest.items():
259261
# fix potential inconsistencies between nix profiles
260262
# sometimes storing url/originalUrl and sometimes uri/originalUri
261263
if 'uri' in m:

src/kup/nix.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,23 @@ def nix_raw(
8686
.replace('"', '')
8787
)
8888

89+
# based on https://github.com/NixOS/nixpkgs/blob/d329d65edb3680f5aa7cc46b364a564bab27f8c7/nixos/modules/config/nix.nix#L114
90+
# to remove warnings about deprecated nix command
91+
SHOW_CONFIG_COMMAND = (
92+
nix_raw(
93+
[
94+
'eval',
95+
'--impure',
96+
'--expr',
97+
'if builtins.compareVersions builtins.nixVersion "2.20pre" == -1 then "show-config" else "config show"',
98+
],
99+
extra_flags=[],
100+
)
101+
.decode('utf8')
102+
.strip()
103+
.replace('"', '')
104+
)
105+
89106
USER = pwd.getpwuid(os.getuid())[0]
90107
USER_IS_ROOT = os.geteuid() == 0
91108

@@ -98,9 +115,11 @@ def nix_raw(
98115
def check_substituters() -> Tuple[bool, bool]:
99116
global TRUSTED_USERS, CURRENT_SUBSTITUTERS, CURRENT_TRUSTED_PUBLIC_KEYS, CURRENT_NETRC_FILE
100117
try:
101-
result = nix_raw(['show-config', '--json'], extra_flags=[])
118+
cmd = SHOW_CONFIG_COMMAND.split()
119+
cmd.append('--json')
120+
result = nix_raw(cmd, extra_flags=[])
102121
except Exception:
103-
rich.print("⚠️ [yellow]Could not run 'nix show-config'.")
122+
rich.print(f"⚠️ [yellow]Could not run 'nix {SHOW_CONFIG_COMMAND}'.")
104123
return False, False
105124
config = json.loads(result)
106125
try:

src/kup/package.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def __init__(
165165
github_package: GithubPackage,
166166
package_name: PackageName,
167167
path: str,
168-
index: int = -1,
168+
index: Union[int, str] = -1,
169169
):
170170
self.path = path
171171
self.index = index
@@ -237,7 +237,7 @@ def __init__(
237237
status: str,
238238
commit: str,
239239
tag: Optional[str] = None,
240-
index: int = -1,
240+
index: Union[int, str] = -1,
241241
ssh_git: bool = False,
242242
access_token: Optional[str] = None,
243243
substituters: Optional[list[str]] = None,
@@ -283,7 +283,7 @@ def concrete(
283283
)
284284

285285
@staticmethod
286-
def parse(url: str, package: GithubPackage, idx: int, load_versions: bool) -> 'ConcretePackage':
286+
def parse(url: str, package: GithubPackage, idx: Union[int, str], load_versions: bool) -> 'ConcretePackage':
287287
global tag_cache
288288
if package.ssh_git:
289289
commit = url.split('&rev=')[1]

0 commit comments

Comments
 (0)