Skip to content

Instantly share code, notes, and snippets.

@avnik
Created September 6, 2021 12:13
Show Gist options
  • Save avnik/e45f509bd22d96d59b1ab32382237735 to your computer and use it in GitHub Desktop.
Save avnik/e45f509bd22d96d59b1ab32382237735 to your computer and use it in GitHub Desktop.
#!@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