my Nix configuration
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

conf 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/usr/bin/env bash
  2. if ! [ -e deploy_key ] || ! [ -e secrets.nix ]
  3. then
  4. git crypt unlock
  5. sudo chgrp nixbld deploy_key
  6. chmod 640 deploy_key
  7. fi
  8. export NIX_PATH="ssh-id-file=$PWD/deploy_key":secrets=$PWD/secrets.nix:yori-nix=$PWD
  9. function get_channel {
  10. case $1 in
  11. git)
  12. echo "nixpkgs=https://github.com/NixOS/nixpkgs/archive/master.tar.gz"
  13. ;;
  14. stable)
  15. echo "nixpkgs=https://nixos.org/channels/nixos-18.03/nixexprs.tar.xz"
  16. ;;
  17. checkout)
  18. echo "nixpkgs=$PWD/../projects/nixpkgs"
  19. ;;
  20. channel)
  21. echo "/nix/var/nix/profiles/per-user/root/channels/nixos"
  22. ;;
  23. esac
  24. }
  25. case $1 in
  26. cloc)
  27. exec cloc --read-lang-def=deploy/nix_cloc .
  28. ;;
  29. copy-keys)
  30. $0 exec "$2" nix build -f "\\<nixpkgs/nixos\\>" config.deployment.keys-copy --out-link copy-keys
  31. TARGET_HOST=$(jq -r ".$2.host"<servers.json)
  32. ./copy-keys/bin/copy-keys "$TARGET_HOST"
  33. # rm ./copy-keys
  34. ;;
  35. exec)
  36. CHANNEL=$(jq -r ".$2.pkgs"<servers.json)
  37. export NIX_PATH="$(get_channel "$CHANNEL"):nixos-config=$PWD/logical/$2.nix:$NIX_PATH"
  38. eval "${@:3}"
  39. ;;
  40. ssh)
  41. TARGET_HOST=$(jq -r ".$2.host"<servers.json)
  42. ssh root@"$TARGET_HOST"
  43. ;;
  44. repl)
  45. exec "$0" exec "$2" nix repl "\\<nixpkgs\\>" "\\<nixpkgs/nixos\\>"
  46. ;;
  47. build)
  48. exec "$0" exec "$2" nixos-rebuild build
  49. ;;
  50. copy)
  51. TARGET_HOST=$(jq -r ".$2.host"<servers.json)
  52. exec "$0" exec "$2" nixos-rebuild build --build-host localhost --target-host root@"$TARGET_HOST"
  53. ;;
  54. boot)
  55. TARGET_HOST=$(jq -r ".$2.host"<servers.json)
  56. exec "$0" exec "$2" nixos-rebuild --build-host localhost --target-host root@"$TARGET_HOST" boot
  57. ;;
  58. switch)
  59. TARGET_HOST=$(jq -r ".$2.host"<servers.json)
  60. exec "$0" exec "$2" nixos-rebuild --build-host localhost --target-host root@"$TARGET_HOST" switch
  61. ;;
  62. esac