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

81 lines
1.9 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-12-03 01:44:01 -08:00
def --wrapped rebuild [--force (-f), subcommand, ...rest] {
2025-11-30 15:19:08 -08:00
if not (
2025-10-16 17:25:13 -07:00
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}
2025-12-02 17:33:57 -08:00
) and not $force {
2025-10-16 17:25:13 -07:00
print "not enough disk space!"
return false
}
2025-11-25 17:22:05 -08:00
mut 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
}
2025-11-25 17:22:05 -08:00
sudo systemd-inhibit nice -n19 nixos-rebuild $subcommand --flake . --accept-flake-config --impure --verbose ...$rest o+e>| nom
2025-11-02 14:11:40 -08:00
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-30 17:08:45 -08:00
jj bookmark set main -r $r
jj git push
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