From 9cd620723810ab14bf7cbb925884c0fb9ab1df82 Mon Sep 17 00:00:00 2001 From: Alexander Tomokhov Date: Fri, 22 Dec 2023 21:33:07 +0400 Subject: [PATCH] add stateVersion to userdata.json --- nixos-infect | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/nixos-infect b/nixos-infect index 68f211e..c540c61 100755 --- a/nixos-infect +++ b/nixos-infect @@ -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