NOflake/users/tao/nushell/extras/nix.nu

81 lines
2 KiB
Text
Raw Normal View History

2025-02-20 14:55:55 -08:00
alias nd = nix develop
2025-03-06 00:20:30 -08:00
2025-04-01 13:27:41 -07:00
def ns [...packages: string] {
let packages = $packages | each {$"nixpkgs#($in)"}
nix shell ...$packages
2025-02-20 14:55:55 -08:00
}
2025-03-06 00:20:30 -08:00
2025-03-14 18:07:44 -07:00
# def nr [package] {
# nix search nixpkgs $package
# }
2025-02-20 14:55:55 -08:00
2025-03-14 18:07:44 -07:00
def rebuild [subcommand, --builders: string] {
2025-10-16 17:25:13 -07:00
if (
df -h | detect columns --guess | where "Mounted on" == "/" or "Mounted on" == "/boot" | get Use% | each {parse "{usage}%" | get usage | into int} | flatten | all {$in < 99}
) {
print "not enough disk space!"
return false
}
2025-03-06 17:05:34 -08:00
mut builders = $builders;
2025-02-20 14:55:55 -08:00
if (open /etc/hostname --raw) == "NOlaptop\n" and ($builders != "") {
2025-03-06 17:05:34 -08:00
if (ping -c1 -W1 nocomputer | complete | $in.exit_code == 0) {
sudo nix store info --store ssh://nocomputer
} else {
$builders = ""
}
2025-02-20 14:55:55 -08:00
}
if ($builders == "") {
2025-11-02 14:11:40 -08:00
sudo systemd-inhibit nice -n19 nixos-rebuild $subcommand --flake . --accept-flake-config --impure --verbose --builders "" o+e>| nom
2025-02-20 14:55:55 -08:00
} else {
2025-11-02 14:11:40 -08:00
sudo systemd-inhibit nice -n19 nixos-rebuild $subcommand --flake . --accept-flake-config --impure --verbose o+e>| nom
}
if $env.LAST_EXIT_CODE == 0 {
toastify send "rebuild" "done!"
return true
} else {
toastify send "rebuild" "failed!"
return false
2025-02-20 14:55:55 -08:00
}
}
2025-03-06 00:20:30 -08:00
2025-02-20 14:55:55 -08:00
def post-rebuild [] {
rm -r ~/.config/helix/runtime/grammars/
hx --grammar fetch; hx --grammar build
rustup update
}
2025-03-06 00:20:30 -08:00
2025-03-14 18:07:44 -07:00
def bump [...rest] {
2025-02-20 14:55:55 -08:00
cd /home/tao/projects/NOflake/
2025-11-04 22:15:58 -08:00
mut r = "@"
loop {
match (jj log -r $r --no-pager --no-graph --template 'if(empty, "empty", self.description())') {
2025-11-09 23:24:17 -08:00
"bump (unbuilt)" | "bump (failed)" => {
jj desc -m "bump (unbuilt)"
}
2025-11-04 22:15:58 -08:00
"empty" => {
$r = $r + "-"
continue
}
_ => {
2025-11-09 23:28:06 -08:00
jj new -r $r -m "bump (unbuilt)"
2025-11-04 22:15:58 -08:00
}
2025-10-31 22:02:09 -07:00
}
2025-11-04 22:15:58 -08:00
break
2025-03-27 12:06:17 -07:00
}
2025-10-31 22:02:09 -07:00
let r = jj log -r @ --no-pager --no-graph --template 'change_id'
2025-11-02 14:11:40 -08:00
sudo nix flake update
if (rebuild boot) {
2025-10-31 22:02:09 -07:00
jj desc -r $r -m $"bump (date now | format date "%Y-%m-%d")"
2025-11-02 14:11:40 -08:00
} else {
2025-10-31 22:02:09 -07:00
jj desc -r $r -m "bump (failed)"
2025-11-02 14:11:40 -08:00
}
2025-11-04 22:15:58 -08:00
jj new
2025-11-10 06:24:22 -08:00
nvd history
2025-02-20 14:55:55 -08:00
}
2025-03-06 00:20:30 -08:00
2025-02-20 14:55:55 -08:00
alias rb = rebuild boot
alias rs = rebuild switch
alias gc = nh clean all