# SPDX-FileCopyrightText: 2026 Nitesh Kumar Debnath # # SPDX-License-Identifier: GPL-3.0-or-later # These are the hosts I have def hostnames [] { ["tjmaxxer", "msi-colgate", "disko-elysium"] } #Catchall to overload base jst @category 'Debug' export def main []: nothing -> nothing { health } # Print if the import is working @category 'Debug' export def health [] { $"Import is working! $SHLVL at ($env.SHLVL)" | print $in } # Push to the CI mirror @category 'Remote operations' export def ci [revset: string = @- # The jj revset ] { jj bookmark advance jj git push -c ($revset) --remote flake-mirror jj git push -c ($revset) --remote tngl-mirror } @category 'Remote operations' def change-id [revset: string = @- # The jj revset ] { jj log -r ($revset) -T "change_id.short()" --no-graph } # Create a Pull Request @category 'Remote operations' export def pr [revset: string = @- # The jj revset ] { ci gh pr create --head push-(change-id $revset) --fill-verbose } # Merge into trunk and commit to remotes @category 'Remote operations' export def trunk [revset: string = @- # The jj revset ] { jj git push -r ($revset) --remote flake-mirror --bookmark main jj git push -r ($revset) --remote tngl-mirror --bookmark main jj git push -r ($revset) --remote origin --bookmark main jj gf jj git push --deleted --remote tngl-mirror } # Create a snapshotted watcher @category 'Remote operations' export def new [] { # Watch is uncapturable for some reason watch $"($nu.home-dir)/nixos-machine" --glob=**/*.nix {|| nix flake check; jj new } } # Large squashes that flatten multiple revisions @category 'Remote operations' export def squash [base: string] { jj squash -t $base -f $"($base)::@-" } export def pwget [field: string, path: path = secrets/core.yaml] { sops decrypt --extract $"['($field)']['password']" ($path) } export def throttle --wrapped [...cmd: string] { ( systemd-inhibit --what=sleep:shutdown systemd-run --user --scope --property=MemoryMax=8G --property=CPUWeight=500 ...$cmd ) } # Creates new files and attaches SPDX Identifiers to them export def file --wrapped [filename: path, ...args] { touch $filename ( ^reuse annotate --copyright="Nitesh Kumar Debnath " --license="GPL-3.0-or-later" $filename ...$args ) jj st } @deprecated "I don't really care about nfb anymore" def fast [machine: string@hostnames] { nix-fast-build --flake=$".#nixosConfigurations.($machine).config.system.build.toplevel" nh os switch . } # Remote deploys export def deploy [hostname: string@hostnames # The hostname argument --switch(-s) # Whether to use switch or test ] { let command = if $switch { "switch" } else { "test" } ( nh os $command . --hostname $hostname --target-host $"(whoami)@($hostname).local" ) } export def switch [hostname: string@hostnames] { nixos-rebuild switch --flake . --elevate run0 } # Generates a tack lock update export def --wrapped lock [ --dry-run(-n) # Will not make a commit, only looks ...rest: string # Arguments to be passed to tack ] { $env.TACK_NIX_CONF_TOKENS = 1 tack look --verbose ...$rest | lines | where { $in !~ "unchanged|fixed|\#" } | where { is-not-empty } | tee { each {print} } | let $changelog if $changelog == [] { print "Nothing changed" return } if $dry_run { return } jj new -B @ -m "tack: update" -m $"($changelog | to text)" tack update ...$rest if (jj diff) == "" { jj undo return } try { jj next --edit } catch { jj new } } # Get an evaluation perf time report export def --wrapped eval [hostname: string@hostnames = tjmaxxer # Host config to evaluate ...rest # Extra arguments ] { $env.NIX_SHOW_STATS = 1 ( nix eval $".#nixosConfigurations.($hostname).config.system.build.toplevel" --substituters " " --no-eval-cache --read-only ...$rest ) } # Get a profiler flamegraph export def "eval profiler" [hostname: string@hostnames = tjmaxxer # Host config to profile ] { $env.NIX_SHOW_STATS = 1 ( nix eval $".#nixosConfigurations.($hostname).config.system.build.toplevel" --substituters " " --no-eval-cache --read-only --impure --eval-profiler flamegraph --eval-profiler-frequency 9999 ) (inferno-flamegraph --width 10000 nix.profile o> $"result-($hostname).svg") zen result-($hostname).svg }