From 1071440ed1e0de01f27a67841ef28204346ad7a8 Mon Sep 17 00:00:00 2001 From: NullBite Date: Sat, 8 Feb 2025 13:55:11 -0500 Subject: [PATCH] flake: add modules, make lib compatible --- flake.nix | 2 ++ lib/nixfiles/default.nix | 31 +++++++++++++++++++----- lib/nixfiles/module.nix | 11 +++++++++ pkgs/module.nix | 51 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 89 insertions(+), 6 deletions(-) create mode 100644 lib/nixfiles/module.nix create mode 100644 pkgs/module.nix diff --git a/flake.nix b/flake.nix index aba2f84..b51cf22 100644 --- a/flake.nix +++ b/flake.nix @@ -121,6 +121,8 @@ # flake-parts imports imports = [ ./flake + ./lib/nixfiles/module.nix + # ./pkgs/module.nix ]; config = { diff --git a/lib/nixfiles/default.nix b/lib/nixfiles/default.nix index 6468712..70a6430 100644 --- a/lib/nixfiles/default.nix +++ b/lib/nixfiles/default.nix @@ -1,8 +1,27 @@ -{ pkgs, ... }: -let +{...} @ attrs: let + # compatibility with old loading system (this looks awful fix this when i + # fully migrate to flake-parts). this constructs an attrset that resembles + # what the old args used to look like in attrs', so i don't have to rewrite + # all of the glue. it creates a fake pkgs value containing only `lib`. + # + # actually no idk if i can fix this because it needs to be accessible from + # everything (flake, nixos/home-manager modules, maybe derivations). this + # might be the best way to do this so i can pass in either pkgs or lib based + # on the current context, and just return relevant libraries based on that + # input. + # + # create empty `pkgs` with lib only `lib` attr as fallback + pkgs = attrs.pkgs or {inherit (attrs) lib;}; + # inherit lib from whatever `pkgs` happens to be inherit (pkgs) lib; + + # compat + attrs' = attrs // {inherit pkgs;}; in -{ - types = (import ./types.nix) { inherit pkgs; }; - minecraft = (import ./minecraft.nix) { inherit pkgs; }; -} + { + types = (import ./types.nix) attrs'; + } + # only if an actual `pkgs` was passed + // lib.optionalAttrs (attrs ? pkgs) { + minecraft = (import ./minecraft.nix) attrs'; + } diff --git a/lib/nixfiles/module.nix b/lib/nixfiles/module.nix new file mode 100644 index 0000000..2048867 --- /dev/null +++ b/lib/nixfiles/module.nix @@ -0,0 +1,11 @@ +{lib, ...}: let + inherit (lib) types; + nixfiles-lib = (import ./.) {inherit lib;}; +in { + options.nixfiles.lib = lib.mkOption { + description = "nixfiles library"; + type = types.attrs; + readOnly = true; + default = nixfiles-lib; + }; +} diff --git a/pkgs/module.nix b/pkgs/module.nix new file mode 100644 index 0000000..cff2ddf --- /dev/null +++ b/pkgs/module.nix @@ -0,0 +1,51 @@ +{ + inputs, + self, + config, + lib, + options, + ... +}: let + cfg = config.nixfiles.outputs.packages; + inherit (lib) mapAttrs mkEnableOption mkIf; +in { + options.nixfiles.outputs.packages = { + enable = + mkEnableOption "" + // { + description = '' + Whether to generate the packages output. + ''; + default = true; + }; + }; + config = mkIf cfg.enable { + perSystem = { + system, + inputs', + self', + pkgs, + ... + }: { + packages = let + inherit (pkgs) callPackage callPackages; + + # i forget how this works so i'm not messing with it. + mopidyPackages = callPackages ./mopidy { + python = pkgs.python3; + }; + in + (mapAttrs (_: v: callPackage v {}) { + google-fonts = ./google-fonts; + wm-helpers = ./wm-helpers; + atool = ./atool-wrapped; + nixfiles-assets = ./nixfiles-assets; + redlib = ./redlib; + cross-seed = ./cross-seed; + }) + // { + inherit (mopidyPackages) mopidy-autoplay; + }; + }; + }; +}