add stateVersion to userdata.json

jsonnet
Alexander 2023-12-22 21:33:07 +04:00
parent 2d54653924
commit 9cd6207238
1 changed files with 12 additions and 7 deletions

View File

@ -22,6 +22,8 @@
readonly NL=$'\n'
readonly LOCAL_FLAKE_DIR="/etc/nixos"
readonly SECRETS_FILEPATH="/etc/selfprivacy/secrets.json"
readonly NIX="/root/.nix-profile/bin/nix"
readonly NIX_OPTS=(--extra-experimental-features "nix-command flakes")
DoNetConf=
genOptionalSsh() {
@ -32,9 +34,15 @@ EOF
# Merge original userdata.json with deployment specific fields and print result.
genUserdata() {
local HASHED_PASSWORD userdata_infect
local HASHED_PASSWORD userdata_infect release
HASHED_PASSWORD="$(mkpasswd -m sha-512 "$USER_PASS")"
if ! release="$($NIX "${NIX_OPTS[@]}" eval --impure --raw --expr "(builtins.getFlake (builtins.toString ${LOCAL_FLAKE_DIR})).inputs.selfprivacy-nixos-config.inputs.nixpkgs.lib.trivial.release")"
then
echo "cannot determine NixOS release version"
return 1
fi
userdata_infect=$(cat << EOF
{
$(genOptionalSsh)
@ -48,7 +56,8 @@ genUserdata() {
"domain": "$DOMAIN",
"hashedMasterPassword": "$HASHED_PASSWORD",
"hostname": "$HOSTNAME",
"username": "$LUSER"
"username": "$LUSER",
"stateVersion": "$release"
}
EOF
)
@ -97,8 +106,6 @@ EOF
)
fi
local NIX="/root/.nix-profile/bin/nix"
local NIX_OPTS=(--extra-experimental-features nix-command)
local currentSystem
if ! currentSystem="$($NIX "${NIX_OPTS[@]}" eval --impure --raw --expr builtins.currentSystem)"
then
@ -132,8 +139,6 @@ EOF
}
genDeploymentConfiguration() {
local NIX="/root/.nix-profile/bin/nix"
local NIX_OPTS=(--extra-experimental-features "nix-command flakes")
local release
if ! release="$($NIX "${NIX_OPTS[@]}" eval --impure --raw --expr "(builtins.getFlake (builtins.toString ${LOCAL_FLAKE_DIR})).inputs.selfprivacy-nixos-config.inputs.nixpkgs.lib.trivial.release")"
@ -147,7 +152,7 @@ ${DoNetConf:+"{ lib, ... }: "}{
# The content below is static and belongs to this deployment only!
# Do not copy this configuration file to another NixOS installation!
system.stateVersion = "$release";`
# system.stateVersion = "$release";`
`$(if [ "$DoNetConf" == "y" ]; then echo -e "$NL"; genNetworkingConf; fi)
}
EOF