feat(modules): add declarations (#198)

This commit is contained in:
seth 2024-05-28 02:15:28 -06:00 committed by GitHub
parent ed79a45b47
commit 296adaf933
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 188 additions and 76 deletions

View file

@ -6,6 +6,8 @@ Create a file in `modules/<module>/` with the name of the port. All ports should
the `catppuccin.enable` and `catppuccin.flavor` options, and optionally the the `catppuccin.enable` and `catppuccin.flavor` options, and optionally the
`catppuccin.accent` option. `catppuccin.flavor` and `catppuccin.accent` should `catppuccin.accent` option. `catppuccin.flavor` and `catppuccin.accent` should
default to `config.catppuccin.flavor` and `config.catppuccin.accent`, respectively. default to `config.catppuccin.flavor` and `config.catppuccin.accent`, respectively.
When you're done, make sure to add your new file to the list in
`modules/<module>/all-modules.nix`
[npins](https://github.com/andir/npins) is used to track our upstream [npins](https://github.com/andir/npins) is used to track our upstream
sources to use in modules. This allows us to easily access and auto-update all themes. sources to use in modules. This allows us to easily access and auto-update all themes.

View file

@ -105,12 +105,12 @@
{ {
nixos-doc = mkOptionDoc { nixos-doc = mkOptionDoc {
inherit version; inherit version;
modules = [ ../modules/nixos ]; moduleRoot = ../modules/nixos;
}; };
home-manager-doc = mkOptionDoc { home-manager-doc = mkOptionDoc {
inherit version; inherit version;
modules = [ ../modules/home-manager ]; moduleRoot = ../modules/home-manager;
}; };
site = mkSite { site = mkSite {

View file

@ -1,9 +1,25 @@
{ lib, nixosOptionsDoc }: { lib, nixosOptionsDoc }:
{ version, modules }: {
(nixosOptionsDoc { version,
options = modules ? [ moduleRoot ],
builtins.removeAttrs moduleRoot,
(lib.evalModules { }:
let
baseDeclarationUrl = "https://github.com/catppuccin/nix/blob/main";
declarationIsOurs = declaration: lib.hasPrefix (toString moduleRoot) (toString declaration);
declarationSubpath = declaration: lib.removePrefix (toString ../. + "/") (toString declaration);
toGithubDeclaration =
declaration:
let
subpath = declarationSubpath declaration;
in
{
url = "${baseDeclarationUrl}/${subpath}";
name = "<catppuccin/${subpath}>";
};
evaluated = lib.evalModules {
modules = modules ++ [ modules = modules ++ [
{ {
options.system.nixos.release = lib.mkOption { options.system.nixos.release = lib.mkOption {
@ -17,14 +33,25 @@
}; };
} }
]; ];
}).options };
[
optionsDoc = nixosOptionsDoc {
options = builtins.removeAttrs evaluated.options [
"_module" "_module"
"system" "system"
]; ];
transformOptions = opt: builtins.removeAttrs opt [ "declarations" ]; transformOptions =
opt:
opt
// {
declarations = map (
declaration: if declarationIsOurs declaration then toGithubDeclaration declaration else declaration
) opt.declarations;
};
documentType = "none"; documentType = "none";
revision = version; revision = version;
}).optionsCommonMark };
in
optionsDoc.optionsCommonMark

View file

@ -0,0 +1,43 @@
[
./alacritty.nix
./bat.nix
./bottom.nix
./btop.nix
./cava.nix
./delta.nix
./dunst.nix
./fcitx5.nix
./fish.nix
./foot.nix
./fzf.nix
./gh-dash.nix
./gitui.nix
./glamour.nix
./globals.nix
./gtk.nix
./helix.nix
./hyprland.nix
./imv.nix
./k9s.nix
./kitty.nix
./kvantum.nix
./lazygit.nix
./mako.nix
./micro.nix
./mpv.nix
./neovim.nix
./polybar.nix
./rio.nix
./rofi.nix
./skim.nix
./starship.nix
./swaylock.nix
./sway.nix
./tmux.nix
./tofi.nix
./waybar.nix
./yazi.nix
./zathura.nix
./zellij.nix
./zsh-syntax-highlighting.nix
]

View file

@ -1,4 +1,12 @@
{ lib, pkgs, ... }@args:
{ {
imports = import ../lib/mkImports.nix args ./.; config,
lib,
pkgs,
...
}:
{
imports = import ../lib/import-modules.nix {
inherit config lib pkgs;
modules = import ./all-modules.nix;
};
} }

View file

@ -1,4 +1,4 @@
{ lib, defaultSources, ... }: { lib, ... }:
{ {
options.catppuccin = { options.catppuccin = {
enable = lib.mkEnableOption "Catppuccin globally"; enable = lib.mkEnableOption "Catppuccin globally";
@ -15,7 +15,11 @@
description = "Global Catppuccin accent"; description = "Global Catppuccin accent";
}; };
sources = lib.mkOption { sources =
let
defaultSources = import ../../.sources;
in
lib.mkOption {
type = lib.types.lazyAttrsOf lib.types.raw; type = lib.types.lazyAttrsOf lib.types.raw;
default = defaultSources; default = defaultSources;
defaultText = "{ ... }"; defaultText = "{ ... }";

View file

@ -0,0 +1,19 @@
{
modules,
config,
lib,
pkgs,
...
}:
let
toModule = file: {
_file = file;
imports = [
(import file {
inherit config pkgs;
lib = import ./mk-ext-lib.nix { inherit config lib pkgs; };
})
];
};
in
map toModule modules

View file

@ -0,0 +1,14 @@
{
config,
lib,
pkgs,
...
}:
lib.extend (
final: _: {
ctp = import ./. {
inherit config pkgs;
lib = final;
};
}
)

View file

@ -1,24 +0,0 @@
# this imports all files in a directory (besides default.nix)
# with our modified arguments
{ lib, pkgs, ... }@args:
dir:
let
# instead of letting `evalModules` pass arguments to each file
# in our list, we import them directly
applyImports =
file: _:
import "${dir}/${file}" (
args
// {
lib = lib.extend (final: _: { ctp = import ./. (args // { lib = final; }); });
defaultSources = import ../../.sources;
}
);
in
lib.pipe dir [
builtins.readDir
builtins.attrNames
(lib.remove "default.nix")
(map applyImports)
]

View file

@ -0,0 +1,7 @@
[
./console.nix
./globals.nix
./grub.nix
./plymouth.nix
./sddm.nix
]

View file

@ -1,4 +1,12 @@
{ lib, pkgs, ... }@args:
{ {
imports = import ../lib/mkImports.nix args ./.; config,
lib,
pkgs,
...
}:
{
imports = import ../lib/import-modules.nix {
inherit config lib pkgs;
modules = import ./all-modules.nix;
};
} }

View file

@ -1,4 +1,4 @@
{ lib, defaultSources, ... }: { lib, ... }:
{ {
options.catppuccin = { options.catppuccin = {
enable = lib.mkEnableOption "Catppuccin globally"; enable = lib.mkEnableOption "Catppuccin globally";
@ -15,7 +15,11 @@
description = "Global Catppuccin accent"; description = "Global Catppuccin accent";
}; };
sources = lib.mkOption { sources =
let
defaultSources = import ../../.sources;
in
lib.mkOption {
type = lib.types.lazyAttrsOf lib.types.raw; type = lib.types.lazyAttrsOf lib.types.raw;
default = defaultSources; default = defaultSources;
defaultText = "{ ... }"; defaultText = "{ ... }";