From f75916f3c016d6f9b00e8da0965b240d37d3ca41 Mon Sep 17 00:00:00 2001 From: bricked Date: Sat, 30 Mar 2024 16:00:51 +0100 Subject: [PATCH] ags: build with derivation --- modules/home/ags/.gitignore | 2 +- modules/home/ags/README.md | 12 ++++++-- modules/home/ags/assets/.keep | 0 modules/home/ags/config.js | 18 ------------ modules/home/ags/config.ts | 7 +++++ modules/home/ags/default.nix | 29 ++++++++++++------- modules/home/ags/package.json | 3 +- modules/home/ags/src/index.ts | 7 ----- modules/home/ags/src/style/global.css | 1 - modules/home/ags/style/main.css | 0 .../home/ags/{src => }/widget/Bar/index.ts | 0 11 files changed, 38 insertions(+), 41 deletions(-) create mode 100644 modules/home/ags/assets/.keep delete mode 100644 modules/home/ags/config.js create mode 100644 modules/home/ags/config.ts delete mode 100644 modules/home/ags/src/index.ts delete mode 100644 modules/home/ags/src/style/global.css create mode 100644 modules/home/ags/style/main.css rename modules/home/ags/{src => }/widget/Bar/index.ts (100%) diff --git a/modules/home/ags/.gitignore b/modules/home/ags/.gitignore index bef1a7d..7a92110 100644 --- a/modules/home/ags/.gitignore +++ b/modules/home/ags/.gitignore @@ -1,4 +1,4 @@ node_modules/ types -dist/ +config.js diff --git a/modules/home/ags/README.md b/modules/home/ags/README.md index 6d453c5..cbaac3f 100644 --- a/modules/home/ags/README.md +++ b/modules/home/ags/README.md @@ -1,19 +1,25 @@ # AgsDots -## Contributing +## Getting Started -1. Install AGS and Bun. +### Installing AGS and Bun ```bash home-manager switch --flake . ``` -2. Install type definitions. +### Installing type definitions ```bash bun install ``` +### Building + +```bash +bun run build +``` + ## Acknowledgements This project was created using `bun init` in bun v1.0.33. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime. diff --git a/modules/home/ags/assets/.keep b/modules/home/ags/assets/.keep new file mode 100644 index 0000000..e69de29 diff --git a/modules/home/ags/config.js b/modules/home/ags/config.js deleted file mode 100644 index 17160a2..0000000 --- a/modules/home/ags/config.js +++ /dev/null @@ -1,18 +0,0 @@ -const entry = `${App.configDir}/src/index.ts`; -const main = `/tmp/ags/main.js`; - -await Utils.execAsync([ - "bun", - "build", - entry, - "--outfile", - main, - "--external", - "ressource://*", - "--external", - "gi://*", - "--external", - "file://*", -]).catch(console.error); - -await import(`file://${main}`); diff --git a/modules/home/ags/config.ts b/modules/home/ags/config.ts new file mode 100644 index 0000000..0bc30f2 --- /dev/null +++ b/modules/home/ags/config.ts @@ -0,0 +1,7 @@ +import Bar from "./widget/Bar"; + +App.addIcons(`${App.configDir}/assets`); +App.config({ + windows: [Bar(0)], + style: `${App.configDir}/style/main.css`, +}); diff --git a/modules/home/ags/default.nix b/modules/home/ags/default.nix index d447e1e..8b6aca5 100644 --- a/modules/home/ags/default.nix +++ b/modules/home/ags/default.nix @@ -1,25 +1,34 @@ { config, lib, + pkgs, nixos-symbolic, ... }: with lib; let cfg = config.programs.ags; - colors = config.lib.stylix.colors; - colorNames = map (n: "base${fixedWidthNumber 2 n}") (range 0 16); in { config = mkIf cfg.enable { programs.ags = { - configDir = ./.; - }; - xdg.configFile."ags".recursive = true; + configDir = pkgs.stdenv.mkDerivation { + name = "ags-dots"; + src = ./.; + + nativeBuildInputs = with pkgs; [bun]; + buildPhase = '' + # Copy assets + cp ${nixos-symbolic} ./assets/nixos-symbolic.svg - xdg.configFile."ags/src/style/colors.css".text = - concatMapStringsSep "\n" - (color: "@define-color ${color} ${colors.withHashtag.${color}};") - colorNames; + # Build bun files + bun install + bun run build + ''; - xdg.configFile."ags/src/assets/nixos-symbolic.svg".source = nixos-symbolic; + installPhase = '' + mkdir -p $out + cp -r assets style config.js $out + ''; + }; + }; }; } diff --git a/modules/home/ags/package.json b/modules/home/ags/package.json index 44f0f54..7de5023 100644 --- a/modules/home/ags/package.json +++ b/modules/home/ags/package.json @@ -9,6 +9,7 @@ "typescript": "^5.0.0" }, "scripts": { - "postinstall": "rm types; ln -s $HOME/.local/share/com.github.Aylur.ags/types types" + "postinstall": "rm types; ln -s $HOME/.local/share/com.github.Aylur.ags/types types", + "build": "bun build ./config.ts --outfile ./config.js --external \"resource://*\" --external \"gi://*\"" } } diff --git a/modules/home/ags/src/index.ts b/modules/home/ags/src/index.ts deleted file mode 100644 index 6b24baa..0000000 --- a/modules/home/ags/src/index.ts +++ /dev/null @@ -1,7 +0,0 @@ -import Bar from "./widget/Bar"; - -App.addIcons(`${App.configDir}/src/assets`); -App.config({ - windows: [Bar(0)], - style: `${App.configDir}/src/style/global.css`, -}); diff --git a/modules/home/ags/src/style/global.css b/modules/home/ags/src/style/global.css deleted file mode 100644 index e88cfe0..0000000 --- a/modules/home/ags/src/style/global.css +++ /dev/null @@ -1 +0,0 @@ -@import "./colors.css"; diff --git a/modules/home/ags/style/main.css b/modules/home/ags/style/main.css new file mode 100644 index 0000000..e69de29 diff --git a/modules/home/ags/src/widget/Bar/index.ts b/modules/home/ags/widget/Bar/index.ts similarity index 100% rename from modules/home/ags/src/widget/Bar/index.ts rename to modules/home/ags/widget/Bar/index.ts