just using nu scripts
This commit is contained in:
1 parent
f1e5830181
commit
6d9821a67b
7 files changed
+88
-103
No files matched your search
@@ -1,26 +0,0 @@
|
||||
set shell := ["zsh", "-cu"]
|
||||
|
||||
default:
|
||||
just --list
|
||||
|
||||
build:
|
||||
nh os build
|
||||
|
||||
switch:
|
||||
nh os switch
|
||||
|
||||
rollback:
|
||||
sudo nixos-rebuild switch --rollback
|
||||
|
||||
update input_name="":
|
||||
if [ ! -z {{input_name}} ]; then \
|
||||
echo "just updating... {{input_name}}"; \
|
||||
nix flake update {{input_name}}; \
|
||||
else \
|
||||
echo "updating all..."; \
|
||||
nix flake update; \
|
||||
fi
|
||||
git diff flake.lock
|
||||
|
||||
remote cmd target:
|
||||
./bin/extra/build-remote-nixos {{target}} {{cmd}}
|
||||
@@ -1,52 +0,0 @@
|
||||
#!/bin/sh
|
||||
# Bootstrap
|
||||
set -e
|
||||
ROOT_FOLDER=$(realpath $0 | xargs dirname)
|
||||
. $ROOT_FOLDER/common.sh
|
||||
# Bootstrap
|
||||
|
||||
# export NIX_SSHOPTS="-o RequestTTY=force"
|
||||
|
||||
target=${1}
|
||||
target_host=root@$target.lab.internal
|
||||
profile=hl-$target
|
||||
|
||||
valid_profiles=$(nix flake show --json 2> /dev/null | jq -r -c '.nixosConfigurations | keys[]' | grep "hl")
|
||||
|
||||
function print_valid_targets {
|
||||
echo "valid targets:"
|
||||
while IFS= read -r line; do
|
||||
echo $line | sed -r 's/.*hl-/ - /g'
|
||||
done <<< "$valid_profiles"
|
||||
}
|
||||
|
||||
if [ -z $target ]; then
|
||||
echo "must specify a target!"
|
||||
print_valid_targets
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if echo "$valid_profiles" | grep -qFx "$profile"; then
|
||||
echo "Using [$profile]"
|
||||
else
|
||||
echo "Invalid target! '$profile'"
|
||||
print_valid_targets
|
||||
exit 1
|
||||
fi
|
||||
|
||||
function run {
|
||||
remote_cmd=${1}
|
||||
echo -e "$BOLD$remote_cmd$NC on $YELLOW$target_host with $profile through $build_host$NC"
|
||||
runcmd="nixos-rebuild --target-host $target_host --use-remote-sudo $remote_cmd --flake .#$profile"
|
||||
echo -e "$BLUE$runcmd$NC"
|
||||
$runcmd
|
||||
}
|
||||
|
||||
cmd=${2}
|
||||
case $cmd in
|
||||
"test" | "dry-activate" | "run" | "switch" | "build") run $cmd;;
|
||||
*)
|
||||
echo "invalid command"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
@@ -1,9 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
## Colors
|
||||
YELLOW='\033[0;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m'
|
||||
BOLD='\033[1m'
|
||||
BLUE_BOLD='\033[1;34m'
|
||||
YELLOW_BOLD='\033[1;33m'
|
||||
@@ -0,0 +1,74 @@
|
||||
#!/usr/bin/env nu
|
||||
|
||||
# Ensure we are located at the bin folder
|
||||
const current_folder = path self | path dirname
|
||||
cd $current_folder
|
||||
|
||||
def valid_profiles [] {
|
||||
nix flake show --json err> /dev/null | from json |
|
||||
select nixosConfigurations |
|
||||
flatten | transpose |
|
||||
select column0 | rename name
|
||||
}
|
||||
|
||||
def is-valid-profile [name: string] {
|
||||
(valid_profiles | where name == $name | length) == 1
|
||||
}
|
||||
|
||||
def main [] {
|
||||
help main
|
||||
}
|
||||
|
||||
# Build configuration
|
||||
def "main build" [] {
|
||||
nh os build | print
|
||||
}
|
||||
|
||||
# Switch configuration
|
||||
def "main switch" [] {
|
||||
nh os switch | print
|
||||
}
|
||||
|
||||
# test configuration
|
||||
def "main test" [] {
|
||||
nh os test | print
|
||||
}
|
||||
|
||||
# rollback configuration
|
||||
def "main rollback" [] {
|
||||
sudo nixos-rebuild switch --rollback
|
||||
}
|
||||
|
||||
# update some flakes
|
||||
def "main update" [input_name:string = ""] {
|
||||
if $input_name == "" {
|
||||
print "Updating all flakes..."
|
||||
nix flake update | print
|
||||
} else {
|
||||
print "Updating flake: $input_name"
|
||||
nix flake update $input_name | print
|
||||
}
|
||||
git diff flake.lock | print
|
||||
}
|
||||
|
||||
# Deploy to remote machine
|
||||
def "main remote" [cmd:string, target:string = ""] {
|
||||
mut target_host = $"root@($target).lab.internal"
|
||||
mut profile = $"hl-($target)"
|
||||
if not (is-valid-profile $profile) {
|
||||
print $"Invalid Profile ($profile), please select one of:"
|
||||
return valid_profiles
|
||||
}
|
||||
$"Using [($profile)]" | print
|
||||
const valid_cmds = [
|
||||
"test" , "dry-activate" , "run" , "switch" , "build"
|
||||
]
|
||||
if not ($cmd in $valid_cmds) {
|
||||
print $"Invalid command ($cmd), please select one of"
|
||||
return $valid_cmds
|
||||
}
|
||||
$"($cmd) on ($target_host) with ($profile)" | print
|
||||
mut runcmd = $"nixos-rebuild --target-host ($target_host) --use-remote-sudo ($cmd) --flake .#($profile)"
|
||||
$runcmd | print
|
||||
bash -c $runcmd
|
||||
}
|
||||
@@ -117,9 +117,6 @@
|
||||
nixpkgs-fmt
|
||||
nixd
|
||||
nh
|
||||
just
|
||||
just-formatter
|
||||
just-lsp
|
||||
];
|
||||
shellHook = ''
|
||||
export PATH=$PATH:$(pwd)/bin
|
||||
|
||||
+14
-12
@@ -114,8 +114,6 @@ in
|
||||
]);
|
||||
in
|
||||
(with pkgs; [
|
||||
# python
|
||||
python312
|
||||
|
||||
# Work
|
||||
postgresql
|
||||
@@ -152,21 +150,25 @@ in
|
||||
discord
|
||||
signal-desktop
|
||||
|
||||
# development
|
||||
vscode
|
||||
devenv
|
||||
just
|
||||
uv
|
||||
rpi-imager
|
||||
rpiboot
|
||||
code-cursor-fhs
|
||||
nix-prefetch
|
||||
# Languages
|
||||
python312
|
||||
python313
|
||||
rust-analyzer
|
||||
uv
|
||||
cargo
|
||||
rustc
|
||||
go
|
||||
pipx
|
||||
rust-analyzer
|
||||
|
||||
# development
|
||||
vscode
|
||||
zed-editor-fhs
|
||||
devenv
|
||||
just
|
||||
rpi-imager
|
||||
rpiboot
|
||||
code-cursor-fhs
|
||||
nix-prefetch
|
||||
|
||||
# Run macos apps
|
||||
darling-dmg
|
||||
|
||||
@@ -78,7 +78,6 @@
|
||||
|
||||
# development
|
||||
zed-editor-fhs
|
||||
vscode
|
||||
nix-prefetch
|
||||
]);
|
||||
services.usbmuxd.enable = true;
|
||||
|
||||
Reference in new issue
Block a user