nixos/system/home/scripts/python/sync-all.py
Evie Litherland-Smith 5ff572a9b7 Major rewrite/refactor to simplify things
Move home/ directory under system/ directory. Remove duplicated
machine-specific config files, now handled as one per host (excluding
hardware-configuration directory)

Move as much configuration as possible out of flake.nix and into more
appropriate files (e.g. system/default.nix)

Add a desktop.nix and laptop.nix for system, both will import
home/desktop.nix and home/laptop.nix respectively to reduce
duplication in machine-specific config files

Remove games and streaming directories, moved directly into Vanguard
config file

Remove home/personal.nix since it ended up being empty after changes

Remove old sway config since I haven't been maintaining it and this
refactor will definitely break it
2024-08-30 12:57:02 +01:00

69 lines
2.1 KiB
Python
Executable file

#!/usr/bin/env nix-shell
#!nix-shell -i python3 -p git git-sync
import os
import queue
import subprocess
from pathlib import Path
from typing import Dict
HOME = Path("~").expanduser().resolve()
SYNC_MAPPING: Dict[Path, str] = {
Path(
"~/.password-store"
).expanduser(): "https://git.xenia.me.uk/pixelifytica/pass.git",
Path("~/.elfeed").expanduser(): "https://git.xenia.me.uk/pixelifytica/elfeed.git",
Path(
"~/Documents/Org"
).expanduser(): "https://git.xenia.me.uk/pixelifytica/org.git",
Path(
"~/Documents/References"
).expanduser(): "https://git.xenia.me.uk/pixelifytica/references.git",
}
PULL_MAPPINGS: Dict[Path, str] = {
Path("/etc/nixos"): "https://git.xenia.me.uk/pixelifytica/nixos.git",
Path(os.getenv("XDG_CONFIG_HOME", "~/.config")).expanduser()
/ "emacs": "https://git.xenia.me.uk/pixelifytica/emacs.git",
}
def git_set_url(directory: Path, url: str) -> None:
"""Set url for directory"""
comp = subprocess.run(f"git remote set-url origin {url}".split(), cwd=directory)
if comp.returncode != 0:
raise UserWarning(f"{comp.returncode} from {' '.join(comp.args)}")
subprocess.run("git remote -v".split(), cwd=directory)
def git_sync(directory: Path, url: str) -> subprocess.CompletedProcess:
"""Sync status of repository"""
print(f"--- sync: ${directory} ---")
if not directory.exists():
return subprocess.run("exit 1".split()) # TODO
git_set_url(directory, url)
return subprocess.run("git-sync -ns".split(), cwd=directory)
def git_pull(
directory: Path, url: str, ff_only: bool = True
) -> subprocess.CompletedProcess:
"""Pull updates for directory from url"""
print(f"--- pull: {directory} ---")
if not directory.exists():
return subprocess.run("exit 1".split()) # TODO
git_set_url(directory, url)
return subprocess.run("git pull --ff-only".split(), cwd=directory)
def main(*args, **kwargs) -> None:
for directory, url in SYNC_MAPPING.items():
print(git_sync(directory, url))
for directory, url in PULL_MAPPINGS.items():
print(git_pull(directory, url))
if __name__ == "__main__":
main()