otm.nix 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. {
  2. config,
  3. lib,
  4. pkgs,
  5. ...
  6. }:
  7. let
  8. zscaler-cert = ''
  9. -----BEGIN CERTIFICATE-----
  10. MIIE0zCCA7ugAwIBAgIJANu+mC2Jt3uTMA0GCSqGSIb3DQEBCwUAMIGhMQswCQYD
  11. VQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTERMA8GA1UEBxMIU2FuIEpvc2Ux
  12. FTATBgNVBAoTDFpzY2FsZXIgSW5jLjEVMBMGA1UECxMMWnNjYWxlciBJbmMuMRgw
  13. FgYDVQQDEw9ac2NhbGVyIFJvb3QgQ0ExIjAgBgkqhkiG9w0BCQEWE3N1cHBvcnRA
  14. enNjYWxlci5jb20wHhcNMTQxMjE5MDAyNzU1WhcNNDIwNTA2MDAyNzU1WjCBoTEL
  15. MAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExETAPBgNVBAcTCFNhbiBK
  16. b3NlMRUwEwYDVQQKEwxac2NhbGVyIEluYy4xFTATBgNVBAsTDFpzY2FsZXIgSW5j
  17. LjEYMBYGA1UEAxMPWnNjYWxlciBSb290IENBMSIwIAYJKoZIhvcNAQkBFhNzdXBw
  18. b3J0QHpzY2FsZXIuY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA
  19. qT7STSxZRTgEFFf6doHajSc1vk5jmzmM6BWuOo044EsaTc9eVEV/HjH/1DWzZtcr
  20. fTj+ni205apMTlKBW3UYR+lyLHQ9FoZiDXYXK8poKSV5+Tm0Vls/5Kb8mkhVVqv7
  21. LgYEmvEY7HPY+i1nEGZCa46ZXCOohJ0mBEtB9JVlpDIO+nN0hUMAYYdZ1KZWCMNf
  22. 5J/aTZiShsorN2A38iSOhdd+mcRM4iNL3gsLu99XhKnRqKoHeH83lVdfu1XBeoQz
  23. z5V6gA3kbRvhDwoIlTBeMa5l4yRdJAfdpkbFzqiwSgNdhbxTHnYYorDzKfr2rEFM
  24. dsMU0DHdeAZf711+1CunuQIDAQABo4IBCjCCAQYwHQYDVR0OBBYEFLm33UrNww4M
  25. hp1d3+wcBGnFTpjfMIHWBgNVHSMEgc4wgcuAFLm33UrNww4Mhp1d3+wcBGnFTpjf
  26. oYGnpIGkMIGhMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTERMA8G
  27. A1UEBxMIU2FuIEpvc2UxFTATBgNVBAoTDFpzY2FsZXIgSW5jLjEVMBMGA1UECxMM
  28. WnNjYWxlciBJbmMuMRgwFgYDVQQDEw9ac2NhbGVyIFJvb3QgQ0ExIjAgBgkqhkiG
  29. 9w0BCQEWE3N1cHBvcnRAenNjYWxlci5jb22CCQDbvpgtibd7kzAMBgNVHRMEBTAD
  30. AQH/MA0GCSqGSIb3DQEBCwUAA4IBAQAw0NdJh8w3NsJu4KHuVZUrmZgIohnTm0j+
  31. RTmYQ9IKA/pvxAcA6K1i/LO+Bt+tCX+C0yxqB8qzuo+4vAzoY5JEBhyhBhf1uK+P
  32. /WVWFZN/+hTgpSbZgzUEnWQG2gOVd24msex+0Sr7hyr9vn6OueH+jj+vCMiAm5+u
  33. kd7lLvJsBu3AO3jGWVLyPkS3i6Gf+rwAp1OsRrv3WnbkYcFf9xjuaf4z0hRCrLN2
  34. xFNjavxrHmsH8jPHVvgc1VD0Opja0l/BRVauTrUaoW6tE+wFG5rEcPGS80jjHK4S
  35. pB5iDj2mUZH1T8lzYtuZy0ZPirxmtsk3135+CKNa2OCAhhFjE0xd
  36. -----END CERTIFICATE-----
  37. '';
  38. internal-cert = ''
  39. -----BEGIN CERTIFICATE-----
  40. MIIDpzCCAo+gAwIBAgIRAPimIVPUvFeeWdKoTVr/KaowDQYJKoZIhvcNAQELBQAw
  41. bTELMAkGA1UEBhMCR0IxGDAWBgNVBAoMD29udGhlbWFya2V0LmNvbTELMAkGA1UE
  42. CwwCSVQxDzANBgNVBAgMBkxvbmRvbjEVMBMGA1UEAwwMaW50ZXJuYWwub3RtMQ8w
  43. DQYDVQQHDAZMb25kb24wHhcNMjQwNTIxMTIyNTUzWhcNMzQwNTIxMTMyNTQ1WjBt
  44. MQswCQYDVQQGEwJHQjEYMBYGA1UECgwPb250aGVtYXJrZXQuY29tMQswCQYDVQQL
  45. DAJJVDEPMA0GA1UECAwGTG9uZG9uMRUwEwYDVQQDDAxpbnRlcm5hbC5vdG0xDzAN
  46. BgNVBAcMBkxvbmRvbjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAKMb
  47. +jxbONNYRWXFYLHOVsKkTBVY/SkPo9VYv63Xzp8YF5CC3GMNKVvtdfwDLxdB4yDE
  48. 71kOngybxIRTeX+UdZCfhmcgpmu6trT8RB27SzpOVkrVz+wCzYx/3qE4xSQok474
  49. komOtHkuwoL1MMqTH1WOPqUL3RaNkK3YSq2M8JPfjG9w6eboT0i+c7GG9OEk9BwW
  50. 35M+tdiI9fjAK95yMU9DjVI7PqTfqBVT5pUoyzAKhTikZlC6O8X8U98NJojwhaT4
  51. RJcbbd1bdNqcxdpshIiP1kWAE4CKp2+tMzzz9yqwgQ1igbsm2j37TxI74JoEV9+k
  52. 95tFwgXLT7Bih3MFuI0CAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4E
  53. FgQUuA22mh+yV3W8D3mpiouhO2Y/2c4wDgYDVR0PAQH/BAQDAgGGMA0GCSqGSIb3
  54. DQEBCwUAA4IBAQCJgkhzAWW0Rh4EWyAdVIoUnjHIr032Qu61cXiNqvvRS9GIF5gs
  55. oynXjIIj2scBeNlkG3oSy0G3wWyFzng6ixwuol2fRhDsllvm2bgeaObdbccbLbWx
  56. 8OTobCqWTfZvEn8dYs7Qbx/9l4yBH6pYptnOmDt+Ze2hOVZyTuiVq91CEn+on9FG
  57. 2V6Bjuu8dNpz2CC8na7H4wsqUNRfBVSTSKgdeeiLj1zdueWgOtA1PNOZp5wi452U
  58. mpb61I1k/Xfe6ECUn8QEh9oEB4MprNvlvLVmmnstcBmqU9SvONtmSrn8ekI2OO69
  59. R7pRciveNTEVrJRPqOfL4fjfQbjtpKx6Gk5m
  60. -----END CERTIFICATE-----
  61. '';
  62. internal-staging-cert = ''
  63. -----BEGIN CERTIFICATE-----
  64. MIIDpzCCAo+gAwIBAgIRANXYUsUWHHGL/LgpcIY3zlUwDQYJKoZIhvcNAQELBQAw
  65. bTELMAkGA1UEBhMCR0IxGDAWBgNVBAoMD29udGhlbWFya2V0LmNvbTELMAkGA1UE
  66. CwwCSVQxDzANBgNVBAgMBkxvbmRvbjEVMBMGA1UEAwwMaW50ZXJuYWwub3RtMQ8w
  67. DQYDVQQHDAZMb25kb24wHhcNMjQwNTI0MDc1MDQ3WhcNMzQwNTI0MDg1MDQ0WjBt
  68. MQswCQYDVQQGEwJHQjEYMBYGA1UECgwPb250aGVtYXJrZXQuY29tMQswCQYDVQQL
  69. DAJJVDEPMA0GA1UECAwGTG9uZG9uMRUwEwYDVQQDDAxpbnRlcm5hbC5vdG0xDzAN
  70. BgNVBAcMBkxvbmRvbjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAImM
  71. FljdqdQ4M0tRYAiRU6WPWiIKFHwZSTsdLohNXikjnSar1xnN1LQLLH1mzPpztnpA
  72. eCnADo9Dc1Nsm+dt6WREL6n57oQSG3d5eM+br6MIm2qWIXQhtJtpKFcbSuOlaB4z
  73. uWNmk3R09+3GaGNhpYBmEbh3Nvc5it0/p6EUOVWigF3ghr0NO2JSOhPtGhNSPyyS
  74. 9Q7DZSwdaGeix9yKWKDh3X4ikZvjm4xqkogFFdyFHKA1qmsaCsT+NP1iH6HNb6pB
  75. xOb1ZyzR1EcFKAP+8uOgoI3bF0iJswNtkSc2kqf0vNQ+K/qoNL8OH7VyKCfeQqNL
  76. 2b8lV+FwHIBD2ZwhsuUCAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4E
  77. FgQUxbubUk2Kf9k68OUOSwrdgGuAtJYwDgYDVR0PAQH/BAQDAgGGMA0GCSqGSIb3
  78. DQEBCwUAA4IBAQBNRKzWrQQBh1RAU023u0pgNjfk0OV5mTlb2024jCLmqG7U/eSC
  79. X8LoO/Gm3yVuj5RsoH8H5ftNU1j71c+dHg7+UVvQZRCOfgVIMnPCxuMvcaljRnLG
  80. qHaRCra5G3IOLrBtJDg9DgKg6/gUbg5DvZwiO5J21yzJWxy6wmoRBmy43DZBa2RV
  81. /rO3WOM0uuMp4DHqBIYx55d+4mdtshikZoys3TCiFH3C11xrUwkIdNEqvMcjl/Pr
  82. 5WrzfbTpDzvo/GCkPhA0thVgUBx4LXB8HizVmDZgGbSuh7ic7LHyh1ahE0fqGX9C
  83. ZvHif3XTcAZlNkilVHvF3pM4EIosFEc6dHFy
  84. -----END CERTIFICATE-----
  85. '';
  86. aws-cert =
  87. (builtins.readFile "${pkgs.awscli2}/lib/python${pkgs.awscli2.python.pythonVersion}/site-packages/awscli/botocore/cacert.pem")
  88. + zscaler-cert;
  89. full-cert =
  90. (builtins.readFile /etc/ssl/cert.pem) + aws-cert + internal-cert + internal-staging-cert;
  91. zscaler-cert-file = pkgs.writeText "zscaler-cert.pem" zscaler-cert;
  92. aws-cert-file = pkgs.writeText "aws-cert.pem" aws-cert;
  93. full-cert-file = pkgs.writeText "full-cert.pem" full-cert;
  94. zscaler-jdk = pkgs.jdk.overrideAttrs (old: {
  95. # passthru.home must be set to ensure JAVA_HOME is set correctly
  96. # See https://github.com/nix-community/home-manager/blob/086f619dd991a4d355c07837448244029fc2d9ab/modules/programs/java.nix#L39-L41
  97. # and https://github.com/NixOS/nixpkgs/blob/4877ea239f4d02410c3516101faf35a81af0c30e/pkgs/development/compilers/openjdk/jre.nix#L32
  98. passthru.home = "${zscaler-jdk}"; # make sure JAVA_HOME is set
  99. installPhase =
  100. # This is probably equivalent to
  101. # $out/bin/keytool -import -noprompt -trustcacerts -alias zscalerrootca -keystore $out/lib/security/cacerts <<< "${zscaler-cert}"
  102. # but follow the zscaler instructions just in case
  103. old.installPhase
  104. + ''
  105. ${pkgs.openssl}/bin/openssl x509 -inform pem -outform der <<< "${zscaler-cert}" | $out/bin/keytool -import -noprompt -trustcacerts -alias zscalerrootca -keystore $out/lib/security/cacerts
  106. '';
  107. });
  108. zscaler-lein = pkgs.leiningen.override { jdk = zscaler-jdk; };
  109. zscaler-clojure = pkgs.clojure.override { jdk = zscaler-jdk; };
  110. toggle = pkgs.writeShellScriptBin "remote-toggle" ''
  111. ssh -nT pi "playerctl play-pause" 2>/dev/null
  112. '';
  113. in
  114. {
  115. imports = [ ./includes/darwin.nix ];
  116. # Let Home Manager install and manage itself.
  117. programs.home-manager.enable = true;
  118. # Home Manager needs a bit of information about you and the
  119. # paths it should manage.
  120. home.username = "dmorgan";
  121. home.homeDirectory = "/Users/dmorgan";
  122. home.sessionPath = [ "$HOME/.costar/auth2aws" ];
  123. home.sessionVariables = {
  124. AWS_DEFAULT_REGION = "eu-west-1";
  125. AWS_PROFILE = "aws_otm_dev_developers";
  126. AM_PROFILE = "staging";
  127. AWS_CA_BUNDLE = "${aws-cert-file}";
  128. CURL_CA_BUNDLE = "${full-cert-file}";
  129. NIX_SSL_CERT_FILE = "${full-cert-file}";
  130. NODE_EXTRA_CA_CERTS = "${zscaler-cert-file}";
  131. JVM_OPTS = "-Dcom.amazonaws.sdk.disableCertChecking";
  132. LEIN_JVM_OPTS = "-Dcom.amazonaws.sdk.disableCertChecking";
  133. };
  134. home.shellAliases = {
  135. notify_success = ''( osascript -e 'display notification "The command finished" with title "Success"' && afplay /System/Library/Sounds/Ping.aiff && say done )'';
  136. notify_failure = ''( osascript -e 'display notification "The command failed" with title "Failure"' && afplay /System/Library/Sounds/Sosumi.aiff && say failed )'';
  137. notify = "notify_success || notify_failure";
  138. auth = "auth2aws login -r aws_otm_dev_developers,aws_otm_prd_developers && osascript -e 'tell app \"iTerm\" to activate'";
  139. yarn_build = "aws codeartifact login --tool npm --repository otm-js --domain otm --domain-owner 103567893073 --region eu-west-1 --profile aws_otm_dev_developers && yarn && yarn build && notify";
  140. };
  141. home.packages = with pkgs; [
  142. zscaler-clojure
  143. zscaler-lein
  144. toggle
  145. ];
  146. home.file = {
  147. "certs/zscaler-cert.pem".source = zscaler-cert-file;
  148. "certs/aws-cert.pem".source = aws-cert-file;
  149. "certs/full-cert.pem".source = full-cert-file;
  150. "certs/internal-ca.pem".text = internal-cert;
  151. "certs/staging-internal-ca.pem".text = internal-staging-cert;
  152. ".skhdrc".text = "play : remote-toggle";
  153. };
  154. sops.secrets = {
  155. "git_email_config/otm" = { };
  156. "ssh_config/otm" = { };
  157. };
  158. programs.java = {
  159. enable = true;
  160. package = zscaler-jdk;
  161. };
  162. programs.git = {
  163. signing.signByDefault = lib.mkForce false;
  164. includes = lib.mkForce [
  165. { path = config.sops.secrets."git_email_config/otm".path; }
  166. {
  167. path = config.sops.secrets."git_email_config/default".path;
  168. condition = "gitdir:~/src/personal/";
  169. }
  170. {
  171. path = config.sops.secrets."git_email_config/default".path;
  172. condition = "gitdir:~/dotfiles/";
  173. }
  174. {
  175. contents = {
  176. commit.gpgSign = true;
  177. tag.gpgSign = true;
  178. };
  179. condition = "gitdir:~/src/personal/";
  180. }
  181. {
  182. contents = {
  183. commit.gpgSign = true;
  184. tag.gpgSign = true;
  185. };
  186. condition = "gitdir:~/dotfiles/";
  187. }
  188. ];
  189. extraConfig = {
  190. github.user = "david-morgan-otm";
  191. http.sslcainfo = "${full-cert-file}";
  192. };
  193. ignores = [
  194. ".envrc"
  195. ".clj-kondo"
  196. "shell.nix"
  197. ".direnv"
  198. ".dir-locals.el"
  199. "browser-tests/package-lock.json"
  200. "resources/react-app/package-lock.json"
  201. "resources/next/package-lock.json"
  202. ];
  203. };
  204. programs.ssh = {
  205. includes = [ config.sops.secrets."ssh_config/otm".path ];
  206. matchBlocks = {
  207. "github.com" = lib.mkForce {
  208. hostname = "github.com";
  209. user = "git";
  210. identityFile = "~/.ssh/id_rsa";
  211. identitiesOnly = true;
  212. };
  213. "github.com-personal" = {
  214. hostname = "github.com";
  215. user = "git";
  216. identityFile = "~/.ssh/id_ed25519";
  217. identitiesOnly = true;
  218. };
  219. };
  220. };
  221. # This value determines the Home Manager release that your
  222. # configuration is compatible with. This helps avoid breakage
  223. # when a new Home Manager release introduces backwards
  224. # incompatible changes.
  225. #
  226. # You can update Home Manager without changing this value. See
  227. # the Home Manager release notes for a list of state version
  228. # changes in each release.
  229. home.stateVersion = "21.11";
  230. }