diff --git a/home/mail/msmtp.nix b/home/mail/msmtp.nix index 3e725e8..c469982 100644 --- a/home/mail/msmtp.nix +++ b/home/mail/msmtp.nix @@ -1,4 +1,4 @@ -{ config, lib, pkgs, ... }: +{ config, lib, ... }: let cfg = config.my.home.mail.msmtp; in diff --git a/home/ssh.nix b/home/ssh.nix index 22f85d3..3bd7f28 100644 --- a/home/ssh.nix +++ b/home/ssh.nix @@ -7,7 +7,7 @@ in enable = mkDisableOption "ssh configuration"; }; - config.programs.ssh = { + config.programs.ssh = lib.mkIf cfg.enable { enable = true; matchBlocks = { diff --git a/lib/default.nix b/lib/default.nix index 9014f85..fa37c23 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -12,8 +12,7 @@ let }; mylib = makeExtensible (self: - with self; mapModules ./. - (file: import file { inherit self lib pkgs inputs; }) + mapModules ./. (file: import file { inherit self lib pkgs inputs; }) ); in mylib.extend (self: super: diff --git a/lib/modules.nix b/lib/modules.nix index 92e8476..5b8c4c3 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -3,21 +3,48 @@ let inherit (builtins) readDir pathExists; inherit (lib) hasPrefix hasSuffix nameValuePair removeSuffix; inherit (self.attrs) mapFilterAttrs; + + implOptionalRecursion = recurse: + let + recurseStep = + if recurse + then (n: path: fn: nameValuePair n (impl path fn)) + else (_: _: _: nameValuePair "" null); + impl = dir: fn: + mapFilterAttrs + (n: _: n != "" && !(hasPrefix "_" n)) + (n: v: + let + path = "${toString dir}/${n}"; + in + if v == "directory" + then + if pathExists "${path}/default.nix" + then nameValuePair n (fn path) + else recurseStep n path fn + else if v == "regular" && n != "default.nix" && hasSuffix ".nix" n + then nameValuePair (removeSuffix ".nix" n) (fn path) + else nameValuePair "" null) + (readDir dir); + in + impl; in { - mapModules = dir: fn: - mapFilterAttrs - (n: v: - v != null && - !(hasPrefix "_" n)) - (n: v: - let path = "${toString dir}/${n}"; in - if v == "directory" && pathExists "${path}/default.nix" - then nameValuePair n (fn path) - else if v == "regular" && - n != "default.nix" && - hasSuffix ".nix" n - then nameValuePair (removeSuffix ".nix" n) (fn path) - else nameValuePair "" null) - (readDir dir); + # Find all nix modules in a directory, discard any prefixed with "_", + # map a function to each resulting path, and generate an attribute set + # to associate module name to resulting value. + # + # mapModules :: + # path + # (path -> any) + # attrs + mapModules = implOptionalRecursion false; + + # Recursive version of mapModules. + # + # mapModulesRec :: + # path + # (path -> any) + # attrs + mapModulesRec = implOptionalRecursion true; } diff --git a/machines/aramis/default.nix b/machines/aramis/default.nix index 878f2c9..e2211f4 100644 --- a/machines/aramis/default.nix +++ b/machines/aramis/default.nix @@ -2,7 +2,7 @@ # your system. Help is available in the configuration.nix(5) man page # and in the NixOS manual (accessible by running ‘nixos-help’). -{ config, pkgs, ... }: +{ ... }: { imports = [ diff --git a/machines/aramis/services.nix b/machines/aramis/services.nix index 30dc47d..0287c30 100644 --- a/machines/aramis/services.nix +++ b/machines/aramis/services.nix @@ -1,4 +1,4 @@ -{ lib, ... }: +{ ... }: { config.my.services = { wireguard = { diff --git a/modules/hardware/upower.nix b/modules/hardware/upower.nix index f21b9d2..95fa282 100644 --- a/modules/hardware/upower.nix +++ b/modules/hardware/upower.nix @@ -1,4 +1,4 @@ -{ config, lib, pkgs, ... }: +{ config, lib, ... }: let cfg = config.my.hardware.upower; in diff --git a/modules/services/paperless.nix b/modules/services/paperless.nix index b4e1f44..0e29325 100644 --- a/modules/services/paperless.nix +++ b/modules/services/paperless.nix @@ -1,4 +1,4 @@ -{ config, lib, pkgs, ... }: +{ config, lib, ... }: let cfg = config.my.services.paperless; in diff --git a/modules/services/podgrab.nix b/modules/services/podgrab.nix index bc16178..9793d60 100644 --- a/modules/services/podgrab.nix +++ b/modules/services/podgrab.nix @@ -1,5 +1,5 @@ # A simple podcast fetcher -{ config, lib, pkgs, ... }: +{ config, lib, ... }: let cfg = config.my.services.podgrab; in diff --git a/pkgs/nolimips/default.nix b/pkgs/nolimips/default.nix index 2a1dc33..65d847d 100644 --- a/pkgs/nolimips/default.nix +++ b/pkgs/nolimips/default.nix @@ -1,4 +1,4 @@ -{ lib, fetchurl, gnulib, stdenv }: +{ lib, fetchurl, stdenv }: stdenv.mkDerivation rec { pname = "nolimips"; version = "0.11"; diff --git a/pkgs/unbound-zones-adblock/default.nix b/pkgs/unbound-zones-adblock/default.nix index 845c123..ecec917 100644 --- a/pkgs/unbound-zones-adblock/default.nix +++ b/pkgs/unbound-zones-adblock/default.nix @@ -1,4 +1,4 @@ -{ lib, fetchFromGitHub, gawk, stdenvNoCC, unified-hosts-lists }: +{ lib, gawk, stdenvNoCC, unified-hosts-lists }: stdenvNoCC.mkDerivation rec { name = "unbound-zones-adblock"; version = unified-hosts-lists.version;