|
| 1 | +{ |
| 2 | + config, |
| 3 | + lib, |
| 4 | + pkgs, |
| 5 | + ... |
| 6 | +}: |
| 7 | + |
| 8 | +let |
| 9 | + cfg = config.programs.saml2aws; |
| 10 | + iniFormat = pkgs.formats.ini { }; |
| 11 | + inherit (lib) mkIf mkOption types; |
| 12 | +in |
| 13 | +{ |
| 14 | + meta.maintainers = [ lib.maintainers.mokrinsky ]; |
| 15 | + |
| 16 | + options.programs.saml2aws = { |
| 17 | + enable = lib.mkEnableOption "saml2aws CLI tool"; |
| 18 | + |
| 19 | + package = lib.mkPackageOption pkgs "saml2aws" { |
| 20 | + default = "saml2aws"; |
| 21 | + nullable = true; |
| 22 | + }; |
| 23 | + |
| 24 | + enableBashIntegration = lib.hm.shell.mkBashIntegrationOption { |
| 25 | + inherit config; |
| 26 | + extraDescription = ''If enabled, this will install autocompletion for bash.''; |
| 27 | + }; |
| 28 | + |
| 29 | + enableZshIntegration = lib.hm.shell.mkZshIntegrationOption { |
| 30 | + inherit config; |
| 31 | + extraDescription = ''If enabled, this will install autocompletion for zsh.''; |
| 32 | + }; |
| 33 | + |
| 34 | + configLocation = mkOption { |
| 35 | + default = "${config.home.homeDirectory}/.saml2aws"; |
| 36 | + type = types.str; |
| 37 | + example = lib.literalExpression '' |
| 38 | + ''${config.home.homeDirectory}/.config/.saml2aws |
| 39 | + ''; |
| 40 | + description = '' |
| 41 | + Environment variable to specify the location of saml2aws configuration. |
| 42 | + ''; |
| 43 | + }; |
| 44 | + |
| 45 | + credentials = mkOption { |
| 46 | + type = types.submodule { freeformType = iniFormat.type; }; |
| 47 | + default = { }; |
| 48 | + example = lib.literalExpression '' |
| 49 | + { |
| 50 | + aws = { |
| 51 | + name = "aws"; |
| 52 | + url = "https://domain.tld/uri/of/your/auth/endpoint"; |
| 53 | + username = "username"; |
| 54 | + provider = "Authentik"; |
| 55 | + mfa = "Auto"; |
| 56 | + skip_verify = false; |
| 57 | + timeout = 0; |
| 58 | + aws_urn = "urn:amazon:webservices"; |
| 59 | + aws_session_duration = 3600; |
| 60 | + aws_profile = "123456789000"; |
| 61 | + saml_cache = false; |
| 62 | + disable_remember_device = false; |
| 63 | + disable_sessions = false; |
| 64 | + download_browser_driver = false; |
| 65 | + headless = false; |
| 66 | + }; |
| 67 | + } |
| 68 | + ''; |
| 69 | + description = '' |
| 70 | + Configuration written to {file}`$HOME/.saml2aws` or config.programs.saml2aws.configLocation. |
| 71 | + ''; |
| 72 | + }; |
| 73 | + }; |
| 74 | + |
| 75 | + config = mkIf cfg.enable { |
| 76 | + home = { |
| 77 | + packages = mkIf (cfg.package != null) [ cfg.package ]; |
| 78 | + |
| 79 | + sessionVariables.SAML2AWS_CONFIGFILE = cfg.configLocation; |
| 80 | + |
| 81 | + file."${cfg.configLocation}" = mkIf (cfg.credentials != { }) { |
| 82 | + source = iniFormat.generate "saml2aws-credentials-${config.home.username}" cfg.credentials; |
| 83 | + }; |
| 84 | + }; |
| 85 | + |
| 86 | + programs.bash.initExtra = mkIf cfg.enableBashIntegration '' |
| 87 | + eval "$(${lib.getExe cfg.package} --completion-script-bash)" |
| 88 | + ''; |
| 89 | + |
| 90 | + programs.zsh.initContent = mkIf cfg.enableZshIntegration '' |
| 91 | + eval "$(${lib.getExe cfg.package} --completion-script-zsh)" |
| 92 | + ''; |
| 93 | + |
| 94 | + }; |
| 95 | +} |
0 commit comments