Skip to content

Commit

Permalink
refactor(modules)!: auto import modules & improve passing of arguments (
Browse files Browse the repository at this point in the history
  • Loading branch information
getchoo authored Nov 3, 2023
1 parent a0e5082 commit 714c415
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 85 deletions.
13 changes: 3 additions & 10 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@
inherit (nixpkgs) lib;

forAllSystems = fn: lib.genAttrs systems (s: fn nixpkgs.legacyPackages.${s});

sources = pkgs:
let
s =
import ./_sources/generated.nix { inherit (pkgs) fetchgit fetchurl fetchFromGitHub dockerTools; };
in
builtins.mapAttrs (_: p: p.src) s;
in
{
checks = forAllSystems (pkgs: lib.optionalAttrs pkgs.stdenv.isLinux {
Expand All @@ -37,9 +30,9 @@

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

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

nixosModules.catppuccin = import ./modules/nixos { inherit inputs sources; };
nixosModules.catppuccin = import ./modules/nixos;

packages = forAllSystems (pkgs:
let
Expand All @@ -60,7 +53,7 @@
doc = pkgs.nixosOptionsDoc {
options = lib.filterAttrs (n: _: n != "_module") (eval module).options;
documentType = "none";
revision = builtins.substring 0 7 self.rev or "dirty";
revision = builtins.substring 0 8 self.rev or "dirty";
};
in
pkgs.runCommand "${name}-module-doc.md" { } ''
Expand Down
45 changes: 2 additions & 43 deletions modules/home-manager/default.nix
Original file line number Diff line number Diff line change
@@ -1,45 +1,4 @@
{ inputs, ... }@flakeArgs: { lib, pkgs, ... }@systemArgs:
let
extendedLib = import ../lib/mkExtLib.nix inputs.nixpkgs.lib (flakeArgs // systemArgs);
inherit (extendedLib) ctp;
in
{ lib, pkgs, ... }@args:
{
imports =
let
files = [
./alacritty.nix
./bat.nix
./bottom.nix
./btop.nix
./fish.nix
./kitty.nix
./lazygit.nix
./starship.nix
./helix.nix
./hyprland.nix
./glamour.nix
./gtk.nix
./mako.nix
./neovim.nix
./micro.nix
./polybar.nix
./sway.nix
./tmux.nix
./zathura.nix
];
in
extendedLib.ctp.mapModules extendedLib files;

options.catppuccin = {
flavour = lib.mkOption {
type = ctp.types.flavourOption;
default = "latte";
description = "Global Catppuccin flavour";
};
accent = lib.mkOption {
type = ctp.types.accentOption;
default = "teal";
description = "Global Catppuccin accent";
};
};
imports = import ../lib/mkImports.nix args ./.;
}
15 changes: 15 additions & 0 deletions modules/home-manager/globals.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{ lib, ... }: {
options.catppuccin = {
flavour = lib.mkOption {
type = lib.ctp.types.flavourOption;
default = "latte";
description = "Global Catppuccin flavour";
};

accent = lib.mkOption {
type = lib.ctp.types.accentOption;
default = "teal";
description = "Global Catppuccin accent";
};
};
}
1 change: 1 addition & 0 deletions modules/home-manager/zathura.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
, pkgs
, lib
, sources
, ...
}:
let
cfg = config.programs.zathura.catppuccin;
Expand Down
12 changes: 1 addition & 11 deletions modules/lib/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
lib: { config, pkgs, sources, ... }:
{ config, lib, pkgs, ... }:
let
# string -> type -> string -> a -> a
# this is an internal function and shouldn't be
Expand Down Expand Up @@ -80,16 +80,6 @@ in
in
fromJSON (readFile json);

# a -> a -> [path] -> [path]
# this imports a list of paths while inheriting
# multiple attributes
mapModules = extendedLib:
map (m: (import m {
inherit config pkgs;
sources = sources pkgs;
lib = extendedLib;
}));

# string -> a -> a
# this creates a basic attrset only containing an
# enable and flavour option. the fist string should
Expand Down
1 change: 0 additions & 1 deletion modules/lib/mkExtLib.nix

This file was deleted.

22 changes: 22 additions & 0 deletions modules/lib/mkImports.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# this imports all files in a directory (besides default.nix)
# with our modified arguments
{ lib, pkgs, ... }@args:
dir:
let
generated = pkgs.callPackage ../../_sources/generated.nix { };
in
lib.pipe dir [
builtins.readDir
builtins.attrNames

(builtins.filter (
n: !(builtins.elem n [ "default.nix" ])
))

(map (
f: _: import "${dir}/${f}" (args // {
sources = builtins.mapAttrs (_: p: p.src) generated;
lib = lib.extend (_: _: { ctp = import ./. args; });
})
))
]
22 changes: 2 additions & 20 deletions modules/nixos/default.nix
Original file line number Diff line number Diff line change
@@ -1,22 +1,4 @@
{ inputs, ... }@flakeArgs: { lib, pkgs, ... }@systemArgs:
let
extendedLib = import ../lib/mkExtLib.nix inputs.nixpkgs.lib (systemArgs // flakeArgs);
in
{ lib, pkgs, ... }@args:
{
imports =
let
files = [
./grub.nix
];
in
extendedLib.ctp.mapModules extendedLib files;


options.catppuccin = with extendedLib; {
flavour = mkOption {
type = ctp.types.flavourOption;
default = "latte";
description = "Global Catppuccin flavour";
};
};
imports = import ../lib/mkImports.nix args ./.;
}
9 changes: 9 additions & 0 deletions modules/nixos/globals.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{ lib, ... }: {
options.catppuccin = {
flavour = lib.mkOption {
type = lib.ctp.types.flavourOption;
default = "latte";
description = "Global Catppuccin flavour";
};
};
}

0 comments on commit 714c415

Please sign in to comment.