diff --git a/lib/default.nix b/lib/default.nix index a4cfcee8..3c4d86bc 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -1,6 +1,7 @@ { inputs ? {}, pkgs ? {}, + self ? {}, }: let lock = builtins.fromJSON (builtins.readFile ../flake.lock); @@ -9,11 +10,12 @@ sha256 = lock.nodes.nixpkgs.locked.narHash; }}/lib"; - inherit (lib) optionalAttrs; + inherit (lib) concatStringsSep optionalAttrs stringToCharacters substring tail toUpper; mkVersion = src: "0.0.0+" + src.shortRev; + capitalise = str: (toUpper (substring 0 1 str) + (concatStringsSep "" (tail (stringToCharacters str)))); in - {inherit lib mkVersion;} + {inherit lib mkVersion capitalise;} // (import ./inputs.nix lib lock) // optionalAttrs (inputs != {}) (import ./flake-lib.nix inputs) - // optionalAttrs (pkgs != {}) (import ./pkgs.nix pkgs mkVersion) + // optionalAttrs (pkgs != {}) (import ./pkgs.nix pkgs mkVersion capitalise self) diff --git a/nixosModules/ags/mk-types/.envrc b/lib/mk-types/.envrc similarity index 100% rename from nixosModules/ags/mk-types/.envrc rename to lib/mk-types/.envrc diff --git a/nixosModules/ags/mk-types/default.nix b/lib/mk-types/default.nix similarity index 54% rename from nixosModules/ags/mk-types/default.nix rename to lib/mk-types/default.nix index aefe02dc..702fe1cd 100644 --- a/nixosModules/ags/mk-types/default.nix +++ b/lib/mk-types/default.nix @@ -1,13 +1,16 @@ { - package, - girName, + lib, + pname, + withGirNames, buildNpmPackage, ts-for-gir-src, ... -}: +}: let + inherit (lib) concatMapStringsSep; +in buildNpmPackage { - pname = "${package.pname}-types"; - inherit (package) version; + pname = "${pname}-types"; + version = "0.0.0"; npmDepsHash = "sha256-8De8tRUKzRhD1jyx0anYNPMhxZyIr2nI45HdK6nb8jI="; @@ -15,8 +18,8 @@ buildNpmPackage { dontNpmBuild = true; buildPhase = '' - npx @ts-for-gir/cli generate ${girName} \ - -g ${package.dev}/share/gir-1.0 \ + npx @ts-for-gir/cli generate ${concatMapStringsSep " " (p: p.girName) withGirNames} \ + ${concatMapStringsSep "\n" (p: "-g ${p.package.dev}/share/gir-1.0 \\") withGirNames} -g ${ts-for-gir-src}/girs \ --ignoreVersionConflicts \ --package \ diff --git a/nixosModules/ags/mk-types/package-lock.json b/lib/mk-types/package-lock.json similarity index 100% rename from nixosModules/ags/mk-types/package-lock.json rename to lib/mk-types/package-lock.json diff --git a/nixosModules/ags/mk-types/package.json b/lib/mk-types/package.json similarity index 100% rename from nixosModules/ags/mk-types/package.json rename to lib/mk-types/package.json diff --git a/lib/pkgs.nix b/lib/pkgs.nix index 831d7f6f..bbe75720 100644 --- a/lib/pkgs.nix +++ b/lib/pkgs.nix @@ -1,4 +1,4 @@ -pkgs: mkVersion: { +pkgs: mkVersion: capitalise: self: { buildPlugin = pname: src: pkgs.vimUtils.buildVimPlugin { inherit pname src; @@ -21,4 +21,29 @@ pkgs: mkVersion: { dontNpmBuild = true; }) {}; in "${pkg}/lib/node_modules/${pkg.pname}/node_modules"; + + buildNodeTypes = { + configPath, + packages, + pname, + }: let + inherit (pkgs.lib) concatMapStrings elemAt length map optionalString splitString toLower; + + withGirNames = + map (package: { + inherit package; + girName = + if package.pname == "astal-wireplumber" + then "AstalWp-0.1" + else (concatMapStrings capitalise (splitString "-" package.pname)) + "-0.1"; + }) + packages; + in { + "${configPath}${optionalString (length packages == 1) "/${toLower (elemAt withGirNames 0).girName}"}".source = + pkgs.callPackage + ./mk-types { + inherit (self.inputs) ts-for-gir-src; + inherit pname withGirNames; + }; + }; } diff --git a/nixosModules/ags/default.nix b/nixosModules/ags/default.nix index a61a7f07..5dd9ea63 100644 --- a/nixosModules/ags/default.nix +++ b/nixosModules/ags/default.nix @@ -4,10 +4,10 @@ self: { pkgs, ... }: let - inherit (self.inputs) ags astal gtk-session-lock ts-for-gir-src; + inherit (self.inputs) ags astal gtk-session-lock; in { config = let - inherit (lib) boolToString mkIf toLower; + inherit (lib) boolToString mkIf; # Configs inherit (config.vars) hostName; @@ -70,15 +70,11 @@ in { home = { file = let - inherit (import "${self}/lib" {inherit pkgs;}) buildNodeModules; - - mkType = package: girName: { - "${agsConfigDir}/config/types/@girs/${toLower girName}".source = - pkgs.callPackage - ./mk-types { - inherit ts-for-gir-src package girName; - }; - }; + inherit + (import "${self}/lib" {inherit pkgs self;}) + buildNodeModules + buildNodeTypes + ; in ( { # Generated types @@ -87,8 +83,16 @@ in { recursive = true; # To add other types inside the folder }; } - // (mkType gtkSessionLock "GtkSessionLock-0.1") - // (mkType astalTray "AstalTray-0.1") + // (buildNodeTypes { + pname = "gtk-session-lock"; + configPath = "${agsConfigDir}/config/types/@girs"; + packages = [gtkSessionLock]; + }) + // (buildNodeTypes { + pname = "astal-tray"; + configPath = "${agsConfigDir}/config/types/@girs"; + packages = [astalTray]; + }) // { # Out of store symlinks ".config/ags".source = mkOutOfStoreSymlink "${flakeDir}/nixosModules/ags/config";