Skip to content

Commit

Permalink
feat(modules): add declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
getchoo committed May 28, 2024
1 parent f32e5ab commit b11f64d
Show file tree
Hide file tree
Showing 12 changed files with 188 additions and 76 deletions.
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
`catppuccin.accent` option. `catppuccin.flavor` and `catppuccin.accent` should
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
sources to use in modules. This allows us to easily access and auto-update all themes.
Expand Down
4 changes: 2 additions & 2 deletions dev/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@
{
nixos-doc = mkOptionDoc {
inherit version;
modules = [ ../modules/nixos ];
moduleRoot = ../modules/nixos;
};

home-manager-doc = mkOptionDoc {
inherit version;
modules = [ ../modules/home-manager ];
moduleRoot = ../modules/home-manager;
};

site = mkSite {
Expand Down
79 changes: 53 additions & 26 deletions docs/options-doc.nix
Original file line number Diff line number Diff line change
@@ -1,30 +1,57 @@
{ lib, nixosOptionsDoc }:
{ version, modules }:
(nixosOptionsDoc {
options =
builtins.removeAttrs
(lib.evalModules {
modules = modules ++ [
{
options.system.nixos.release = lib.mkOption {
type = lib.types.str;
default = lib.trivial.release;
readOnly = true;
};
{
version,
modules ? [ moduleRoot ],
moduleRoot,
}:
let
baseDeclarationUrl = "https://github.com/catppuccin/nix/blob/main";
declarationIsOurs = declaration: lib.hasPrefix (toString moduleRoot) (toString declaration);
declarationSubpath = declaration: lib.removePrefix (toString ../. + "/") (toString declaration);

config = {
_module.check = false;
};
}
];
}).options
[
"_module"
"system"
];
toGithubDeclaration =
declaration:
let
subpath = declarationSubpath declaration;
in
{
url = "${baseDeclarationUrl}/${subpath}";
name = "<catppuccin/${subpath}>";
};

transformOptions = opt: builtins.removeAttrs opt [ "declarations" ];
evaluated = lib.evalModules {
modules = modules ++ [
{
options.system.nixos.release = lib.mkOption {
type = lib.types.str;
default = lib.trivial.release;
readOnly = true;
};

documentType = "none";
revision = version;
}).optionsCommonMark
config = {
_module.check = false;
};
}
];
};

optionsDoc = nixosOptionsDoc {
options = builtins.removeAttrs evaluated.options [
"_module"
"system"
];

transformOptions =
opt:
opt
// {
declarations = map (
declaration: if declarationIsOurs declaration then toGithubDeclaration declaration else declaration
) opt.declarations;
};

documentType = "none";
revision = version;
};
in
optionsDoc.optionsCommonMark
43 changes: 43 additions & 0 deletions modules/home-manager/all-modules.nix
Original file line number Diff line number Diff line change
@@ -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
]
12 changes: 10 additions & 2 deletions modules/home-manager/default.nix
Original file line number Diff line number Diff line change
@@ -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;
};
}
24 changes: 14 additions & 10 deletions modules/home-manager/globals.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ lib, defaultSources, ... }:
{ lib, ... }:
{
options.catppuccin = {
enable = lib.mkEnableOption "Catppuccin globally";
Expand All @@ -15,14 +15,18 @@
description = "Global Catppuccin accent";
};

sources = lib.mkOption {
type = lib.types.lazyAttrsOf lib.types.raw;
default = defaultSources;
defaultText = "{ ... }";
# HACK!
# without this, overriding one source will delete all others. -@getchoo
apply = lib.recursiveUpdate defaultSources;
description = "Port sources used across all options";
};
sources =
let
defaultSources = import ../../.sources;
in
lib.mkOption {
type = lib.types.lazyAttrsOf lib.types.raw;
default = defaultSources;
defaultText = "{ ... }";
# HACK!
# without this, overriding one source will delete all others. -@getchoo
apply = lib.recursiveUpdate defaultSources;
description = "Port sources used across all options";
};
};
}
19 changes: 19 additions & 0 deletions modules/lib/import-modules.nix
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions modules/lib/mk-ext-lib.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
config,
lib,
pkgs,
...
}:
lib.extend (
final: _: {
ctp = import ./. {
inherit config pkgs;
lib = final;
};
}
)
24 changes: 0 additions & 24 deletions modules/lib/mkImports.nix

This file was deleted.

7 changes: 7 additions & 0 deletions modules/nixos/all-modules.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
./console.nix
./globals.nix
./grub.nix
./plymouth.nix
./sddm.nix
]
12 changes: 10 additions & 2 deletions modules/nixos/default.nix
Original file line number Diff line number Diff line change
@@ -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;
};
}
24 changes: 14 additions & 10 deletions modules/nixos/globals.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ lib, defaultSources, ... }:
{ lib, ... }:
{
options.catppuccin = {
enable = lib.mkEnableOption "Catppuccin globally";
Expand All @@ -15,14 +15,18 @@
description = "Global Catppuccin accent";
};

sources = lib.mkOption {
type = lib.types.lazyAttrsOf lib.types.raw;
default = defaultSources;
defaultText = "{ ... }";
# HACK!
# without this, overriding one source will delete all others. -@getchoo
apply = lib.recursiveUpdate defaultSources;
description = "Port sources used across all options";
};
sources =
let
defaultSources = import ../../.sources;
in
lib.mkOption {
type = lib.types.lazyAttrsOf lib.types.raw;
default = defaultSources;
defaultText = "{ ... }";
# HACK!
# without this, overriding one source will delete all others. -@getchoo
apply = lib.recursiveUpdate defaultSources;
description = "Port sources used across all options";
};
};
}

0 comments on commit b11f64d

Please sign in to comment.