From bad9b8a06b1e24f732a32c5122af14d435e549ea Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Fri, 24 Sep 2021 00:18:19 +0200 Subject: [PATCH 1/8] lib: modules: document 'mapModules' --- lib/modules.nix | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/modules.nix b/lib/modules.nix index 92e8476..455015b 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -5,6 +5,14 @@ let inherit (self.attrs) mapFilterAttrs; in { + # 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 = dir: fn: mapFilterAttrs (n: v: From 8467fda721733b881d81c9cee250a2860c365e09 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Fri, 24 Sep 2021 00:54:00 +0200 Subject: [PATCH 2/8] lib: modules: refactor 'mapModules' Introduce the recursive version of this function, then refactor to reduce repetition. --- lib/modules.nix | 49 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 15 deletions(-) diff --git a/lib/modules.nix b/lib/modules.nix index 455015b..5b8c4c3 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -3,6 +3,31 @@ 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 { # Find all nix modules in a directory, discard any prefixed with "_", @@ -13,19 +38,13 @@ in # path # (path -> any) # attrs - 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); + mapModules = implOptionalRecursion false; + + # Recursive version of mapModules. + # + # mapModulesRec :: + # path + # (path -> any) + # attrs + mapModulesRec = implOptionalRecursion true; } From 604b99a7ac6ab29e38aa2d01bdb40ebaeb170701 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Fri, 24 Sep 2021 00:57:46 +0200 Subject: [PATCH 3/8] lib: remove 'with self;' --- lib/default.nix | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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: From 9d362655e20dc368a5993859e26fb3b0bf1ff047 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Fri, 24 Sep 2021 01:01:29 +0200 Subject: [PATCH 4/8] pkgs: remove unused arguments --- pkgs/nolimips/default.nix | 2 +- pkgs/unbound-zones-adblock/default.nix | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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; From 68be7743adbcf23f50d16f633dce74201720a243 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Fri, 24 Sep 2021 01:04:34 +0200 Subject: [PATCH 5/8] machines: remove unused arguments --- machines/aramis/default.nix | 2 +- machines/aramis/services.nix | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 = { From 75312c747bbeb7a831361de50f2fdca6d7f7a13a Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Fri, 24 Sep 2021 01:15:40 +0200 Subject: [PATCH 6/8] modules: remove unused arguments --- modules/hardware/upower.nix | 2 +- modules/services/paperless.nix | 2 +- modules/services/podgrab.nix | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) 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 From 3d10461a6e716094c1011bbc4883feffda0f111d Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Fri, 24 Sep 2021 01:16:04 +0200 Subject: [PATCH 7/8] home: remove unused arguments --- home/mail/msmtp.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 673ead7863bec924ffc3ba7c971423c9b5d02e27 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Fri, 24 Sep 2021 01:13:23 +0200 Subject: [PATCH 8/8] home: ssh: add missing 'mkIf cfg.enable' --- home/ssh.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 = {