rose-pine-nix/modules/lib/default.nix

149 lines
4 KiB
Nix
Raw Normal View History

2024-05-21 14:53:46 -07:00
{
config,
lib,
pkgs,
...
}:
let
# this is a recursive attribute with all the functions below
inherit (lib) ctp;
in
{
# string -> type -> string -> a -> a
# this is an internal function and shouldn't be
# used unless you know what you're doing. it takes
# a string (the name of the property, i.e., flavour
# or accent), the type of the property, the name of
# the module, followed by local config attrset
2024-05-21 14:53:46 -07:00
mkBasicOpt =
attr: type: name:
lib.mkOption {
inherit type;
default = config.catppuccin.${attr};
description = "Catppuccin ${attr} for ${name}";
};
2023-04-17 09:44:07 -07:00
# string -> a -> a
# this creates a flavour option for modules
# the first string should be the name of the module,
# followed by the local config attrset
mkFlavourOpt = ctp.mkBasicOpt "flavour" ctp.types.flavourOption;
2023-04-17 09:44:07 -07:00
types = {
2024-05-21 14:53:46 -07:00
flavourOption = lib.types.enum [
"latte"
"frappe"
"macchiato"
"mocha"
];
2023-04-17 09:44:07 -07:00
accentOption = lib.types.enum [
"blue"
"flamingo"
"green"
"lavender"
"maroon"
"mauve"
"peach"
"pink"
"red"
"rosewater"
"sapphire"
"sky"
"teal"
"yellow"
];
};
# string -> string
# this capitalizes the first letter in a string,
# which is sometimes needed in order to format
# the names of themes correctly
2024-05-21 14:53:46 -07:00
mkUpper =
str:
(lib.toUpper (builtins.substring 0 1 str)) + (builtins.substring 1 (builtins.stringLength str) str);
2023-04-17 09:44:07 -07:00
# a -> path -> a
# fromJSON but for yaml (and without readFile)
# a should be the local pkgs attrset
2024-05-21 14:53:46 -07:00
fromYaml =
file:
let
# convert to json
json = pkgs.runCommand "converted.json" { } ''
${lib.getExe pkgs.yj} < ${file} > $out
'';
in
builtins.fromJSON (builtins.readFile json);
# a -> path -> a
# fromJSON but for ini (and without readFile)
# a should be the local pkgs attrset
2024-05-21 14:53:46 -07:00
fromINI =
file:
let
# convert to json
json = pkgs.runCommand "converted.json" { } ''
${lib.getExe pkgs.jc} --ini < ${file} > $out
'';
in
builtins.fromJSON (builtins.readFile json);
# a -> path -> a
# fromJSON but for raw ini (and without readFile)
# a should be the local pkgs attrset
2024-05-21 14:53:46 -07:00
fromINIRaw =
file:
let
inherit (builtins) fromJSON readFile;
# convert to json
2024-05-21 14:53:46 -07:00
json =
with pkgs;
runCommand "converted.json" { } ''
${jc}/bin/jc --ini -r < ${file} > $out
'';
in
fromJSON (readFile json);
2023-04-17 09:44:07 -07:00
# string -> a -> a
# this creates a basic attrset only containing an
# enable and flavour option. the fist string should
# be the name of the module, followed by the local config
# attrset
feat: limit use of IFD, add auto updates & vm testing (#40) * feat(modules): remove unnecessary IFD by moving all upstream repos to our flake inputs, we no longer need to have [IFD](https://nixos.wiki/wiki/Import_From_Derivation) in most of our modules - making evaluation faster for all configurations. the only remaining instances of IFD are in `lib.ctp.toYAML` and the themes for kitty, which is due to it's use upstream in home-manager * ci: start auto updating flake inputs * ci: init basic vm tests * ci: rename ci to format * ci: use PAT for update-lock workflow this is required to run tests such as test-vm after the pull request is made * fix(home-manager): make sure to use readFile in helix module * ci: fix typo in test-vm * ci: use verbose logging in test-vm & enable kvm * docs: add flake inputs & vm testing to CONTRIBUTING.md * feat(modules)!: use nvfetcher for upstream sources * docs: add information about nvfetcher * chore: don't include flake-compat in flake inputs while this does make us lose out on easy updating, i think it's nice not have this as a required dependency for flake users * chore: update flake inputs Flake lock file updates: • Updated input 'home-manager': 'github:nix-community/home-manager/f58889c07efa8e1328fdf93dc1796ec2a5c47f38' (2023-07-29) → 'github:nix-community/home-manager/48b0a30202516e25d9885525fbb200a045f23f26' (2023-11-01) • Updated input 'nixpkgs': 'github:NixOS/nixpkgs/2a9d660ff0f7ffde9d73be328ee6e6f10ef66b28' (2023-07-28) → 'github:NixOS/nixpkgs/0cbe9f69c234a7700596e943bfae7ef27a31b735' (2023-10-29) * chore: update nvfetcher sources * refactor: don't instantiate nixpkgs in flake + cleanup vm test * fix(home-manager): update paths from new lazygit theme revision * feat(lib)!: use constant module arguments automatically
2023-11-02 10:55:47 -07:00
mkCatppuccinOpt = name: {
enable = lib.mkEnableOption "Catppuccin theme" // {
default = config.catppuccin.enable;
};
flavour = ctp.mkFlavourOpt name;
2023-04-17 09:44:07 -07:00
};
# string -> a -> a
# this creates an accent option for modules
# the first string should be the name of the module,
# followed by the local config attrset
mkAccentOpt = ctp.mkBasicOpt "accent" ctp.types.accentOption;
# a -> a -> a
# see https://nlewo.github.io/nixos-manual-sphinx/development/option-types.xml.html
# by default enums cannot be merged, but they keep their passed value in `functor.payload`.
# `functor.binOp` can merge those values
mergeEnums = a: b: lib.types.enum (a.functor.binOp a.functor.payload b.functor.payload);
# string
# returns the current release version of nixos or home-manager. throws an evaluation error if neither are
# found
2024-05-21 14:53:46 -07:00
getModuleRelease =
config.home.version.release or config.system.nixos.release
or (throw "Couldn't determine release version!");
# string -> a -> a
# if the current module release is less than `minVersion`, all options are made no-ops with
# `lib.mkSinkUndeclaredOptions`
2024-05-21 14:53:46 -07:00
mkVersionedOpts =
minVersion: option:
if lib.versionAtLeast ctp.getModuleRelease minVersion then
option
else
lib.mkSinkUndeclaredOptions { };
2023-04-17 09:44:07 -07:00
}