From e45a44e26e9a9b15525a67d782e2d3c1ca04dff8 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Mon, 22 Apr 2024 19:39:12 +0200 Subject: [PATCH] feat(modules): add global `enable` option (#124) * feat: add `enable` option globally * chore(modules): use catppuccin.enable in test.nix --------- Co-authored-by: seth --- dev/flake.lock | 16 ----- dev/flake.nix | 11 ++-- modules/home-manager/globals.nix | 2 + modules/lib/default.nix | 4 +- modules/nixos/globals.nix | 2 + test.nix | 109 +++++++++++++++---------------- 6 files changed, 64 insertions(+), 80 deletions(-) diff --git a/dev/flake.lock b/dev/flake.lock index 66a0809..654e45d 100644 --- a/dev/flake.lock +++ b/dev/flake.lock @@ -1,20 +1,5 @@ { "nodes": { - "get-flake": { - "locked": { - "lastModified": 1694475786, - "narHash": "sha256-s5wDmPooMUNIAAsxxCMMh9g68AueGg63DYk2hVZJbc8=", - "owner": "ursi", - "repo": "get-flake", - "rev": "ac54750e3b95dab6ec0726d77f440efe6045bec1", - "type": "github" - }, - "original": { - "owner": "ursi", - "repo": "get-flake", - "type": "github" - } - }, "home-manager": { "inputs": { "nixpkgs": [ @@ -52,7 +37,6 @@ }, "root": { "inputs": { - "get-flake": "get-flake", "home-manager": "home-manager", "nixpkgs": "nixpkgs" } diff --git a/dev/flake.nix b/dev/flake.nix index aeb44c9..bbedb34 100644 --- a/dev/flake.nix +++ b/dev/flake.nix @@ -8,11 +8,9 @@ url = "github:nix-community/home-manager"; inputs.nixpkgs.follows = "nixpkgs"; }; - - get-flake.url = "github:ursi/get-flake"; }; - outputs = { self, nixpkgs, get-flake, ... }@inputs: + outputs = { self, nixpkgs, ... }@inputs: let systems = [ "x86_64-linux" @@ -24,11 +22,10 @@ inherit (nixpkgs) lib; forAllSystems = fn: lib.genAttrs systems (s: fn nixpkgs.legacyPackages.${s}); - ctp = get-flake ../.; in { checks = forAllSystems (pkgs: lib.optionalAttrs pkgs.stdenv.isLinux { - module-vm-test = pkgs.nixosTest (import ../test.nix { inherit ctp inputs; }); + module-vm-test = pkgs.nixosTest (import ../test.nix inputs); }); formatter = forAllSystems (pkgs: pkgs.nixpkgs-fmt); @@ -57,8 +54,8 @@ ''; in { - nixos-doc = mkDoc "nixos" ctp.nixosModules.catppuccin; - home-manager-doc = mkDoc "home-manager" ctp.homeManagerModules.catppuccin; + nixos-doc = mkDoc "nixos" ../modules/nixos; + home-manager-doc = mkDoc "home-manager" ../modules/home-manager; default = self.packages.${pkgs.system}.home-manager-doc; }); diff --git a/modules/home-manager/globals.nix b/modules/home-manager/globals.nix index 259cd99..f39367a 100644 --- a/modules/home-manager/globals.nix +++ b/modules/home-manager/globals.nix @@ -1,5 +1,7 @@ { lib, ... }: { options.catppuccin = { + enable = lib.mkEnableOption "Catppuccin globally"; + flavour = lib.mkOption { type = lib.ctp.types.flavourOption; default = "latte"; diff --git a/modules/lib/default.nix b/modules/lib/default.nix index 5735929..9a3beb3 100644 --- a/modules/lib/default.nix +++ b/modules/lib/default.nix @@ -105,7 +105,9 @@ in # be the name of the module, followed by the local config # attrset mkCatppuccinOpt = name: { - enable = lib.mkEnableOption "Catppuccin theme"; + enable = lib.mkEnableOption "Catppuccin theme" // { + default = config.catppuccin.enable; + }; flavour = mkFlavourOpt name; }; diff --git a/modules/nixos/globals.nix b/modules/nixos/globals.nix index 63ea819..5f0ddc9 100644 --- a/modules/nixos/globals.nix +++ b/modules/nixos/globals.nix @@ -1,5 +1,7 @@ { lib, ... }: { options.catppuccin = { + enable = lib.mkEnableOption "Catppuccin globally"; + flavour = lib.mkOption { type = lib.ctp.types.flavourOption; default = "latte"; diff --git a/test.nix b/test.nix index 2ac98d1..67ac478 100644 --- a/test.nix +++ b/test.nix @@ -1,36 +1,35 @@ -{ ctp -, inputs -, ... -}: +inputs: let common = { - catppuccin.flavour = "mocha"; - users.users.test = { - isNormalUser = true; - home = "/home/test"; + catppuccin = { + enable = true; + flavour = "mocha"; }; }; - ctpEnable = { - enable = true; - catppuccin.enable = true; - }; + # shorthand enable + enable = { enable = true; }; in { name = "module-test"; nodes.machine = { lib, ... }: { imports = [ - ctp.nixosModules.catppuccin inputs.home-manager.nixosModules.default + ./modules/nixos common ]; - boot.loader.grub = ctpEnable; + boot.loader.grub = enable; - console = ctpEnable; + console = enable; - programs.dconf.enable = true; # required for gtk + programs.dconf = enable; # required for gtk + + users.users.test = { + isNormalUser = true; + home = "/home/test"; + }; virtualisation = { memorySize = 4096; @@ -39,11 +38,10 @@ in home-manager.users.test = { imports = [ - ctp.homeManagerModules.catppuccin + ./modules/home-manager + common ]; - inherit (common) catppuccin; - xdg.enable = true; home = { @@ -53,49 +51,48 @@ in manual.manpages.enable = lib.mkDefault false; - i18n.inputMethod = { - enabled = "fcitx5"; - fcitx5.catppuccin.enable = true; - }; + i18n.inputMethod.enabled = "fcitx5"; programs = { - alacritty = ctpEnable; - bat = ctpEnable; - bottom = ctpEnable; - btop = ctpEnable; - cava = ctpEnable; - fish = ctpEnable; - foot = ctpEnable; - fzf = ctpEnable; - git.enable = true; # Required for delta - git.delta = ctpEnable; - gitui = ctpEnable; + alacritty = enable; + bat = enable; + bottom = enable; + btop = enable; + cava = enable; + fish = enable; + foot = enable; + fzf = enable; + git = enable // { + delta = enable; + }; + gitui = enable; + # this is enabled by default already, but still + # listing explicitly so we know it's tested glamour.catppuccin.enable = true; - helix = ctpEnable; - home-manager.enable = false; - imv = ctpEnable; - k9s = ctpEnable; - kitty = ctpEnable; - lazygit = ctpEnable; - micro = ctpEnable; - mpv = ctpEnable; - neovim = ctpEnable; - rio = ctpEnable; - rofi = ctpEnable; - starship = ctpEnable; - swaylock = ctpEnable; - tmux = ctpEnable; - yazi = ctpEnable; - zathura = ctpEnable; + helix = enable; + imv = enable; + k9s = enable; + kitty = enable; + lazygit = enable; + micro = enable; + mpv = enable; + neovim = enable; + rio = enable; + rofi = enable; + starship = enable; + swaylock = enable; + tmux = enable; + yazi = enable; + zathura = enable; }; - gtk = lib.recursiveUpdate ctpEnable { catppuccin.cursor.enable = true; }; + gtk = lib.recursiveUpdate enable { catppuccin.cursor.enable = true; }; services = { - dunst = ctpEnable; - mako = ctpEnable; + dunst = enable; + mako = enable; polybar = - ctpEnable + enable // { script = '' polybar top & @@ -103,8 +100,8 @@ in }; }; - wayland.windowManager.sway = ctpEnable; - wayland.windowManager.hyprland = ctpEnable; + wayland.windowManager.sway = enable; + wayland.windowManager.hyprland = enable; }; };