This commit is contained in:
Peder Bergebakken Sundt 2025-03-23 17:55:15 +01:00
parent 793ef6ca6f
commit 07801d65b2
6 changed files with 42 additions and 18 deletions
pkgs/mk-nspawn-setup
profiles
users/pbsds/home/profiles

@ -6,19 +6,19 @@ NSPAWN_NAME=nixos-@hostname@
TARBALL=./nixos-@hostname@.tar.xz TARBALL=./nixos-@hostname@.tar.xz
test $(id -u) -eq 0 || { test $(id -u) -eq 0 || {
>&2 echo you must run this as root echo >&2 you must run this as root
exit 1 exit 1
} }
if ! >/dev/null command -v systemd-nspawn; then if ! >/dev/null command -v systemd-nspawn; then
>&2 echo "systemd-nspawn" not found in PATH echo >&2 "systemd-nspawn" not found in PATH
>&2 echo consider installing 'systemd-container' echo >&2 consider installing 'systemd-container'
exit 1 exit 1
fi fi
if ! >/dev/null command -v machinectl; then if ! >/dev/null command -v machinectl; then
>&2 echo "machinectl" not found in PATH echo >&2 "machinectl" not found in PATH
>&2 echo consider installing 'systemd-container' echo >&2 consider installing 'systemd-container'
exit 1 exit 1
fi fi

@ -38,11 +38,11 @@ in
runtimeInputs = with pkgs; [ curl iproute2 jq ]; runtimeInputs = with pkgs; [ curl iproute2 jq ];
text = '' text = ''
test -s /run/secrets/domeneshop/token || { test -s /run/secrets/domeneshop/token || {
>&2 echo "ERROR: /run/secrets/domeneshop/token not found!" echo >&2 "ERROR: /run/secrets/domeneshop/token not found!"
exit 1 exit 1
} }
test -s /run/secrets/domeneshop/secret || { test -s /run/secrets/domeneshop/secret || {
>&2 echo "ERROR: /run/secrets/domeneshop/secret not found!" echo >&2 "ERROR: /run/secrets/domeneshop/secret not found!"
exit 1 exit 1
} }
DOMENESHOP_TOKEN="$( cat /run/secrets/domeneshop/token)" DOMENESHOP_TOKEN="$( cat /run/secrets/domeneshop/token)"

@ -33,7 +33,7 @@ let
time rsync -r --chmod +rw --copy-links ${root}/ . time rsync -r --chmod +rw --copy-links ${root}/ .
test ! -e pagefind || { test ! -e pagefind || {
>&2 echo 'ERROR: `root` input has `pagefind` already in it!' echo >&2 'ERROR: `root` input has `pagefind` already in it!'
false false
} }

@ -4,7 +4,7 @@ destore() {
if test ! -w "$(dirname $(realpath --no-symlinks $dst))" ; then if test ! -w "$(dirname $(realpath --no-symlinks $dst))" ; then
MAYBESUDO="sudo" MAYBESUDO="sudo"
sudo true || { sudo true || {
>&2 echo "ERROR: could not destore '$dst' due to lack of sudo" echo >&2 "ERROR: could not destore '$dst' due to lack of sudo"
break break
} }
fi fi

@ -1,4 +1,5 @@
_ns() { # TODO: nom
_ns_ohk2aaDu() {
local is_dev=$1; shift # "true" or "false" local is_dev=$1; shift # "true" or "false"
if $is_dev; then if $is_dev; then
local arg_suffix="^*" local arg_suffix="^*"
@ -6,6 +7,7 @@ _ns() {
local arg_suffix="" local arg_suffix=""
fi fi
local args=() local args=()
local pkg
for pkg in "$@"; do for pkg in "$@"; do
if [[ "$pkg" = -- ]]; then if [[ "$pkg" = -- ]]; then
break break
@ -25,7 +27,7 @@ _ns() {
cmd=("${cmd[@]:1}") cmd=("${cmd[@]:1}")
if [[ ${#cmd[@]} -gt 0 ]]; then if [[ ${#cmd[@]} -gt 0 ]]; then
( (
_ns false "${args[@]}" _ns_ohk2aaDu false "${args[@]}"
set -x set -x
"${cmd[@]}" "${cmd[@]}"
) )
@ -33,13 +35,14 @@ _ns() {
fi fi
# echo current shell # echo current shell
# >&2 echo -n + exec nix shell # TODO: deduplicate repeats, 'x^*' should replace 'x'
>&2 echo -n + ns # echo >&2 -n + exec nix shell
echo >&2 -n + ns
if [[ -v _PREVIOUS_NS_ARGS ]]; then if [[ -v _PREVIOUS_NS_ARGS ]]; then
>&2 echo -n " ${_PREVIOUS_NS_ARGS:-}" echo >&2 -n " ${_PREVIOUS_NS_ARGS:-}"
fi fi
>&2 printf " %q" "${args[@]}" >&2 printf " %q" "${args[@]}"
>&2 echo echo >&2
if [[ "${#args[@]}" -eq 0 ]]; then if [[ "${#args[@]}" -eq 0 ]]; then
return return
@ -135,5 +138,24 @@ _ns() {
fi fi
} }
ns() { _ns false "$@"; } ns() { _ns_ohk2aaDu false "$@"; }
nd() { _ns true "$@"; } nd() { _ns_ohk2aaDu true "$@"; }
# TODO: some way to "pop"?
# TODO: support empty args with nix-search
# enter
ne() {
local pkg="$1"
if [[ -z "$pkg" ]]; then
return
fi
if [[ ! "$pkg" =~ ^.*[#:/].*$ ]]; then
pkg=nixpkgs#"${pkg}"
fi
ns "$@"
storepath="$(nix --extra-experimental-features "nix-command flakes" build --impure "$pkg" --print-out-paths --no-link)"
printf >&2 "+ cd %q\n" "$storepath"
cd "$storepath"
}

@ -130,7 +130,9 @@ in
home.shellAliases.fda = "fd --no-ignore --hidden"; home.shellAliases.fda = "fd --no-ignore --hidden";
home.shellAliases.afd = "fd --no-ignore --hidden"; home.shellAliases.afd = "fd --no-ignore --hidden";
home.shellAliases.nlocate = "nix-locate --top-level --regex"; # via nix-index-with-full-db # via nix-index-with-full-db
home.shellAliases.nlocate = "nix-locate --top-level --regex";
home.shellAliases.nlocateo = mkArgsAlias ''nix-locate --top-level --regex "$@" | tr -s ' ' | cut -d' ' -f4'';
home.shellAliases.inom = mkArgsAlias ''nom "$@" --system i686-linux -j0''; home.shellAliases.inom = mkArgsAlias ''nom "$@" --system i686-linux -j0'';
home.shellAliases.inix = mkArgsAlias ''nix "$@" --system i686-linux -j0''; home.shellAliases.inix = mkArgsAlias ''nix "$@" --system i686-linux -j0'';