From 55f2e625ec9b8801c603565327f64ec7eb4c757b Mon Sep 17 00:00:00 2001 From: Daylin Morgan Date: Thu, 21 Mar 2024 10:53:27 -0500 Subject: [PATCH] reduce boilerplate with mkOizysModule --- lib/extended.nix | 7 +++++- modules/desktop/fonts.nix | 3 +-- modules/desktop/gui.nix | 3 +-- modules/desktop/window-managers/hyprland.nix | 11 +++------- modules/editors/vscode.nix | 3 +-- modules/networking/vpn.nix | 13 +++-------- modules/programs/chrome/default.nix | 10 +++------ modules/storage/restic.nix | 11 ++++------ modules/virtualization/docker.nix | 23 +++++++++++++------- modules/virtualization/virtualbox.nix | 12 ++++------ 10 files changed, 41 insertions(+), 55 deletions(-) diff --git a/lib/extended.nix b/lib/extended.nix index a381906..aa4dc49 100644 --- a/lib/extended.nix +++ b/lib/extended.nix @@ -1,5 +1,5 @@ final: prev: let - inherit (final) hasSuffix; + inherit (final) hasSuffix mkEnableOption mkIf; runes = import ../modules/runes; in rec { enabled = {enable = true;}; @@ -28,4 +28,9 @@ in rec { runeKind ? "braille", }: "[1;3${number}m\n" + runes.${rune}.${runeKind} + "\n"; + + mkOizysModule = config: attr: content: { + options.oizys.${attr}.enable = mkEnableOption "enable ${attr} support"; + config = mkIf config.oizys.${attr}.enable content; + }; } diff --git a/modules/desktop/fonts.nix b/modules/desktop/fonts.nix index 0922e00..dd3d0c9 100644 --- a/modules/desktop/fonts.nix +++ b/modules/desktop/fonts.nix @@ -5,9 +5,8 @@ ... }: let inherit (lib) mkIf; - cfg = config.oizys.desktop; in { - config = mkIf cfg.enable { + config = mkIf config.oizys.desktop.enable { fonts.fontconfig.enable = true; fonts.packages = with pkgs; [ (nerdfonts.override {fonts = ["FiraCode"];}) diff --git a/modules/desktop/gui.nix b/modules/desktop/gui.nix index 6677bdc..74e4c45 100644 --- a/modules/desktop/gui.nix +++ b/modules/desktop/gui.nix @@ -5,9 +5,8 @@ ... }: let inherit (lib) mkIf; - cfg = config.oizys.desktop; in { - config = mkIf cfg.enable { + config = mkIf config.oizys.desktop.enable { environment.systemPackages = with pkgs; [ wezterm alacritty diff --git a/modules/desktop/window-managers/hyprland.nix b/modules/desktop/window-managers/hyprland.nix index 0746ee8..c67c1d7 100644 --- a/modules/desktop/window-managers/hyprland.nix +++ b/modules/desktop/window-managers/hyprland.nix @@ -5,9 +5,7 @@ lib, ... }: let - inherit (lib) mkIf; - cfg = config.programs.hyprland; - + inherit (lib) mkOizysModule; lock = pkgs.writeShellApplication { name = "lock"; runtimeInputs = with pkgs; [swaylock]; @@ -15,10 +13,8 @@ swaylock -c 1e1e2e ''; }; -in { - config = mkIf cfg.enable { +in mkOizysModule config "hyprland" { security.pam.services.swaylock = {}; - # programs.hyprland.package = inputs.hyprland.packages.${pkgs.system}.default; # Optional, hint electron apps to use wayland: environment.sessionVariables.NIXOS_OZONE_WL = "1"; @@ -52,5 +48,4 @@ in { inputs.nixpkgs-wayland.overlay inputs.hyprland.overlays.default ]; - }; -} + } diff --git a/modules/editors/vscode.nix b/modules/editors/vscode.nix index 6102c4c..37f9f4e 100644 --- a/modules/editors/vscode.nix +++ b/modules/editors/vscode.nix @@ -5,9 +5,8 @@ ... }: let inherit (lib) mkIf; - cfg = config.oizys.desktop; in { - config = mkIf cfg.enable { + config = mkIf config.oizys.desktop.enable { environment.systemPackages = with pkgs; [ # vscode vscode-fhs diff --git a/modules/networking/vpn.nix b/modules/networking/vpn.nix index 685c847..f150972 100644 --- a/modules/networking/vpn.nix +++ b/modules/networking/vpn.nix @@ -4,14 +4,7 @@ pkgs, ... }: let - inherit (lib) mkEnableOption mkIf; - cfg = config.oizys.vpn; -in { - options.oizys.vpn.enable = mkEnableOption '' - Whether to enable openconnect for vpn connection. - ''; - - config = mkIf cfg.enable { + inherit (lib) mkOizysModule; +in mkOizysModule config "vpn" { environment.systemPackages = [pkgs.openconnect]; - }; -} + } diff --git a/modules/programs/chrome/default.nix b/modules/programs/chrome/default.nix index f65cfe1..050aaa9 100644 --- a/modules/programs/chrome/default.nix +++ b/modules/programs/chrome/default.nix @@ -4,11 +4,8 @@ lib, ... }: let - inherit (lib) mkIf mkEnableOption; - cfg = config.oizys.chrome; -in { - options.oizys.chrome.enable = mkEnableOption "enable chrome + extensions"; - config = mkIf cfg.enable { + inherit (lib) mkOizysModule; +in mkOizysModule config "chrome" { programs.chromium = { enable = true; @@ -29,5 +26,4 @@ in { ]; }) ]; - }; -} + } diff --git a/modules/storage/restic.nix b/modules/storage/restic.nix index 1037f7e..80d3918 100644 --- a/modules/storage/restic.nix +++ b/modules/storage/restic.nix @@ -4,11 +4,9 @@ lib, ... }: let - inherit (lib) mkEnableOption mkIf; - cfg = config.oizys.backups; -in { - options.oizys.backups.enable = mkEnableOption "enable restic/rclone backups"; - config = mkIf cfg.enable { + inherit (lib) mkOizysModule; +in + mkOizysModule config "backups" { environment.systemPackages = with pkgs; [rclone]; services.restic.backups.gdrive = { @@ -36,5 +34,4 @@ in { RandomizedDelaySec = "5h"; }; }; - }; -} + } diff --git a/modules/virtualization/docker.nix b/modules/virtualization/docker.nix index b4c6066..e1bf5f4 100644 --- a/modules/virtualization/docker.nix +++ b/modules/virtualization/docker.nix @@ -4,15 +4,22 @@ lib, ... }: let - inherit (lib) mkEnableOption mkIf; - cfg = config.oizys.docker; -in { - options.oizys.docker.enable = mkEnableOption "enable docker support"; - - config = mkIf cfg.enable { + inherit (lib) mkOizysModule; +in + mkOizysModule config "docker" { virtualisation.docker.enable = true; environment.systemPackages = with pkgs; [ lazydocker ]; - }; -} + } +# in { +# options.oizys.docker.enable = mkEnableOption "enable docker support"; +# +# config = mkIf cfg.enable { +# virtualisation.docker.enable = true; +# environment.systemPackages = with pkgs; [ +# lazydocker +# ]; +# }; +# } + diff --git a/modules/virtualization/virtualbox.nix b/modules/virtualization/virtualbox.nix index 5080525..5e3f3c8 100644 --- a/modules/virtualization/virtualbox.nix +++ b/modules/virtualization/virtualbox.nix @@ -3,15 +3,11 @@ lib, ... }: let - inherit (lib) mkEnableOption mkIf; - cfg = config.oizys.vbox; -in { - options.oizys.vbox.enable = mkEnableOption "enable virtualbox host"; - - config = mkIf cfg.enable { + inherit (lib) mkOizysModule; +in + mkOizysModule config "vbox" { virtualisation.virtualbox = { host.enable = true; }; users.extraGroups.vboxusers.members = ["daylin"]; - }; -} + }