feat: render config files
This commit is contained in:
5 files changed
+264
-1
No files matched your search
@@ -26,6 +26,7 @@ need python3 python3 && run_suite python python3 -m unittest -q test_python
|
||||
need fetch curl python3 flock && run_suite shell/fetch-iso ./test_fetch_iso.sh
|
||||
run_suite shell/gen-keys ./test_gen_keys.sh
|
||||
run_suite shell/capture-hardware ./test_capture_hardware.sh
|
||||
run_suite shell/render-config ./test_render_config.sh
|
||||
need docker gpg python3 && run_suite shell/docker-creds ./test_docker_creds.sh
|
||||
need usb script cmp findmnt && run_suite shell/make-usb ./test_make_usb.sh
|
||||
|
||||
|
||||
Executable
+15
@@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env bash
|
||||
# Fake nix: `nix build --no-link --print-out-paths .#ATTR` -> fabricates a store-like dir.
|
||||
echo "nix $*" >> "${FAKE_NIX_LOG:-/dev/null}"
|
||||
[[ -z "${FAKE_NIX_FAIL:-}" ]] || { echo "error: attribute missing" >&2; exit 1; }
|
||||
attr="${@: -1}"
|
||||
out="${FAKE_NIX_STORE:?}/abc-home-manager-generation"
|
||||
mkdir -p "$out/home-files/.config/helix" "$out/home-files/.config/git" "$out/store"
|
||||
echo 'theme = "base16"' > "$out/store/helix.toml"; chmod 444 "$out/store/helix.toml"
|
||||
ln -sfn "$out/store/helix.toml" "$out/home-files/.config/helix/config.toml" # like real HM: symlink into store
|
||||
echo '[user]
|
||||
name = alex' > "$out/store/gitconfig"; chmod 444 "$out/store/gitconfig"
|
||||
ln -sfn "$out/store/gitconfig" "$out/home-files/.gitconfig"
|
||||
[[ -z "${FAKE_NIX_NOHOMEFILES:-}" ]] || rm -rf "$out/home-files"
|
||||
echo "$attr" > "$out/attr"
|
||||
echo "$out"
|
||||
Executable
+112
@@ -0,0 +1,112 @@
|
||||
#!/usr/bin/env bash
|
||||
set -u
|
||||
# shellcheck source=harness.sh
|
||||
source "$(dirname "$0")/harness.sh"
|
||||
RC_="$SCRIPTS/render-config.sh"
|
||||
|
||||
setup() {
|
||||
export PATH="$SHIMS:$PATH" FAKE_NIX_STORE="$T/store" FAKE_NIX_LOG="$T/nix.log"
|
||||
REPO="$T/repo"; mkdir -p "$REPO"; cd "$REPO" || exit 1
|
||||
cat > flake.nix <<'EOF'
|
||||
{ outputs = { nixpkgs, ... }: { nixosConfigurations = {
|
||||
whitegrizzly = nixpkgs.lib.nixosSystem { };
|
||||
willow = nixpkgs.lib.nixosSystem { };
|
||||
}; }; }
|
||||
EOF
|
||||
}
|
||||
|
||||
test_renders_plain_writable_files() {
|
||||
setup
|
||||
run "$RC_" --user alex
|
||||
assert_rc 0; assert_err_has "Rendered 2 file(s)"
|
||||
assert_file rendered/.config/helix/config.toml
|
||||
[[ ! -L rendered/.config/helix/config.toml ]] || _fail "still a store symlink"
|
||||
assert_file_eq rendered/.config/helix/config.toml 'theme = "base16"'
|
||||
[[ -w rendered/.gitconfig ]] || _fail "not writable"
|
||||
assert_mode rendered/.gitconfig 600
|
||||
}
|
||||
|
||||
test_default_host_is_first_in_flake_and_attr_is_correct() {
|
||||
setup
|
||||
run "$RC_" --user alex; assert_rc 0
|
||||
assert_eq ".#nixosConfigurations.whitegrizzly.config.home-manager.users.alex.home.activationPackage" "$(<"$T/store/abc-home-manager-generation/attr")"
|
||||
run "$RC_" --host willow --user bob --out o2; assert_rc 0
|
||||
assert_eq ".#nixosConfigurations.willow.config.home-manager.users.bob.home.activationPackage" "$(<"$T/store/abc-home-manager-generation/attr")"
|
||||
}
|
||||
|
||||
test_attr_override() {
|
||||
setup
|
||||
run "$RC_" --attr homeConfigurations.alex.activationPackage; assert_rc 0
|
||||
assert_eq ".#homeConfigurations.alex.activationPackage" "$(<"$T/store/abc-home-manager-generation/attr")"
|
||||
}
|
||||
|
||||
test_list_prints_relative_sorted_paths() {
|
||||
setup
|
||||
run "$RC_" --user alex --list; assert_rc 0
|
||||
assert_eq ".config/helix/config.toml
|
||||
.gitconfig" "$OUT"
|
||||
}
|
||||
|
||||
test_rerun_replaces_stale_files() {
|
||||
setup
|
||||
run "$RC_" --user alex; assert_rc 0
|
||||
echo stale > rendered/.stale; echo local-edit > rendered/.gitconfig
|
||||
run "$RC_" --user alex; assert_rc 0
|
||||
assert_no_path rendered/.stale
|
||||
assert_file_eq rendered/.gitconfig "$(printf '[user]\nname = alex')"
|
||||
}
|
||||
|
||||
test_refuses_to_delete_unrelated_directory() {
|
||||
setup
|
||||
mkdir -p precious; echo data > precious/file
|
||||
run "$RC_" --user alex --out precious
|
||||
assert_rc 1; assert_err_has "refusing to delete"
|
||||
assert_file_eq precious/file data
|
||||
mkdir empty; run "$RC_" --user alex --out empty; assert_rc 0 # empty dir is fine
|
||||
echo x > afile; run "$RC_" --user alex --out afile; assert_rc 1
|
||||
}
|
||||
|
||||
test_build_failure_leaves_previous_render_intact() {
|
||||
setup
|
||||
run "$RC_" --user alex; assert_rc 0
|
||||
FAKE_NIX_FAIL=1 run "$RC_" --user alex
|
||||
assert_rc 1; assert_err_has "git add"
|
||||
assert_file rendered/.gitconfig
|
||||
}
|
||||
|
||||
test_output_without_home_files_is_an_error() {
|
||||
setup
|
||||
FAKE_NIX_NOHOMEFILES=1 run "$RC_" --user alex
|
||||
assert_rc 1; assert_err_has "no home-files"
|
||||
assert_no_path rendered
|
||||
}
|
||||
|
||||
test_input_validation() {
|
||||
setup
|
||||
local a
|
||||
for a in "--host Bad" "--host ../x" "--user a;b" "--user 1a" "--attr a;b" "--attr \$(x)" "--bogus"; do
|
||||
# shellcheck disable=SC2086
|
||||
run "$RC_" $a; [[ $RC == 2 ]] || _fail "'$a' -> exit $RC"
|
||||
done
|
||||
run "$RC_" --out ""; assert_rc 2
|
||||
[[ ! -e "$FAKE_NIX_LOG" ]] || _fail "nix ran on invalid input"
|
||||
}
|
||||
|
||||
test_environment_errors() {
|
||||
setup
|
||||
local bin="$T/bin"; mkdir -p "$bin"
|
||||
local c; for c in bash dirname readlink env cat; do ln -s "$(command -v $c)" "$bin/$c"; done
|
||||
PATH="$bin" run "$RC_"; assert_rc 3
|
||||
rm flake.nix; run "$RC_" --user alex; assert_rc 1; assert_err_has "no flake.nix"
|
||||
run "$RC_" --repo-root /nonexistent; assert_rc 1
|
||||
}
|
||||
|
||||
test_warns_when_not_gitignored() {
|
||||
setup
|
||||
git init -q .; run "$RC_" --user alex; assert_err_has "not git-ignored"
|
||||
echo "/rendered/" > .gitignore; run "$RC_" --user alex; assert_err_lacks "not git-ignored"
|
||||
}
|
||||
|
||||
test_help() { setup; run "$RC_" -h; assert_rc 0; assert_out_has "Usage:"; }
|
||||
|
||||
run_all "${1:-}"
|
||||
Reference in new issue
Block a user