summary refs log tree commit diff
path: root/nixos/modules/config
diff options
context:
space:
mode:
authorAntoine R. Dumont <antoine.romain.dumont@gmail.com>2014-11-19 20:13:54 +0100
committerLuca Bruno <lucabru@src.gnome.org>2014-11-30 15:19:25 +0100
commit3c7e77960282dcf550fc2df8445c7da3ee27fb3c (patch)
tree35409f1f24b84e23ff90d93c798f5e2cd4038e37 /nixos/modules/config
parent92448fb3ae608c8236140a13cbff635a9133dc86 (diff)
downloadnixpkgs-3c7e77960282dcf550fc2df8445c7da3ee27fb3c.tar
nixpkgs-3c7e77960282dcf550fc2df8445c7da3ee27fb3c.tar.gz
nixpkgs-3c7e77960282dcf550fc2df8445c7da3ee27fb3c.tar.bz2
nixpkgs-3c7e77960282dcf550fc2df8445c7da3ee27fb3c.tar.lz
nixpkgs-3c7e77960282dcf550fc2df8445c7da3ee27fb3c.tar.xz
nixpkgs-3c7e77960282dcf550fc2df8445c7da3ee27fb3c.tar.zst
nixpkgs-3c7e77960282dcf550fc2df8445c7da3ee27fb3c.zip
Introduce a dedicated networking.proxy option
Following the discussion NixOS#5021:
- obsolete the nix.proxy option
- add the networking.proxy option
- open a default no_proxy environment variable
- add a rsync option
- Manual tests ok.
- Automatic tests ok.

Amended by lethalman to simplify the option descriptions.
Diffstat (limited to 'nixos/modules/config')
-rw-r--r--nixos/modules/config/networking.nix88
1 files changed, 87 insertions, 1 deletions
diff --git a/nixos/modules/config/networking.nix b/nixos/modules/config/networking.nix
index 773d0b1f1a7..b908f95df17 100644
--- a/nixos/modules/config/networking.nix
+++ b/nixos/modules/config/networking.nix
@@ -39,6 +39,73 @@ in
       '';
     };
 
+    networking.proxy = {
+
+      default = lib.mkOption {
+        type = types.nullOr types.str;
+        default = null;
+        description = ''
+          This option specifies the default value for httpProxy, httpsProxy, ftpProxy and rsyncProxy.
+        '';
+        example = "http://127.0.0.1:3128";
+      };
+
+      httpProxy = lib.mkOption {
+        type = types.nullOr types.str;
+        default = cfg.proxy.default;
+        description = ''
+          This option specifies the http_proxy environment variable.
+        '';
+        example = "http://127.0.0.1:3128";
+      };
+
+      httpsProxy = lib.mkOption {
+        type = types.nullOr types.str;
+        default = cfg.proxy.default;
+        description = ''
+          This option specifies the https_proxy environment variable.
+        '';
+        example = "http://127.0.0.1:3128";
+      };
+
+      ftpProxy = lib.mkOption {
+        type = types.nullOr types.str;
+        default = cfg.proxy.default;
+        description = ''
+          This option specifies the ftp_proxy environment variable.
+        '';
+        example = "http://127.0.0.1:3128";
+      };
+
+      rsyncProxy = lib.mkOption {
+        type = types.nullOr types.str;
+        default = cfg.proxy.default;
+        description = ''
+          This option specifies the rsync_proxy environment variable.
+        '';
+        example = "http://127.0.0.1:3128";
+      };
+
+      noProxy = lib.mkOption {
+        type = types.nullOr types.str;
+        default = null;
+        description = ''
+          This option specifies the no_proxy environment variable.
+          If a default proxy is used and noProxy is null,
+          then noProxy will be set to 127.0.0.1,localhost.
+        '';
+        example = "127.0.0.1,localhost,.localdomain";
+      };
+
+      envVars = lib.mkOption {
+        type = types.attrs;
+        internal = true;
+        default = {};
+        description = ''
+          Environment variables used for the network proxy.
+        '';
+      };
+    };
   };
 
   config = {
@@ -93,6 +160,25 @@ in
         }
       ));
 
+      networking.proxy.envVars =
+        optionalAttrs (cfg.proxy.default != null) {
+          # other options already fallback to proxy.default
+          no_proxy = "127.0.0.1,localhost";
+        } // optionalAttrs (cfg.proxy.httpProxy != null) {
+          http_proxy  = cfg.proxy.httpProxy;
+        } // optionalAttrs (cfg.proxy.httpsProxy != null) {
+          https_proxy = cfg.proxy.httpsProxy;
+        } // optionalAttrs (cfg.proxy.rsyncProxy != null) {
+          rsync_proxy = cfg.proxy.rsyncProxy;
+        } // optionalAttrs (cfg.proxy.ftpProxy != null) {
+          ftp_proxy   = cfg.proxy.ftpProxy;
+        } // optionalAttrs (cfg.proxy.noProxy != null) {
+          no_proxy    = cfg.proxy.noProxy;
+        };
+
+    # Install the proxy environment variables
+    environment.sessionVariables = config.networking.proxy.envVars;
+
     # The ‘ip-up’ target is started when we have IP connectivity.  So
     # services that depend on IP connectivity (like ntpd) should be
     # pulled in by this target.
@@ -120,4 +206,4 @@ in
 
   };
 
-}
+  }