Kieran's opinionated (and probably slightly dumb) nix config

chore: format

dunkirk.sh 017dc207 36588ee7

verified
Changed files
+78 -22
nixos
modules
apps
network
+1 -1
nixos/modules/apps/default.nix
···
imports = [
./tuigreet.nix
];
-
}
+
}
+77 -21
nixos/modules/network/wifi.nix
···
-
{ lib, config, pkgs, ... }:
+
{
+
lib,
+
config,
+
pkgs,
+
...
+
}:
let
cfg = config.modules.network.wifi;
-
mkProfile = name: p:
+
mkProfile =
+
name: p:
let
base = {
-
connection = { id = name; type = "wifi"; };
+
connection = {
+
id = name;
+
type = "wifi";
+
};
ipv4.method = "auto";
-
ipv6 = { addr-gen-mode = "stable-privacy"; method = "auto"; };
-
wifi = { mode = "infrastructure"; ssid = name; };
+
ipv6 = {
+
addr-gen-mode = "stable-privacy";
+
method = "auto";
+
};
+
wifi = {
+
mode = "infrastructure";
+
ssid = name;
+
};
};
sec =
-
if (p ? pskVar && p.pskVar != null) then { wifi-security = { key-mgmt = "wpa-psk"; psk = "$${" + p.pskVar + "}"; }; }
-
else if (p ? psk && p.psk != null) then { wifi-security = { key-mgmt = "wpa-psk"; psk = p.psk; }; }
-
else if (p ? pskFile && p.pskFile != null) then { wifi-security = { key-mgmt = "wpa-psk"; psk = "$(" + pkgs.coreutils + "/bin/cat " + p.pskFile + ")"; }; }
-
else {};
-
in base // sec;
+
if (p ? pskVar && p.pskVar != null) then
+
{
+
wifi-security = {
+
key-mgmt = "wpa-psk";
+
psk = "$${" + p.pskVar + "}";
+
};
+
}
+
else if (p ? psk && p.psk != null) then
+
{
+
wifi-security = {
+
key-mgmt = "wpa-psk";
+
psk = p.psk;
+
};
+
}
+
else if (p ? pskFile && p.pskFile != null) then
+
{
+
wifi-security = {
+
key-mgmt = "wpa-psk";
+
psk = "$(" + pkgs.coreutils + "/bin/cat " + p.pskFile + ")";
+
};
+
}
+
else
+
{ };
+
in
+
base // sec;
in
{
options.modules.network.wifi = {
enable = lib.mkEnableOption "Enable NetworkManager with simplified Wi-Fi profiles";
-
hostName = lib.mkOption { type = lib.types.str; default = config.networking.hostName or ""; };
-
nameservers = lib.mkOption { type = lib.types.listOf lib.types.str; default = []; };
+
hostName = lib.mkOption {
+
type = lib.types.str;
+
default = config.networking.hostName or "";
+
};
+
nameservers = lib.mkOption {
+
type = lib.types.listOf lib.types.str;
+
default = [ ];
+
};
envFile = lib.mkOption {
type = lib.types.nullOr lib.types.path;
default = null;
···
};
profiles = lib.mkOption {
-
type = lib.types.attrsOf (lib.types.submodule ({ name, ... }: {
-
options = {
-
pskVar = lib.mkOption { type = lib.types.nullOr lib.types.str; default = null; description = "Variable name in envFile providing PSK"; };
-
psk = lib.mkOption { type = lib.types.nullOr lib.types.str; default = null; };
-
pskFile = lib.mkOption { type = lib.types.nullOr lib.types.path; default = null; };
-
};
-
}));
-
default = {};
+
type = lib.types.attrsOf (
+
lib.types.submodule (
+
{ name, ... }:
+
{
+
options = {
+
pskVar = lib.mkOption {
+
type = lib.types.nullOr lib.types.str;
+
default = null;
+
description = "Variable name in envFile providing PSK";
+
};
+
psk = lib.mkOption {
+
type = lib.types.nullOr lib.types.str;
+
default = null;
+
};
+
pskFile = lib.mkOption {
+
type = lib.types.nullOr lib.types.path;
+
default = null;
+
};
+
};
+
}
+
)
+
);
+
default = { };
description = "Map of SSID -> { pskVar | psk | pskFile }.";
};
};
···
config = lib.mkIf cfg.enable {
networking = {
hostName = lib.mkIf (cfg.hostName != "") cfg.hostName;
-
nameservers = lib.mkIf (cfg.nameservers != []) cfg.nameservers;
+
nameservers = lib.mkIf (cfg.nameservers != [ ]) cfg.nameservers;
useDHCP = false;
dhcpcd.enable = false;
networkmanager = {