refactor: Justfile

This commit is contained in:
Ryan Yin
2024-01-02 11:47:59 +08:00
parent 709f56a0c2
commit e3ba141695
3 changed files with 74 additions and 35 deletions

View File

@@ -9,26 +9,24 @@ set shell := ["nu", "-c"]
#
############################################################################
nixos-switch := "nixos-rebuild switch --use-remote-sudo --flake"
debug-args := "--show-trace --verbose"
i3 mode="default":
use utils.nu *; \
nixos-switch .#ai_i3 {{mode}}
i3:
{{nixos-switch}} .#ai_i3
hypr mode="default":
use utils.nu *; \
nixos-switch .#ai_hyprland {{mode}}
hypr:
{{nixos-switch}} .#ai_hyprland
s-i3:
{{nixos-switch}} .#shoukei_i3
s-i3 mode="default":
use utils.nu *; \
nixos-switch .#shoukei_i3 {{mode}}
s-hypr:
{{nixos-switch}} .#shoukei_hyprland
i3-debug:
{{nixos-switch}} .#ai_i3 {{debug-args}}
s-hypr mode="default":
use utils.nu *; \
nixos-switch .#shoukei_hyprland {{mode}}
hypr-debug:
{{nixos-switch}} .#ai_hyprland {{debug-args}}
up:
nix flake update
@@ -58,31 +56,22 @@ gc:
#
############################################################################
darwin-prefix := "./result/sw/bin/darwin-rebuild"
darwin-switch := darwin-prefix + " switch --flake"
darwin-set-proxy:
sudo python3 scripts/darwin_set_proxy.py
sleep 1sec
darwin-rollback:
{{darwin-prefix}} rollback
rollback
ha: darwin-set-proxy
nix build .#darwinConfigurations.harmonica.system
{{darwin-switch}} .#harmonica
ha mode="default": darwin-set-proxy
use utils.nu *; \
darwin-build "harmonica" {{mode}}; \
darwin-switch "harmonica" {{mode}}
ha-debug: darwin-set-proxy
nom build .#darwinConfigurations.harmonica.system {{debug-args}}
{{darwin-switch}} .#harmonica {{debug-args}}
fe: darwin-set-proxy
nix build .#darwinConfigurations.fern.system
{{darwin-switch}} .#fern
fe-debug: darwin-set-proxy
nom build .#darwinConfigurations.fern.system {{debug-args}}
{{darwin-switch}} .#fern {{debug-args}}
fe mode="default":
use utils.nu *; \
darwin-build "fern" {{mode}}; \
darwin-switch "fern" {{mode}}
############################################################################
#

View File

@@ -97,7 +97,7 @@ just i3 # deploy my pc with i3 window manager
# just hypr # deploy my pc with hyprland compositor
# or we can deploy with details
just i3-debug
just i3 debug
# just hypr-debug
```
@@ -111,8 +111,8 @@ just ha
just fe
# deploy with details
just ha-debug
# just fe
just ha debug
# just fe debug
```
> [What y'all will need when Nix drives you to drink.](https://www.youtube.com/watch?v=Eni9PPPPBpg) (copy from hlissner's dotfiles, it really matches my feelings when I first started using NixOS...)

50
utils.nu Normal file
View File

@@ -0,0 +1,50 @@
# ================= NixOS related =========================
export def nixos-switch [
name: string
mode: string
] {
if "debug" == $mode {
nixos-rebuild switch --use-remote-sudo --flake $".#($name)" --show-trace --verbose
} else {
nixos-rebuild switch --use-remote-sudo --flake $".#($name)"
}
}
# ================= macOS related =========================
const darwin_dir = './result/sw/bin'
export def darwin-build [
name: string
mode: string
] {
let target = $".#darwinConfigurations.($name).system"
with-env { PATH : ($env.PATH | prepend darwin_dir) } {
if "debug" == $mode {
nom build $target --show-trace --verbose
} else {
nix build $target
}
}
}
export def darwin-switch [
name: string
mode: string
] {
with-env { PATH : ($env.PATH | prepend darwin_dir) } {
if "debug" == $mode {
darwin-rebuild switch --flake $".#($name)" --show-trace --verbose
} else {
darwin-rebuild switch --flake $".#($name)"
}
}
}
export def darwin-rollback [] {
with-env { PATH : ($env.PATH | prepend darwin_dir) } {
darwin-rebuild rollback
}
}