lkjsadlkajsd

This commit is contained in:
2025-07-02 18:59:30 +02:00
parent 9ca9d8c89a
commit a115b9ff90

234
justfile
View File

@@ -10,19 +10,11 @@ export FZF_DEFAULT_OPTS := "--height 15 --cycle --bind 'ctrl-a:toggle-all' " + e
@_default:
just "$(gum filter --placeholder "Pick a recipie..." $(just --summary --unsorted))"
eval $hostname=`just _a_host` $attrpath="" *args:
#!/usr/bin/env -S bash -euo pipefail
declare attrpath="${attrpath:-system.build.toplevel.outPath}"
[[ "$attrpath" =~ ^config\. ]] && attrpath="${attrpath:7}" ||: # pop optional 'config.' prefix
set -x
nix eval ".#nixosConfigurations.\"$hostname\".config.$attrpath" --show-trace "${@:3}"
eval-vm $hostname=`just _a_host` $attrpath="" *args:
#!/usr/bin/env -S bash -euo pipefail
declare attrpath="${attrpath:-system.build.toplevel.outPath}"
[[ "$attrpath" =~ ^config\. ]] && attrpath="${attrpath:7}" ||: # pop optional 'config.' prefix
set -x
# nix eval ".#nixosConfigurations.\"$hostname\".config.system.build.vm.outPath" --show-trace "${@:3}"
nix eval ".#nixosConfigurations.\"$hostname\".config.virtualisation.vmVariant.$attrpath" --show-trace "${@:3}"
eval $hostname=`just _a_host` $attrpath="system.build.toplevel.outPath" *args:
nix eval --log-format raw ".#nixosConfigurations.\"$hostname\".config.$attrpath" --show-trace "${@:3}"
eval-vm $hostname=`just _a_host` $attrpath="system.build.toplevel.outPath" *args:
# nix eval --log-format raw ".#nixosConfigurations.\"$hostname\".config.system.build.vm.outPath" --show-trace "${@:3}"
nix eval --log-format raw ".#nixosConfigurations.\"$hostname\".config.virtualisation.vmVariant.$attrpath" --show-trace "${@:3}"
repl $hostname=`just _a_host`:
NIX_NO_NOM=1 nixos-rebuild-ng --flake .#"$hostname" repl
@@ -50,6 +42,14 @@ update:
| xargs nix flake update
git add flake.lock
pull-dconf:
./users/pbsds/home/profiles/desktop/gnome/dconf-pull.sh
git diff ./users/pbsds/home/profiles/desktop/gnome/
-gum confirm "git add --patch?" --default=no \
&& git add --patch ./users/pbsds/home/profiles/desktop/gnome/
-gum confirm "git checkout --path?" --default=no \
&& git checkout --patch ./users/pbsds/home/profiles/desktop/gnome/
# todo: support system-manager
# todo: support home-manager?
build hostname="" *_:
@@ -100,118 +100,118 @@ push $hostname=`just _a_host` cmd=`gum choose test switch boot --header "Select
set -x; NIX_NO_NOM=1 nixos-rebuild {{cmd}} --flake .#"$hostname" --target-host "root@$target_host" --use-substitutes
fi
test-files $hostname=`just _a_host` *filenames:
#!/usr/bin/env -S bash -euo pipefail
# TODO: remember previous choices
[[ -n "$hostname" ]] || { printf >&2 "%s\n" "ERROR: no hostname"; false; }
declare -a filenames=("${@:2}")
if [[ "${#filenames[@]}" -eq 0 ]]; then
etcfiles=$(
nix eval ".#nixosConfigurations.\"$hostname\".config.environment.etc" --json \
--apply 'builtins.mapAttrs (k: v: { inherit (v) enable target mode; })'
)
homekeys=$(
nix eval ".#nixosConfigurations.\"$hostname\".config.home-manager.users" --json \
--apply 'builtins.mapAttrs (user: config: { inherit (config.home) homeDirectory; files = builtins.mapAttrs (k: v: { inherit (v) enable target recursive; }) config.home.file; } )'
# | jq 'to_entries[]| .key as $user | .value.homeDirectory as $homeDirectory | .value.files | to_entries[] | select(.value) | [ "config.home-manager.users.\"\($user)\".home.file.\"\(.key)\"", $homeDirectory + "/" + .value.target, .value.target, .key, $user, $homeDirectory] | @tsv' -r
)
filepathindex=$(
jq --null-input -c \
--arg hostname "$hostname" \
--argjson etcfiles "$etcfiles" \
--argjson homekeys "$homekeys" \
'{
"nixosConfigurations.\"\($hostname)\".config.environment.etc": (
$etcfiles | with_entries( select(.value.enable) | { key, value: (.value + { target : ("/etc/" + .value.target) }) } )
)
} + (
$homekeys | with_entries(
.key as $user |
.value.homeDirectory as $homeDirectory |
{
key: ("nixosConfigurations.\"\($hostname)\".config.home-manager.users.\"\($user)\".home.file"),
value: (
.value.files | with_entries(
select(.value.enable) | {
key,
value: (.value + {
target: ($homeDirectory + "/" + .value.target),
}),
}
)
),
}
)
)'
)
# test-files $hostname=`just _a_host` *filenames:
# #!/usr/bin/env -S bash -euo pipefail
# # TODO: remember previous choices
# [[ -n "$hostname" ]] || { printf >&2 "%s\n" "ERROR: no hostname"; false; }
# declare -a filenames=("${@:2}")
# if [[ "${#filenames[@]}" -eq 0 ]]; then
# etcfiles=$(
# nix eval ".#nixosConfigurations.\"$hostname\".config.environment.etc" --json \
# --apply 'builtins.mapAttrs (k: v: { inherit (v) enable target mode; })'
# )
# homekeys=$(
# nix eval ".#nixosConfigurations.\"$hostname\".config.home-manager.users" --json \
# --apply 'builtins.mapAttrs (user: config: { inherit (config.home) homeDirectory; files = builtins.mapAttrs (k: v: { inherit (v) enable target recursive; }) config.home.file; } )'
# # | jq 'to_entries[]| .key as $user | .value.homeDirectory as $homeDirectory | .value.files | to_entries[] | select(.value) | [ "config.home-manager.users.\"\($user)\".home.file.\"\(.key)\"", $homeDirectory + "/" + .value.target, .value.target, .key, $user, $homeDirectory] | @tsv' -r
# )
# filepathindex=$(
# jq --null-input -c \
# --arg hostname "$hostname" \
# --argjson etcfiles "$etcfiles" \
# --argjson homekeys "$homekeys" \
# '{
# "nixosConfigurations.\"\($hostname)\".config.environment.etc": (
# $etcfiles | with_entries( select(.value.enable) | { key, value: (.value + { target : ("/etc/" + .value.target) }) } )
# )
# } + (
# $homekeys | with_entries(
# .key as $user |
# .value.homeDirectory as $homeDirectory |
# {
# key: ("nixosConfigurations.\"\($hostname)\".config.home-manager.users.\"\($user)\".home.file"),
# value: (
# .value.files | with_entries(
# select(.value.enable) | {
# key,
# value: (.value + {
# target: ($homeDirectory + "/" + .value.target),
# }),
# }
# )
# ),
# }
# )
# )'
# )
# cache
if [[ "$UID" -ne 0 ]]; then
mkdir -p .direnv/
cat <<<"$filepathindex" >.direnv/just-cache-test-files-"$hostname".json
fi
else
[[ -s .direnv/just-cache-test-files-"$hostname".json ]] || { printf >&2 "%s\n" "ERROR: no cache found"; false; }
filepathindex=$(cat .direnv/just-cache-test-files-"$hostname".json)
fi
# # cache
# if [[ "$UID" -ne 0 ]]; then
# mkdir -p .direnv/
# cat <<<"$filepathindex" >.direnv/just-cache-test-files-"$hostname".json
# fi
# else
# [[ -s .direnv/just-cache-test-files-"$hostname".json ]] || { printf >&2 "%s\n" "ERROR: no cache found"; false; }
# filepathindex=$(cat .direnv/just-cache-test-files-"$hostname".json)
# fi
if [[ "${#filenames[@]}" -eq 0 ]]; then
filenames=$(
set +e
jq <<<"$filepathindex" 'to_entries[] | .value | to_entries[] | .value' -r \
| fzf --height=50% --reverse --multi -d$'\t' --with-nth 2
)
[[ -n "$selection" ]]
fi
# if [[ "${#filenames[@]}" -eq 0 ]]; then
# filenames=$(
# set +e
# jq <<<"$filepathindex" 'to_entries[] | .value | to_entries[] | .value' -r \
# | fzf --height=50% --reverse --multi -d$'\t' --with-nth 2
# )
# [[ -n "$selection" ]]
# fi
# jq <<<"$filepathindex" . ; false
# # jq <<<"$filepathindex" . ; false
filepathindex_inverse=$(
jq <<<"$filepathindex" 'with_entries( .key as $attr | .value | to_entries[] | {key: .value.target, value: (.value + {attr: $attr, key})} )' -c
)
# jq <<<"$filepathindex_inverse" . ; false
# filepathindex_inverse=$(
# jq <<<"$filepathindex" 'with_entries( .key as $attr | .value | to_entries[] | {key: .value.target, value: (.value + {attr: $attr, key})} )' -c
# )
# # jq <<<"$filepathindex_inverse" . ; false
# jq <<<"$filepathindex" 'to_entries[] | .key as $attr | .value | to_entries[] | @sh "\(.value) \($attr).\("\""+.key+"\"")"' -r
# # jq <<<"$filepathindex" 'to_entries[] | .key as $attr | .value | to_entries[] | @sh "\(.value) \($attr).\("\""+.key+"\"")"' -r
nix_expr=$(
printf "%s\n" 'pkgs.writeScript "do" ('
printf '"%s\\n" +\n' '#!${pkgs.runtimeShell}'
printf '"%s\\n" +\n' 'set -euo pipefail'
printf '"%s\\n" +\n' 'sudo : && SUDO=sudo || SUDO=:'
printf "%s\n" "${filenames[@]}" |
jq -sR --argjson index "$filepathindex_inverse" '
split("\n") | map(select(.==""|not) | $index[.] ) | group_by(.attr) | map(
" (let cfg = \(.[0].attr); in '"''"'" + (map(
if .target | startswith("/etc/") then
if .mode == "symlink" and false then "
$SUDO ln -sfn ${cfg.\"\(.key)\".source} \(.target | @sh )
" else "
$SUDO rm -rf \(.target | @sh )
$SUDO cp -a ${cfg.\"\(.key)\".source} \(.target | @sh )
$SUDO chown -R ${toString cfg.\"\(.key)\".uid}:${toString cfg.\"\(.key)\".gid} \(.target | @sh )
$SUDO chmod -R ${toString cfg.\"\(.key)\".uid}:${toString cfg.\"\(.key)\".gid} \(.target | @sh )
# TODO: cfg.\"\(.key)\".user
# TODO: cfg.\"\(.key)\".group
" end
else
if .recursive then
"${lib.getExe pkgs.xorg.lndir} -silent ${cfg.\"\(.key)\".source} \(.target | @sh )\n"
else
"ln -sfn ${cfg.\"\(.key)\".source} \(.target | @sh )\n"
end
end
) | join("")) + "'"''"')"
) | join(" + \n")
' -r
printf "%s\n" ')'
)
# printf "%s\n" "$nix_expr" ; false
# nix_expr=$(
# printf "%s\n" 'pkgs.writeScript "do" ('
# printf '"%s\\n" +\n' '#!${pkgs.runtimeShell}'
# printf '"%s\\n" +\n' 'set -euo pipefail'
# printf '"%s\\n" +\n' 'sudo : && SUDO=sudo || SUDO=:'
# printf "%s\n" "${filenames[@]}" |
# jq -sR --argjson index "$filepathindex_inverse" '
# split("\n") | map(select(.==""|not) | $index[.] ) | group_by(.attr) | map(
# " (let cfg = \(.[0].attr); in '"''"'" + (map(
# if .target | startswith("/etc/") then
# if .mode == "symlink" and false then "
# $SUDO ln -sfn ${cfg.\"\(.key)\".source} \(.target | @sh )
# " else "
# $SUDO rm -rf \(.target | @sh )
# $SUDO cp -a ${cfg.\"\(.key)\".source} \(.target | @sh )
# $SUDO chown -R ${toString cfg.\"\(.key)\".uid}:${toString cfg.\"\(.key)\".gid} \(.target | @sh )
# $SUDO chmod -R ${toString cfg.\"\(.key)\".uid}:${toString cfg.\"\(.key)\".gid} \(.target | @sh )
# # TODO: cfg.\"\(.key)\".user
# # TODO: cfg.\"\(.key)\".group
# " end
# else
# if .recursive then
# "${lib.getExe pkgs.xorg.lndir} -silent ${cfg.\"\(.key)\".source} \(.target | @sh )\n"
# else
# "ln -sfn ${cfg.\"\(.key)\".source} \(.target | @sh )\n"
# end
# end
# ) | join("")) + "'"''"')"
# ) | join(" + \n")
# ' -r
# printf "%s\n" ')'
# )
# # printf "%s\n" "$nix_expr" ; false
flake=$(nix flake archive . --json | jq .path -r)
nix build --impure --expr "with (builtins.getFlake ''$flake''); let inherit (nixosConfigurations.\"$hostname\") pkgs; in $nix_expr" --show-trace
false
# flake=$(nix flake archive . --json | jq .path -r)
# nix build --impure --expr "with (builtins.getFlake ''$flake''); let inherit (nixosConfigurations.\"$hostname\") pkgs; in $nix_expr" --show-trace
# false
# TODO: run the result
# # TODO: run the result
inspect: