[Nix-dev] Re: [Nix-commits] SVN commit: nix - 16409 - eelco - in nixos/branches/modular-nixos/modules: . services/networking

Tony White tonywhite100 at googlemail.com
Fri Jul 17 01:36:36 CEST 2009


2009/7/16 Ludovic Courtès <ludo at gnu.org>:
> Hello,
>
> Eelco Dolstra <e.dolstra at tudelft.nl> writes:
>
>> +      description = ''
>> +        Whether to start <command>wpa_supplicant</command> to scan for
>> +        and associate with wireless networks.  Note: NixOS currently
>> +        does not generate <command>wpa_supplicant</command>'s
>> +        configuration file, <filename>${configFile}</filename>.  You
>> +        should edit this file yourself to define wireless networks,
>> +        WPA keys and so on (see
>> +        <citerefentry><refentrytitle>wpa_supplicant.conf</refentrytitle>
>> +        <manvolnum>5</manvolnum></citerefentry>).
>> +      '';
>
> Hmm, you recommend mutating files under /etc?  But that's evvviiil,
> isn't it?
>
> Ludo'.
> _______________________________________________
> nix-dev mailing list
> nix-dev at cs.uu.nl
> https://mail.cs.uu.nl/mailman/listinfo/nix-dev
>

Hi,
I've already created a solution to this here that uses /etc and unless
some one knows how to hide the key used to generate
wpa_supplicant.conf or whatever it is named, I vote just make it work.
Also maybe bare in mind that the wpa_supplicant gui program will
probably create wpa_supplicant.conf in /etc too.

configuration.nix :

	  networking = {

	  hostName = "localhost";
	  interfaces = [

	  # Interface eth1 - ipw2100

	  {
	  name = "eth1";
	  essid = "\"13 Padstow Avenue\"";

	  # Added wpa support!

	  wpaKey = "/etc/wpa_supplicant.conf";
	  }


	  ];	# End interfaces entries

	  };	# End networking entries

# And the firmware for said adapter

	  udev = {
	  addFirmware = [

	  # Warning: setting pkgs.ipw2100fw requires acceptance of the firmware
	  # license, see http://ipw2100.sourceforge.net/firmware.php?fid=4.

	  pkgs.ipw2100fw
	  ];

	  };	# End udev entries


Then in /etc/nixos/nixos/upstart-jobs/network-interfaces.nix :

{nettools, modprobe, wirelesstools, wpa_supplicant, bash, writeText, config}:

let

  cfg = config.networking;

  # !!! use XML
  names = map (i: i.name) cfg.interfaces;
  ipAddresses = map (i: if i ? ipAddress then i.ipAddress else "dhcp")
cfg.interfaces;
  subnetMasks = map (i: if i ? subnetMask then i.subnetMask else
"default") cfg.interfaces;
  essids = map (i: if i ? essid then i.essid else "default") cfg.interfaces;
  wepKeys = map (i: if i ? wepKey then i.wepKey else "nokey") cfg.interfaces;
  wpaKeys = map (i: if i ? wpaKey then i.wpaKey else "false") cfg.interfaces;

in

{
  name = "network-interfaces";

  job = ''
    start on udev
    stop on shutdown

    start script
        export PATH=${modprobe}/sbin:$PATH
        modprobe af_packet || true

        for i in $(cd /sys/class/net && ls -d *); do
            echo "Bringing up network device $i..."
            ${nettools}/sbin/ifconfig $i up || true
        done

        # Configure the manually specified interfaces.
        names=(${toString names})
        ipAddresses=(${toString ipAddresses})
        subnetMasks=(${toString subnetMasks})
        essids=(${toString essids})
        wepKeys=(${toString wepKeys})
        wpaKeys=(${toString wpaKeys})

        for ((n = 0; n < ''${#names[*]}; n++)); do
            name=''${names[$n]}
            ipAddress=''${ipAddresses[$n]}
            subnetMask=''${subnetMasks[$n]}
            essid=''${essids[$n]}
            wepKey=''${wepKeys[$n]}
            wpaKey=''${wpaKeys[$n]}

            # Set wireless networking stuff.
            if test "$essid" != default; then
                ${wirelesstools}/sbin/iwconfig "$name" essid "$essid" || true
            fi

            if test "$wepKey" != nokey; then
                ${wirelesstools}/sbin/iwconfig "$name" key "$(cat
"$wepKey")" || true
            fi

            if test "$wpaKey" != false; then

	    ${wpa_supplicant}/sbin/wpa_supplicant -B -D wext -i "$name" -c
"$wpaKey" || true

	    # Use the code :
	    # wpa_passphrase "myssid" mypassphrase > /etc/wpa_supplicant.conf
	    # first, to generate a configuration.

            fi

            # Set IP address / netmask.
            if test "$ipAddress" != dhcp; then
                echo "Configuring interface $name..."
                extraFlags=
                if test "$subnetMask" != default; then
                    extraFlags="$extraFlags netmask $subnetMask"
                fi
                ${nettools}/sbin/ifconfig "$name" "$ipAddress"
$extraFlags || true
            fi

        done

        # Set the nameservers.
        if test -n "${toString cfg.nameservers}"; then
            rm -f /etc/resolv.conf
            if test -n "${cfg.domain}"; then
                echo "domain ${cfg.domain}" >> /etc/resolv.conf
            fi
            for i in ${toString cfg.nameservers}; do
                echo "nameserver $i" >> /etc/resolv.conf
            done
        fi

        # Set the default gateway.
        if test -n "${cfg.defaultGateway}"; then
            ${nettools}/sbin/route add default gw
"${cfg.defaultGateway}" || true
        fi

        # Run any user-specified commands.
        ${bash}/bin/sh ${writeText "local-net-cmds" cfg.localCommands} || true

    end script

    # Hack: Upstart doesn't yet support what we want: a service that
    # doesn't have a running process associated with it.
    respawn sleep 100000

    stop script
        for i in $(cd /sys/class/net && ls -d *); do
            echo "Taking down network device $i..."
            ${nettools}/sbin/ifconfig $i down || true
        done
    end script
  '';

}



I guess creating an expression for each key would be one other way to
approach it but tying that in with the wpa_supplicant expression maybe
could lead to interface misconfiguration on systems that actually use
/etc/wpa_supplicant.conf?

Anyway, I have wpa working here, every boot with the above alterations.
As soon as I establish a better working environment, I will be able to
share some of the hacking I've been doing here directly by committing.
That is, if you guys permit me. :)

Thanks,

Tony



More information about the nix-dev mailing list