diff --git a/doctrine/lib/default.nix b/doctrine/lib/default.nix index 1b03fe1..116bbb8 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 ./import-all.nix; + mkModule = closeFull ./mk-module.nix; } diff --git a/doctrine/lib/importAll.nix b/doctrine/lib/import-all.nix similarity index 98% rename from doctrine/lib/importAll.nix rename to doctrine/lib/import-all.nix index 03c5330..423dd9c 100644 --- a/doctrine/lib/importAll.nix +++ b/doctrine/lib/import-all.nix @@ -1,4 +1,5 @@ -{lib}: { +{ + lib, root, exclude ? ["default"], }: diff --git a/doctrine/lib/mk-module.nix b/doctrine/lib/mk-module.nix index 79c24c5..e72ca08 100644 --- a/doctrine/lib/mk-module.nix +++ b/doctrine/lib/mk-module.nix @@ -1,18 +1,22 @@ { + # 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 ? [], + 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; }; @@ -20,17 +24,27 @@ inherit sys hm; }; - cfg = config.${doctrine.prefix}.${name}; + cfg = config.${prefix}.${name}; in { config = - lib.optionalAttrs (configFiles ? ${doctrine.namespace}) - (lib.mkIf cfg.enable configSet); + lib.optionalAttrs (configFiles ? ${namespace}) + (lib.mkIf cfg.enable (lib.mkMerge [ + configSet + { + assertions = + map (dependency: { + assertion = cfg.enable -> config.${prefix}.${dependency}.enable; + message = "${prefix}.${name}.enable requires ${prefix}.${dependency}.enable"; + }) + requires; + } + ])); options = lib.optionalAttrs (options != null - && optionsSet ? ${doctrine.namespace}) { - ${doctrine.prefix}.${name} = - optionsSet.${doctrine.namespace} + && optionsSet ? ${namespace}) { + ${prefix}.${name} = + optionsSet.${namespace} // { enable = lib.mkEnableOption name; }; 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; + }; +} 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; + }; +}