aboutsummaryrefslogtreecommitdiffhomepage
path: root/bootstrap
blob: ab78d8c8d1157ab46a47997f46ea78246559cc31 (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/bin/sh

if [ $# != 1 ]; then
    echo "Usage: $0 <host>" >&2
    echo "Availabel hosts:" >&2
    grep '= mkHomeConfiguration' flake.nix | cut -d '=' -f 1 | sed -e 's/^ */ * /' >&2
    exit 1
fi

export XDG_CONFIG_HOME="$HOME/.config"
export XDG_CACHE_HOME="$HOME/.cache"
export XDG_DATA_HOME="$HOME/.local/share"
export XDG_STATE_HOME="$HOME/.local/state"

for dir in \
    "$XDG_CONFIG_HOME" \
    "$XDG_CACHE_HOME" \
    "$XDG_DATA_HOME" \
    "$XDG_STATE_HOME" \
    ; \
do
    if [ ! -d "$dir" ]; then
        mkdir -p "$dir"
    fi
done
if [ ! -d .bootstrap ]; then
    mkdir .bootstrap
fi
if [ ! -f .bootstrap/nix-install ]; then
    curl -o .bootstrap/nix-install -L https://nixos.org/nix/install
fi
if [ ! -d /nix ]; then
    sh .bootstrap/nix-install --daemon
    hash -r
fi
if ! grep -q "nix-command flakes" /etc/nix/nix.conf; then
    echo "experimental-features = nix-command flakes" | sudo tee -a /etc/nix/nix.conf > /dev/null
fi
if [ ! -d "$HOME/.local/state/nix/profiles" ]; then
    mkdir -p "$HOME/.local/state/nix/profiles"
fi
if ! type home-manager > /dev/null 2>&1; then
    nix run "nixpkgs#home-manager" -- switch --flake ".#$1"
fi

# These dotfiles are not managed by home-manager.
for name in \
    .vimrc \
    .zshenv \
    .zshrc \
    ; \
do
    if [ ! -L ~/"$name" ]; then
        ln -s -f ~/dotfiles/"$name" ~/"$name"
    fi
done
for name in \
    alacritty \
    git \
    nvim \
    ; \
do
    if [ ! -L ~/.config/"$name" ]; then
        ln -s -f ~/dotfiles/.config/"$name" ~/.config/"$name"
    fi
done

# Go
for name in \
    gitalias/git-extract-issue \
    gitalias/git-sw \
    ; \
do
    src_file="src/$name.go"
    bin_file="bin/$name"
    if [ "$bin_file" -ot "$src_file" ]; then
        go build -o "$bin_file" "$src_file"
    fi
done
if [ ! -d ~/bin ]; then
    mkdir ~/bin
fi
if [ ! -d ~/bin/gitalias ]; then
    mkdir ~/bin/gitalias
fi
for name in \
    tmux-pane-idx \
    gitalias/git-extract-issue \
    gitalias/git-sw \
    ; \
do
    if [ ! -L ~/bin/"$name" ]; then
        ln -s -f ~/dotfiles/bin/"$name" ~/bin/"$name"
    fi
done
if [ ! -f ~/.config/alacritty/alacritty.local.yml ]; then
    if [ "$(uname)" = "Darwin" ]; then
        ln -s -f ~/.config/alacritty/alacritty.macos.yml ~/.config/alacritty/alacritty.local.yml
    else
        ln -s -f ~/.config/alacritty/alacritty.linux.yml ~/.config/alacritty/alacritty.local.yml
    fi
fi
if [ ! -d ~/.config/skk ]; then
    mkdir ~/.config/skk
fi
if [ ! -f ~/.config/skk/jisyo.L ]; then
    _compressed_jisyo="$(mktemp)"
    curl -fL -o "$_compressed_jisyo" https://skk-dev.github.io/dict/SKK-JISYO.L.unannotated.gz
    gunzip -cd "$_compressed_jisyo" > ~/.config/skk/jisyo.L
fi
if [ ! -d "$XDG_STATE_HOME/zsh" ]; then
    mkdir -p "$XDG_STATE_HOME/zsh"
fi