Created
September 6, 2021 12:13
-
-
Save avnik/e45f509bd22d96d59b1ab32382237735 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!@python@/bin/python | |
import os | |
import sys | |
import subprocess | |
nix = "@nix@/bin/nix-env" | |
profiles = "/nix/var/nix/profiles" | |
system = sys.argv[1] | |
found = None | |
for each in os.listdir(profiles): | |
symlink = os.path.join(profiles, each) | |
if not os.path.islink(symlink): | |
continue | |
if os.readlink(symlink) == system: | |
found = symlink | |
if not found: | |
print(f"Registering profile for {system}") | |
subprocess.check_call(f"{nix} -p {profile}/system --set {system}", shell=True) | |
else: | |
print(f"{system} already registered as {found}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment