From 5d375d1d930631b960393b8de12eae16abbe01e0 Mon Sep 17 00:00:00 2001 From: Alejandro Soto Date: Wed, 6 Aug 2025 13:56:34 -0600 Subject: [PATCH 1/8] modules: automatically import all modules --- doctrine/lib/importAll.nix | 4 ++-- modules/default.nix | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/doctrine/lib/importAll.nix b/doctrine/lib/importAll.nix index 6acabe9..03c5330 100644 --- a/doctrine/lib/importAll.nix +++ b/doctrine/lib/importAll.nix @@ -1,6 +1,6 @@ {lib}: { root, - exclude ? [], + exclude ? ["default"], }: with builtins; with lib; @@ -10,7 +10,7 @@ with lib; isMatch = name: type: (hasSuffix ".nix" name || type == "directory") - && ! elem name (map basename exclude); + && ! elem (basename name) exclude; entry = name: _: { name = basename name; diff --git a/modules/default.nix b/modules/default.nix index bd5d292..0c0fd4c 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -1,5 +1,3 @@ -{ - imports = [ - ./sway - ]; +{doctrine, ...}: { + imports = builtins.attrValues (doctrine.lib.importAll {root = ./.;}); } From a8ef8e43b913adea7131ee678a4467e62b70d9b1 Mon Sep 17 00:00:00 2001 From: Alejandro Soto Date: Wed, 6 Aug 2025 13:57:25 -0600 Subject: [PATCH 2/8] modules/yubico: initialcommit --- modules/yubico/default.nix | 13 +++++++++++++ modules/yubico/hm.nix | 9 +++++++++ modules/yubico/sys.nix | 14 ++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 modules/yubico/default.nix create mode 100644 modules/yubico/hm.nix create mode 100644 modules/yubico/sys.nix diff --git a/modules/yubico/default.nix b/modules/yubico/default.nix new file mode 100644 index 0000000..71bed70 --- /dev/null +++ b/modules/yubico/default.nix @@ -0,0 +1,13 @@ +{ + config, + lib, + pkgs, + doctrine, + ... +}: +doctrine.lib.mkModule { + inherit config; + name = "yubico"; + hm = ./hm.nix; + sys = ./sys.nix; +} diff --git a/modules/yubico/hm.nix b/modules/yubico/hm.nix new file mode 100644 index 0000000..8d06368 --- /dev/null +++ b/modules/yubico/hm.nix @@ -0,0 +1,9 @@ +{ + pkgs, + lib, + ... +}: { + home.packages = [ + pkgs.yubikey-manager + ]; +} diff --git a/modules/yubico/sys.nix b/modules/yubico/sys.nix new file mode 100644 index 0000000..3cd009f --- /dev/null +++ b/modules/yubico/sys.nix @@ -0,0 +1,14 @@ +{ + pkgs, + lib, + ... +}: { + environment.etc."pkcs11/modules/ykcs11".text = '' + module: ${pkgs.yubico-piv-tool}/lib/libykcs11.so + ''; + + services = { + pcscd.enable = true; + udev.packages = [pkgs.yubikey-personalization]; + }; +} From 4d7cf46c341ca828bb0258524878739a7bf2376d Mon Sep 17 00:00:00 2001 From: Alejandro Soto Date: Wed, 6 Aug 2025 13:58:07 -0600 Subject: [PATCH 3/8] doctrine/lib: refactor 'close' helper --- doctrine/lib/default.nix | 16 +++++++++++++--- doctrine/lib/importAll.nix | 3 ++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/doctrine/lib/default.nix b/doctrine/lib/default.nix index 1b03fe1..331141d 100644 --- a/doctrine/lib/default.nix +++ b/doctrine/lib/default.nix @@ -3,8 +3,18 @@ doctrine, pkgs, }: let - close = f: args: f (args // {inherit lib pkgs doctrine;}); + close = vars: f: args: + ( + if builtins.isPath f + then import f + else f + ) + (args // {inherit lib pkgs doctrine;}); + + closeLib = close {inherit lib;}; + closeFull = close {inherit lib pkgs doctrine;}; in { - importAll = pkgs.callPackage ./importAll.nix {}; - mkModule = close (import ./mk-module.nix); + inherit close; + importAll = closeLib ./importAll.nix; + mkModule = closeFull ./mk-module.nix; } diff --git a/doctrine/lib/importAll.nix b/doctrine/lib/importAll.nix index 03c5330..423dd9c 100644 --- a/doctrine/lib/importAll.nix +++ b/doctrine/lib/importAll.nix @@ -1,4 +1,5 @@ -{lib}: { +{ + lib, root, exclude ? ["default"], }: From 64ba64b8571d2e84a9e81465cbe8d0e1d2c74d0c Mon Sep 17 00:00:00 2001 From: Alejandro Soto Date: Wed, 6 Aug 2025 14:05:49 -0600 Subject: [PATCH 4/8] doctrine/lib: rename importAll.nix -> import-all.nix --- doctrine/lib/default.nix | 2 +- doctrine/lib/{importAll.nix => import-all.nix} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename doctrine/lib/{importAll.nix => import-all.nix} (100%) diff --git a/doctrine/lib/default.nix b/doctrine/lib/default.nix index 331141d..116bbb8 100644 --- a/doctrine/lib/default.nix +++ b/doctrine/lib/default.nix @@ -15,6 +15,6 @@ closeFull = close {inherit lib pkgs doctrine;}; in { inherit close; - importAll = closeLib ./importAll.nix; + importAll = closeLib ./import-all.nix; mkModule = closeFull ./mk-module.nix; } diff --git a/doctrine/lib/importAll.nix b/doctrine/lib/import-all.nix similarity index 100% rename from doctrine/lib/importAll.nix rename to doctrine/lib/import-all.nix From 026da8a6d1502552af4c95a30f51e30b7155f832 Mon Sep 17 00:00:00 2001 From: Alejandro Soto Date: Wed, 6 Aug 2025 14:15:41 -0600 Subject: [PATCH 5/8] modules/laptop: initial commit --- modules/laptop/default.nix | 10 ++++++++++ modules/laptop/sys.nix | 11 +++++++++++ 2 files changed, 21 insertions(+) create mode 100644 modules/laptop/default.nix create mode 100644 modules/laptop/sys.nix diff --git a/modules/laptop/default.nix b/modules/laptop/default.nix new file mode 100644 index 0000000..b908d47 --- /dev/null +++ b/modules/laptop/default.nix @@ -0,0 +1,10 @@ +{ + config, + doctrine, + ... +}: +doctrine.lib.mkModule { + inherit config; + name = "laptop"; + sys = ./sys.nix; +} diff --git a/modules/laptop/sys.nix b/modules/laptop/sys.nix new file mode 100644 index 0000000..252f49c --- /dev/null +++ b/modules/laptop/sys.nix @@ -0,0 +1,11 @@ +{ + config, + lib, + pkgs, + ... +}: { + services = { + tlp.enable = lib.mkDefault true; + upower.enable = lib.mkDefault true; + }; +} From 7c1071e396e1c81a165cfe34a9aa6a90637d693b Mon Sep 17 00:00:00 2001 From: Alejandro Soto Date: Wed, 6 Aug 2025 14:23:00 -0600 Subject: [PATCH 6/8] doctrine/lib: support module dependencies --- doctrine/lib/mk-module.nix | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/doctrine/lib/mk-module.nix b/doctrine/lib/mk-module.nix index 79c24c5..78449fe 100644 --- a/doctrine/lib/mk-module.nix +++ b/doctrine/lib/mk-module.nix @@ -1,12 +1,14 @@ { + # The first few arguments are implicitly passed by the 'close' helper + lib, + pkgs, + doctrine, name, + config, hm ? null, sys ? null, options ? null, - lib, - config, - pkgs, - doctrine, + requires ? [], }: let optionsSet = import options { inherit config lib pkgs cfg name doctrine; @@ -24,7 +26,17 @@ in { config = lib.optionalAttrs (configFiles ? ${doctrine.namespace}) - (lib.mkIf cfg.enable configSet); + (lib.mkIf cfg.enable (lib.mkMerge [ + configSet + { + assertions = + map (dependency: { + assertion = cfg.enable -> config.${doctrine.prefix}.${dependency}.enable; + message = "${doctrine.prefix}.${name}.enable requires ${doctrine.prefix}.${dependency}.enable"; + }) + requires; + } + ])); options = lib.optionalAttrs (options != null From 0d37194faba1155e4c1ef5775a88de39e5ef6672 Mon Sep 17 00:00:00 2001 From: Alejandro Soto Date: Wed, 6 Aug 2025 14:25:27 -0600 Subject: [PATCH 7/8] doctrine/lib: add optional prefix/namespace args to mkModule --- doctrine/lib/mk-module.nix | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/doctrine/lib/mk-module.nix b/doctrine/lib/mk-module.nix index 78449fe..e72ca08 100644 --- a/doctrine/lib/mk-module.nix +++ b/doctrine/lib/mk-module.nix @@ -9,12 +9,14 @@ sys ? null, options ? null, requires ? [], + prefix ? doctrine.prefix, + namespace ? doctrine.namespace, }: let optionsSet = import options { inherit config lib pkgs cfg name doctrine; }; - configSet = import configFiles.${doctrine.namespace} { + configSet = import configFiles.${namespace} { inherit config lib pkgs doctrine cfg; }; @@ -22,17 +24,17 @@ inherit sys hm; }; - cfg = config.${doctrine.prefix}.${name}; + cfg = config.${prefix}.${name}; in { config = - lib.optionalAttrs (configFiles ? ${doctrine.namespace}) + lib.optionalAttrs (configFiles ? ${namespace}) (lib.mkIf cfg.enable (lib.mkMerge [ configSet { assertions = map (dependency: { - assertion = cfg.enable -> config.${doctrine.prefix}.${dependency}.enable; - message = "${doctrine.prefix}.${name}.enable requires ${doctrine.prefix}.${dependency}.enable"; + assertion = cfg.enable -> config.${prefix}.${dependency}.enable; + message = "${prefix}.${name}.enable requires ${prefix}.${dependency}.enable"; }) requires; } @@ -40,9 +42,9 @@ in { options = lib.optionalAttrs (options != null - && optionsSet ? ${doctrine.namespace}) { - ${doctrine.prefix}.${name} = - optionsSet.${doctrine.namespace} + && optionsSet ? ${namespace}) { + ${prefix}.${name} = + optionsSet.${namespace} // { enable = lib.mkEnableOption name; }; From e7972bf1e8b10b41f63627b2b70c30996158a57b Mon Sep 17 00:00:00 2001 From: Alejandro Soto Date: Wed, 6 Aug 2025 14:25:43 -0600 Subject: [PATCH 8/8] modules/thinkpad: initial commit --- modules/thinkpad/default.nix | 11 +++++++++++ modules/thinkpad/sys.nix | 30 ++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 modules/thinkpad/default.nix create mode 100644 modules/thinkpad/sys.nix diff --git a/modules/thinkpad/default.nix b/modules/thinkpad/default.nix new file mode 100644 index 0000000..e210947 --- /dev/null +++ b/modules/thinkpad/default.nix @@ -0,0 +1,11 @@ +{ + config, + doctrine, + ... +}: +doctrine.lib.mkModule { + inherit config; + name = "thinkpad"; + sys = ./sys.nix; + requires = ["laptop"]; +} diff --git a/modules/thinkpad/sys.nix b/modules/thinkpad/sys.nix new file mode 100644 index 0000000..bc96146 --- /dev/null +++ b/modules/thinkpad/sys.nix @@ -0,0 +1,30 @@ +{ + config, + pkgs, + lib, + ... +}: { + # For suspending to RAM to work, set Config -> Power -> Sleep State to "Linux" in EFI. + # See https://wiki.archlinux.org/index.php/Lenovo_ThinkPad_X1_Carbon_(Gen_6)#Suspend_issues + # Fingerprint sensor requires a firmware-update to work. + + boot = { + extraModulePackages = with config.boot.kernelPackages; [acpi_call]; + extraModprobeConfig = "options iwlwifi 11n_disable=1 wd_disable=1"; + + # acpi_call makes tlp work for newer thinkpads + kernelModules = ["acpi_call"]; + + # Force use of the thinkpad_acpi driver for backlight control. + # This allows the backlight save/load systemd service to work. + kernelParams = ["acpi_backlight=native"]; + }; + + hardware.firmware = [pkgs.sof-firmware]; + + services = { + fprintd.enable = lib.mkDefault true; + thinkfan.enable = lib.mkDefault true; + tp-auto-kbbl.enable = lib.mkDefault true; + }; +}