Skip to content

Commit 44b8a2b

Browse files
committed
refactor(modules)!: auto import modules & improve passing of arguments
1 parent a0e5082 commit 44b8a2b

File tree

9 files changed

+55
-85
lines changed

9 files changed

+55
-85
lines changed

flake.nix

+3-10
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,6 @@
2222
inherit (nixpkgs) lib;
2323

2424
forAllSystems = fn: lib.genAttrs systems (s: fn nixpkgs.legacyPackages.${s});
25-
26-
sources = pkgs:
27-
let
28-
s =
29-
import ./_sources/generated.nix { inherit (pkgs) fetchgit fetchurl fetchFromGitHub dockerTools; };
30-
in
31-
builtins.mapAttrs (_: p: p.src) s;
3225
in
3326
{
3427
checks = forAllSystems (pkgs: lib.optionalAttrs pkgs.stdenv.isLinux {
@@ -37,9 +30,9 @@
3730

3831
formatter = forAllSystems (pkgs: pkgs.nixpkgs-fmt);
3932

40-
homeManagerModules.catppuccin = import ./modules/home-manager { inherit inputs sources; };
33+
homeManagerModules.catppuccin = import ./modules/home-manager;
4134

42-
nixosModules.catppuccin = import ./modules/nixos { inherit inputs sources; };
35+
nixosModules.catppuccin = import ./modules/nixos;
4336

4437
packages = forAllSystems (pkgs:
4538
let
@@ -60,7 +53,7 @@
6053
doc = pkgs.nixosOptionsDoc {
6154
options = lib.filterAttrs (n: _: n != "_module") (eval module).options;
6255
documentType = "none";
63-
revision = builtins.substring 0 7 self.rev or "dirty";
56+
revision = builtins.substring 0 8 self.rev or "dirty";
6457
};
6558
in
6659
pkgs.runCommand "${name}-module-doc.md" { } ''

modules/home-manager/default.nix

+2-43
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,4 @@
1-
{ inputs, ... }@flakeArgs: { lib, pkgs, ... }@systemArgs:
2-
let
3-
extendedLib = import ../lib/mkExtLib.nix inputs.nixpkgs.lib (flakeArgs // systemArgs);
4-
inherit (extendedLib) ctp;
5-
in
1+
{ lib, pkgs, ... }@args:
62
{
7-
imports =
8-
let
9-
files = [
10-
./alacritty.nix
11-
./bat.nix
12-
./bottom.nix
13-
./btop.nix
14-
./fish.nix
15-
./kitty.nix
16-
./lazygit.nix
17-
./starship.nix
18-
./helix.nix
19-
./hyprland.nix
20-
./glamour.nix
21-
./gtk.nix
22-
./mako.nix
23-
./neovim.nix
24-
./micro.nix
25-
./polybar.nix
26-
./sway.nix
27-
./tmux.nix
28-
./zathura.nix
29-
];
30-
in
31-
extendedLib.ctp.mapModules extendedLib files;
32-
33-
options.catppuccin = {
34-
flavour = lib.mkOption {
35-
type = ctp.types.flavourOption;
36-
default = "latte";
37-
description = "Global Catppuccin flavour";
38-
};
39-
accent = lib.mkOption {
40-
type = ctp.types.accentOption;
41-
default = "teal";
42-
description = "Global Catppuccin accent";
43-
};
44-
};
3+
imports = import ../lib/mkImports.nix args ./.;
454
}

modules/home-manager/globals.nix

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{ lib, ... }: {
2+
options.catppuccin = {
3+
flavour = lib.mkOption {
4+
type = lib.ctp.types.flavourOption;
5+
default = "latte";
6+
description = "Global Catppuccin flavour";
7+
};
8+
9+
accent = lib.mkOption {
10+
type = lib.ctp.types.accentOption;
11+
default = "teal";
12+
description = "Global Catppuccin accent";
13+
};
14+
};
15+
}

modules/home-manager/zathura.nix

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
, pkgs
33
, lib
44
, sources
5+
, ...
56
}:
67
let
78
cfg = config.programs.zathura.catppuccin;

modules/lib/default.nix

+1-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
lib: { config, pkgs, sources, ... }:
1+
{ config, lib, pkgs, ... }:
22
let
33
# string -> type -> string -> a -> a
44
# this is an internal function and shouldn't be
@@ -80,16 +80,6 @@ in
8080
in
8181
fromJSON (readFile json);
8282

83-
# a -> a -> [path] -> [path]
84-
# this imports a list of paths while inheriting
85-
# multiple attributes
86-
mapModules = extendedLib:
87-
map (m: (import m {
88-
inherit config pkgs;
89-
sources = sources pkgs;
90-
lib = extendedLib;
91-
}));
92-
9383
# string -> a -> a
9484
# this creates a basic attrset only containing an
9585
# enable and flavour option. the fist string should

modules/lib/mkExtLib.nix

-1
This file was deleted.

modules/lib/mkImports.nix

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# this imports all files in a directory (besides default.nix)
2+
# with our modified arguments
3+
{ lib, pkgs, ... }@args:
4+
dir:
5+
let
6+
generated = pkgs.callPackage ../../_sources/generated.nix { };
7+
in
8+
lib.pipe dir [
9+
builtins.readDir
10+
builtins.attrNames
11+
12+
(builtins.filter (
13+
n: !(builtins.elem n [ "default.nix" ])
14+
))
15+
16+
(map (
17+
f: _: import "${dir}/${f}" (args // {
18+
sources = builtins.mapAttrs (_: p: p.src) generated;
19+
lib = lib.extend (_: _: { ctp = import ./. args; });
20+
})
21+
))
22+
]

modules/nixos/default.nix

+2-20
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,4 @@
1-
{ inputs, ... }@flakeArgs: { lib, pkgs, ... }@systemArgs:
2-
let
3-
extendedLib = import ../lib/mkExtLib.nix inputs.nixpkgs.lib (systemArgs // flakeArgs);
4-
in
1+
{ lib, pkgs, ... }@args:
52
{
6-
imports =
7-
let
8-
files = [
9-
./grub.nix
10-
];
11-
in
12-
extendedLib.ctp.mapModules extendedLib files;
13-
14-
15-
options.catppuccin = with extendedLib; {
16-
flavour = mkOption {
17-
type = ctp.types.flavourOption;
18-
default = "latte";
19-
description = "Global Catppuccin flavour";
20-
};
21-
};
3+
imports = import ../lib/mkImports.nix args ./.;
224
}

modules/nixos/globals.nix

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{ lib, ... }: {
2+
options.catppuccin = {
3+
flavour = lib.mkOption {
4+
type = lib.ctp.types.flavourOption;
5+
default = "latte";
6+
description = "Global Catppuccin flavour";
7+
};
8+
};
9+
}

0 commit comments

Comments
 (0)