summaryrefslogtreecommitdiff
path: root/hosts/vidhar/borg/copy.py
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2022-02-17 16:25:16 +0100
committerGregor Kleen <gkleen@yggdrasil.li>2022-02-17 16:25:16 +0100
commitff9ddf823707b81d207127267433002454d70bc7 (patch)
tree8bad05f5bb6a669ec1974b534e1f530dcdc12245 /hosts/vidhar/borg/copy.py
parent8944cccd59a7d430d7416b20fc7a0952a65d6a39 (diff)
downloadnixos-ff9ddf823707b81d207127267433002454d70bc7.tar
nixos-ff9ddf823707b81d207127267433002454d70bc7.tar.gz
nixos-ff9ddf823707b81d207127267433002454d70bc7.tar.bz2
nixos-ff9ddf823707b81d207127267433002454d70bc7.tar.xz
nixos-ff9ddf823707b81d207127267433002454d70bc7.zip
vidhar: ...
Diffstat (limited to 'hosts/vidhar/borg/copy.py')
-rwxr-xr-xhosts/vidhar/borg/copy.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/hosts/vidhar/borg/copy.py b/hosts/vidhar/borg/copy.py
index b68fdf8d..71d9fe55 100755
--- a/hosts/vidhar/borg/copy.py
+++ b/hosts/vidhar/borg/copy.py
@@ -105,18 +105,21 @@ def copy_archive(src_repo_path, dst_repo_path, entry):
105 with open('/proc/self/setgroups', 'w') as setgroups: 105 with open('/proc/self/setgroups', 'w') as setgroups:
106 setgroups.write('deny') 106 setgroups.write('deny')
107 with open('/proc/self/uid_map', 'w') as uid_map: 107 with open('/proc/self/uid_map', 'w') as uid_map:
108 uid_map.write(f'{uid} {uid} 1') 108 uid_map.write(f'0 {uid} 1')
109 with open('/proc/self/gid_map', 'w') as gid_map: 109 with open('/proc/self/gid_map', 'w') as gid_map:
110 gid_map.write(f'{gid} {gid} 1') 110 gid_map.write(f'0 {gid} 1')
111 subprocess.run(['mount', '--make-rprivate', '/'], check=True) 111 subprocess.run(['mount', '--make-rprivate', '/'], check=True)
112 chroot = pathlib.Path(tmpdir) / 'chroot' 112 chroot = pathlib.Path(tmpdir) / 'chroot'
113 lower = pathlib.Path(tmpdir) / 'lower'
113 upper = pathlib.Path(tmpdir) / 'upper' 114 upper = pathlib.Path(tmpdir) / 'upper'
114 work = pathlib.Path(tmpdir) / 'work' 115 work = pathlib.Path(tmpdir) / 'work'
115 for path in [chroot,upper,work]: 116 for path in [chroot,lower,upper,work]:
116 path.mkdir() 117 path.mkdir()
117 print(f'euid={os.getuid()}', file=stderr) 118 print(f'euid={os.getuid()}', file=stderr)
118 subprocess.run(['stat', '/', upper, work, chroot], check=True) 119 subprocess.run(['stat', '/', lower, upper, work, chroot], check=True)
119 subprocess.run(['mount', '-t', 'overlay', 'overlay', '-o', f'lowerdir=/,upperdir={upper},workdir={work}', chroot], check=True) 120 subprocess.run(['mount', '-t', 'shifts', '/', lower], check=True)
121 subprocess.run(['stat', lower], check=True)
122 subprocess.run(['mount', '-t', 'overlay', 'overlay', '-o', f'lowerdir={lower},upperdir={upper},workdir={work}', chroot], check=True)
120 bindMounts = ['nix', 'run', 'proc', 'dev', 'sys', pathlib.Path(os.path.expanduser('~')).relative_to('/')] 123 bindMounts = ['nix', 'run', 'proc', 'dev', 'sys', pathlib.Path(os.path.expanduser('~')).relative_to('/')]
121 if not ":" in src_repo_path: 124 if not ":" in src_repo_path:
122 bindMounts.append(pathlib.Path(src_repo_path).relative_to('/')) 125 bindMounts.append(pathlib.Path(src_repo_path).relative_to('/'))