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

91 lines
2.2 KiB
Text
Raw Normal View History

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
2026-01-14 19:06:30 -08:00
ulimit -n 65535
2026-01-16 21:57:07 -08:00
sudo systemd-inhibit nice -n19 nixos-rebuild $subcommand --flake . --accept-flake-config --impure --show-trace --verbose ...$rest o+e>| nom
2025-11-25 17:22:05 -08:00
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
2026-01-16 21:57:07 -08:00
alias nd = nix develop
def ns [...packages: string] {
let packages = $packages | each {$"nixpkgs#($in)"}
nix shell ...$packages
}
# def nr [package] {
# nix search nixpkgs $package
# }
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
2026-02-09 14:28:08 -08:00
def get_gen [] {
sudo nix-env --profile /nix/var/nix/profiles/system --list-generations | detect columns --guess -n | last | get column0
}
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
2026-02-11 00:09:56 -08:00
let curr_gen = get_gen
2026-02-05 03:28:34 -08:00
let build_status = rebuild boot
2026-02-11 00:09:56 -08:00
let new_gen = get_gen
2026-02-05 03:28:34 -08:00
if ($build_status and ($curr_gen == $new_gen)) {
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-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
2025-12-18 17:59:04 -08:00
def gc [] {
sudo nix-collect-garbage -d
snapper clear
}
2025-02-20 14:55:55 -08:00