Compare commits

...

8 commits

Author SHA1 Message Date
Alejandro Soto e7972bf1e8
modules/thinkpad: initial commit 2025-08-06 14:25:43 -06:00
Alejandro Soto 0d37194fab
doctrine/lib: add optional prefix/namespace args to mkModule 2025-08-06 14:25:27 -06:00
Alejandro Soto 7c1071e396
doctrine/lib: support module dependencies 2025-08-06 14:23:32 -06:00
Alejandro Soto 026da8a6d1
modules/laptop: initial commit 2025-08-06 14:15:41 -06:00
Alejandro Soto 64ba64b857
doctrine/lib: rename importAll.nix -> import-all.nix 2025-08-06 14:05:49 -06:00
Alejandro Soto 4d7cf46c34
doctrine/lib: refactor 'close' helper 2025-08-06 14:04:59 -06:00
Alejandro Soto a8ef8e43b9
modules/yubico: initialcommit 2025-08-06 13:57:25 -06:00
Alejandro Soto 5d375d1d93
modules: automatically import all modules 2025-08-06 13:56:54 -06:00
11 changed files with 142 additions and 21 deletions

View file

@ -3,8 +3,18 @@
doctrine, doctrine,
pkgs, pkgs,
}: let }: 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 { in {
importAll = pkgs.callPackage ./importAll.nix {}; inherit close;
mkModule = close (import ./mk-module.nix); importAll = closeLib ./import-all.nix;
mkModule = closeFull ./mk-module.nix;
} }

View file

@ -1,6 +1,7 @@
{lib}: { {
lib,
root, root,
exclude ? [], exclude ? ["default"],
}: }:
with builtins; with builtins;
with lib; with lib;
@ -10,7 +11,7 @@ with lib;
isMatch = name: type: isMatch = name: type:
(hasSuffix ".nix" name || type == "directory") (hasSuffix ".nix" name || type == "directory")
&& ! elem name (map basename exclude); && ! elem (basename name) exclude;
entry = name: _: { entry = name: _: {
name = basename name; name = basename name;

View file

@ -1,18 +1,22 @@
{ {
# The first few arguments are implicitly passed by the 'close' helper
lib,
pkgs,
doctrine,
name, name,
config,
hm ? null, hm ? null,
sys ? null, sys ? null,
options ? null, options ? null,
lib, requires ? [],
config, prefix ? doctrine.prefix,
pkgs, namespace ? doctrine.namespace,
doctrine,
}: let }: let
optionsSet = import options { optionsSet = import options {
inherit config lib pkgs cfg name doctrine; inherit config lib pkgs cfg name doctrine;
}; };
configSet = import configFiles.${doctrine.namespace} { configSet = import configFiles.${namespace} {
inherit config lib pkgs doctrine cfg; inherit config lib pkgs doctrine cfg;
}; };
@ -20,17 +24,27 @@
inherit sys hm; inherit sys hm;
}; };
cfg = config.${doctrine.prefix}.${name}; cfg = config.${prefix}.${name};
in { in {
config = config =
lib.optionalAttrs (configFiles ? ${doctrine.namespace}) lib.optionalAttrs (configFiles ? ${namespace})
(lib.mkIf cfg.enable configSet); (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 options = lib.optionalAttrs (options
!= null != null
&& optionsSet ? ${doctrine.namespace}) { && optionsSet ? ${namespace}) {
${doctrine.prefix}.${name} = ${prefix}.${name} =
optionsSet.${doctrine.namespace} optionsSet.${namespace}
// { // {
enable = lib.mkEnableOption name; enable = lib.mkEnableOption name;
}; };

View file

@ -1,5 +1,3 @@
{ {doctrine, ...}: {
imports = [ imports = builtins.attrValues (doctrine.lib.importAll {root = ./.;});
./sway
];
} }

View file

@ -0,0 +1,10 @@
{
config,
doctrine,
...
}:
doctrine.lib.mkModule {
inherit config;
name = "laptop";
sys = ./sys.nix;
}

11
modules/laptop/sys.nix Normal file
View file

@ -0,0 +1,11 @@
{
config,
lib,
pkgs,
...
}: {
services = {
tlp.enable = lib.mkDefault true;
upower.enable = lib.mkDefault true;
};
}

View file

@ -0,0 +1,11 @@
{
config,
doctrine,
...
}:
doctrine.lib.mkModule {
inherit config;
name = "thinkpad";
sys = ./sys.nix;
requires = ["laptop"];
}

30
modules/thinkpad/sys.nix Normal file
View file

@ -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;
};
}

View file

@ -0,0 +1,13 @@
{
config,
lib,
pkgs,
doctrine,
...
}:
doctrine.lib.mkModule {
inherit config;
name = "yubico";
hm = ./hm.nix;
sys = ./sys.nix;
}

9
modules/yubico/hm.nix Normal file
View file

@ -0,0 +1,9 @@
{
pkgs,
lib,
...
}: {
home.packages = [
pkgs.yubikey-manager
];
}

14
modules/yubico/sys.nix Normal file
View file

@ -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];
};
}