refactor(modules)!: auto import modules & improve passing of arguments (#60)

This commit is contained in:
seth 2023-11-03 22:13:02 +00:00 committed by GitHub
parent a0e508260c
commit 714c415506
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 55 additions and 85 deletions

View file

@ -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 {
@ -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
@ -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" { } ''

View file

@ -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 ./.;
}

View file

@ -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";
};
};
}

View file

@ -2,6 +2,7 @@
, pkgs
, lib
, sources
, ...
}:
let
cfg = config.programs.zathura.catppuccin;

View file

@ -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
@ -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

View file

@ -1 +0,0 @@
lib: args: lib.extend (self: _: { ctp = import ./. self args; })

22
modules/lib/mkImports.nix Normal file
View file

@ -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; });
})
))
]

View file

@ -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 ./.;
}

View file

@ -0,0 +1,9 @@
{ lib, ... }: {
options.catppuccin = {
flavour = lib.mkOption {
type = lib.ctp.types.flavourOption;
default = "latte";
description = "Global Catppuccin flavour";
};
};
}