aboutsummaryrefslogtreecommitdiff
path: root/dot
blob: 4a75c284c37653c4f86d81e206a9ee752054b4e7 (plain) (blame)
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
#!/bin/sh

print_help() {
    echo
    echo "dot - manage, update and deploy configuration with Nix."
    echo
    echo "USAGE:"
    echo "    dot update"
    echo "    dot (system | home) [<profile>]"
    echo "    dot -h | --help"
    echo
    echo "where:"
    echo "    update"
    echo "        update 'flake.lock' file."
    echo "    system:"
    echo "        deploy system configuration (NixOS only). Requires root access."
    echo "    home:"
    echo "        deploy user configuration."
    echo "    help:"
    echo "        print this help"
    echo
}

command=${1:-help}

if [ "$command" = "update" ]; then

    nix flake update
    git add flake.lock

elif [ "$command" = "system" ]; then

    profile=${2:-$(hostname)}
    sudo nixos-rebuild switch --flake .#"$profile"

elif [ "$command" = "home" ]; then

    profile=${2:-$(hostname)}
    nix build --show-trace .#homeConfigurations."$profile".activationPackage && \
        ./result/activate

elif [ "$command" = "help" ]; then

    print_help

else

    printf "Invalid command '%s'\n\n" "$command"
    print_help
    exit 1

fi