Created
January 4, 2017 10:09
-
-
Save ixxie/8f45529be74e0e0bb5b8d9897f4c522d to your computer and use it in GitHub Desktop.
Templating Nix Configurations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e | |
fluxlib bash | |
# this builds configuration files from templates | |
# it takes a template for a nix expression and replaces | |
# certain variables with values stored in some files. | |
function maketemp | |
{ | |
template="$1" | |
file="$2" | |
cp "$template" "$file" | |
com="sed -i" | |
for var in username fullname hostname timezone | |
do | |
#sleep 1 | |
clnvar=${!var//\//\\\/} | |
com="$com -e 's;\$$var;$clnvar;g'" | |
done | |
eval "$com $file" | |
} | |
. "$FLUX_HOME/env/user" | |
. "$FLUX_HOME/env/host" | |
templates=$(find "$FLUX_HOME/env/nixos/" -name "*.tmp") | |
for file in $templates | |
do | |
maketemp "${file:0:-4}".{tmp,nix} | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e | |
function save | |
{ | |
file="$1" | |
vars="${@:2}" | |
declare -p $vars > $file | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e | |
fluxlib bash | |
echo "Enter your user name:" | |
read username | |
echo "Enter your full name or alias:" | |
read fullname | |
save $FLUX_HOME/env/user username fullname |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment