summaryrefslogtreecommitdiffstats
path: root/bin/nixos-fetch-git
blob: 7002208b5e809edec55379d59be548c76b3b8773 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#! /bin/sh
#
# nixos-fetch-git : nixos-config -> ...
#
set -euf

host=$1

target=root@$host

git_rev=$(nixos-query "$host" nixpkgs.rev)
git_url=$(nixos-query "$host" nixpkgs.url)

worktree=$nixpkgs_root/$host

if [ ! -d "$worktree" ]; then
  mkdir -p "$worktree"
fi

cd "$worktree"

git init -q

if ! current_url=$(git config remote.src.url); then
  git remote add src "$git_url"
elif [ "$current_url" != "$git_url" ]; then
  git remote set-url src "$git_url"
fi

git fetch src

git checkout "$git_rev"