-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·47 lines (37 loc) · 1.15 KB
/
install.sh
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!@bash@/bin/bash
export PATH=$PATH:@git@/bin
function inform() {
echo "$*" >&2
}
function die() {
inform "$1"
exit 1
}
system=$(nix-instantiate --eval --strict -E '(import <nixpkgs> {}).stdenv.hostPlatform.system' | sed 's/"//g')
if [[ "$system" == *darwin ]]; then
configDir=~/Library/dotfiles
else
configDir=~/.config/dotfiles
fi
if [ "$1" == --force ] || [ ! -r "$configDir/flake.nix" ]; then
inform "Creating new dotfiles repository $configDir"
mkdir -p "$configDir" || die "Could not create $configDir"
cd "$configDir"
username=$USER
hostname=$(hostname)
homeDirectory=~
if [ -z "$username" ] || [ -z "$hostname" ] || [ -z "$system" ] || [ -z "$homeDirectory" ]; then
die "could not determine parameters"
fi
[ ! -d .git ] && git init .
[ ! -f .gitignore ] && echo settings.nix > .gitignore
echo "{ username = \"$username\"; homeDirectory = \"$homeDirectory\"; hostname = \"$hostname\"; system = \"$system\"; }" > settings.nix
cp @defaultFlake@ flake.nix
cp @defaultReadme@ Readme.md
chmod u+w flake.nix
nix flake update .
git add .
git commit -a -m 'initial'
fi
# TODO inform when config flake is outdated
nix run "$configDir#update"