From 318ccef645d1dd55209411b78350172933fd2215 Mon Sep 17 00:00:00 2001 From: matt1432 Date: Wed, 20 Nov 2024 17:07:10 -0500 Subject: [PATCH] refactor: split up lib in multiple folders --- lib/default.nix | 24 +++++++++++++++------- lib/{flake-lib.nix => flake/default.nix} | 4 ++-- lib/{pkgs.nix => pkgs/default.nix} | 20 ++++++++---------- lib/{ => pkgs}/mk-types/.envrc | 0 lib/{ => pkgs}/mk-types/default.nix | 0 lib/{ => pkgs}/mk-types/package-lock.json | Bin lib/{ => pkgs}/mk-types/package.json | 0 lib/strings/default.nix | 11 ++++++++++ 8 files changed, 39 insertions(+), 20 deletions(-) rename lib/{flake-lib.nix => flake/default.nix} (97%) rename lib/{pkgs.nix => pkgs/default.nix} (76%) rename lib/{ => pkgs}/mk-types/.envrc (100%) rename lib/{ => pkgs}/mk-types/default.nix (100%) rename lib/{ => pkgs}/mk-types/package-lock.json (100%) rename lib/{ => pkgs}/mk-types/package.json (100%) create mode 100644 lib/strings/default.nix diff --git a/lib/default.nix b/lib/default.nix index a99e88c1..c2085d74 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -2,12 +2,22 @@ perSystem, inputs, }: let - inherit (inputs.nixpkgs.lib) concatStringsSep stringToCharacters substring tail toUpper; + flake = import ./flake inputs; + strings = import ./strings inputs.nixpkgs.lib; - mkVersion = src: "0.0.0+" + src.shortRev; - capitalise = str: (toUpper (substring 0 1 str) + (concatStringsSep "" (tail (stringToCharacters str)))); + lib = flake // strings; in - {inherit mkVersion capitalise;} - // (import ./flake-lib.nix inputs) - // perSystem (pkgs: - import ./pkgs.nix {inherit pkgs mkVersion capitalise inputs;}) + # Expose main attrs + lib + # Expose all funcs + // strings + // flake + # Expose funcs that require pkgs + // perSystem ( + pkgs: + (import ./pkgs { + inherit pkgs; + inherit (inputs) self; + }) + // lib + ) diff --git a/lib/flake-lib.nix b/lib/flake/default.nix similarity index 97% rename from lib/flake-lib.nix rename to lib/flake/default.nix index 0e283ac6..2f611bde 100644 --- a/lib/flake-lib.nix +++ b/lib/flake/default.nix @@ -40,7 +40,7 @@ inputs: rec { [ (allowModularOverrides {inherit system cudaSupport;}) {home-manager.extraSpecialArgs = specialArgs;} - ../common + ../../common ] ++ extraModules; }; @@ -86,7 +86,7 @@ inputs: rec { {home-manager = {inherit extraSpecialArgs;};} - ../common/nix-on-droid.nix + ../../common/nix-on-droid.nix ] ++ extraModules; }; diff --git a/lib/pkgs.nix b/lib/pkgs/default.nix similarity index 76% rename from lib/pkgs.nix rename to lib/pkgs/default.nix index c85cd1eb..3fab5aca 100644 --- a/lib/pkgs.nix +++ b/lib/pkgs/default.nix @@ -1,9 +1,11 @@ { - capitalise, - mkVersion, pkgs, - inputs, -}: { + self, +}: let + inherit (builtins) readFile fromJSON; + inherit (self.lib) capitalise mkVersion; + inherit (pkgs.lib) concatMapStrings elemAt length map optionalString splitString toLower; +in { buildPlugin = pname: src: pkgs.vimUtils.buildVimPlugin { inherit pname src; @@ -11,11 +13,9 @@ }; buildNodeModules = dir: npmDepsHash: let - pkg = pkgs.callPackage ({buildNpmPackage, ...}: let - inherit (builtins) readFile fromJSON; + packageJSON = fromJSON (readFile (dir + /package.json)); - packageJSON = fromJSON (readFile (dir + /package.json)); - in + pkg = pkgs.callPackage ({buildNpmPackage, ...}: buildNpmPackage { pname = packageJSON.name; inherit (packageJSON) version; @@ -32,8 +32,6 @@ packages, pname, }: let - inherit (pkgs.lib) concatMapStrings elemAt length map optionalString splitString toLower; - withGirNames = map (package: { inherit package; @@ -51,7 +49,7 @@ "${configPath}${optionalString (length packages == 1) "/${toLower (elemAt withGirNames 0).girName}"}".source = pkgs.callPackage ./mk-types { - inherit (inputs) ts-for-gir-src; + inherit (self.inputs) ts-for-gir-src; inherit pname withGirNames; }; }; diff --git a/lib/mk-types/.envrc b/lib/pkgs/mk-types/.envrc similarity index 100% rename from lib/mk-types/.envrc rename to lib/pkgs/mk-types/.envrc diff --git a/lib/mk-types/default.nix b/lib/pkgs/mk-types/default.nix similarity index 100% rename from lib/mk-types/default.nix rename to lib/pkgs/mk-types/default.nix diff --git a/lib/mk-types/package-lock.json b/lib/pkgs/mk-types/package-lock.json similarity index 100% rename from lib/mk-types/package-lock.json rename to lib/pkgs/mk-types/package-lock.json diff --git a/lib/mk-types/package.json b/lib/pkgs/mk-types/package.json similarity index 100% rename from lib/mk-types/package.json rename to lib/pkgs/mk-types/package.json diff --git a/lib/strings/default.nix b/lib/strings/default.nix new file mode 100644 index 00000000..77c26df5 --- /dev/null +++ b/lib/strings/default.nix @@ -0,0 +1,11 @@ +{ + concatStringsSep, + stringToCharacters, + substring, + tail, + toUpper, + ... +}: { + mkVersion = src: "0.0.0+" + src.shortRev; + capitalise = str: (toUpper (substring 0 1 str) + (concatStringsSep "" (tail (stringToCharacters str)))); +}