summaryrefslogtreecommitdiffstats
path: root/nix-script-channel-checkout-generation.sh
blob: a49067bdf75dd00a1bd8031361e154ce875d5e9d (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
#!/usr/bin/env bash

source $(dirname ${BASH_SOURCE[0]})/nix-utils.sh

usage() {
    cat <<EOS
    $(help_synopsis "channel" "checkout-generation [-h] [-g <n>]")

        -g <n>  Generation to checkout
        -h      Show this help and exit

$(help_end "channel")
EOS
}

# no generation by now
GEN=

while getopts "hg:" OPTION
do
    case $OPTION in
        g)
            GEN=$OPTARG
            stdout "GEN = $GEN"
            ;;
        h)
            usage
            exit 0
            ;;

        *)
            ;;
    esac
done

[[ -z "$GEN" ]] && stderr "No generation number passed" && exit 1

CHANNELS=/nix/var/nix/profiles/per-user/root/channels

stdout "Executing checkout. Password cache will be reset afterwards"
explain sudo nix-env -p $CHANNELS --switch-generation $GEN

stdout "Resetting sudo password"
sudo -k