-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathup
executable file
·114 lines (95 loc) · 3 KB
/
up
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
114
#!/usr/bin/env fish
# Usage:
# Switches to the configuration using the default host name:
# $ up
#
# Switches to the configuration for "myhost":
# $ up -h myhost
#
# Use a different dotfiles directory (default is ~/.dotfiles):
# $ up -d /path/to/dotfiles
#
# Build without switching system configuration:
# $ up build
#
# Switch configuration but don't add boot menu entry (nixos only):
# $ up test
#
# Reclaim disk space:
# $ up prune
#
# Unknown flags are passed down. For example, to show trace use the
# following:
# $ up --show-trace
function nix
command nix --experimental-features 'nix-command flakes' $argv
end
function rebuild
switch (uname)
case Darwin
if type -q darwin-rebuild
darwin-rebuild $argv
else
nix run nix-darwin -- $argv
end
case '*'
sudo nixos-rebuild $argv
end
end
function up
# Options:
# -t/--target configuration target
set -l options (fish_opt -s t -l target -r)
# -f/--flake path to flake
set options $options (fish_opt -s f -l flake -r)
# -h/--help show help
set options $options (fish_opt -s h -l help)
# Using -i to ignore unknown flags so we can pass them down later
argparse -i -n up $options -- $argv
or return
# Default flake path to $(pwd)
set -q _flag_flake || set _flag_flake $(pwd)
# Nix expects --flake /path/to/flake#target. If the target is
# empty, then nix takes the current hostname.
set -l flake "$_flag_flake#$_flag_target"
# Any unknown option is passed through to the underlying command.
set -l options $argv[2..-1]
if set -q _flag_help
echo "Apply flake-based system configuration using Nix"
echo ""
echo "Usage: up [options] [command]"
echo ""
echo "Options:"
echo " -t, --target name Target flake configuration"
echo " -f, --flake PATH Use the flake at PATH"
echo " -h, --help Show help"
echo ""
echo "Commands:"
echo " build Build the configuration"
echo " fetch Update the flake"
echo " prune Reclaim disk space"
echo " test Apply without adding boot entry (Linux only)"
echo ""
echo "Note: unknown flags are passed down to the underlying command"
return 0
end
switch $argv[1]
case build
rebuild build --flake $flake $options
case fetch
nix flake update $_flag_flake $options
case prune
nix-collect-garbage $options
case test
if test (uname) = Darwin
echo "'test' command is not supported on macOS"
return 1
end
rebuild test --fast --flake $flake $options
case '*'
# This is special since we don't have a subcommand
set -l options $argv
rebuild switch --flake $flake $options
end
end
up $argv