Skip to content

Instantly share code, notes, and snippets.

@avnik
Created September 6, 2021 12:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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