diff options
| author | Chris Wells <chris@mathematicaster.org> | 2025-10-22 09:24:40 -0500 |
|---|---|---|
| committer | Chris Wells <chris@mathematicaster.org> | 2025-10-22 09:24:40 -0500 |
| commit | 8d2ef7b4634ea4c2b9f2998ad2121813dcd6859d (patch) | |
| tree | c7e290745646f2e6d7b80c797106c4817314aa35 | |
| download | weznix-8d2ef7b4634ea4c2b9f2998ad2121813dcd6859d.tar weznix-8d2ef7b4634ea4c2b9f2998ad2121813dcd6859d.tar.gz weznix-8d2ef7b4634ea4c2b9f2998ad2121813dcd6859d.tar.bz2 weznix-8d2ef7b4634ea4c2b9f2998ad2121813dcd6859d.tar.lz weznix-8d2ef7b4634ea4c2b9f2998ad2121813dcd6859d.tar.xz weznix-8d2ef7b4634ea4c2b9f2998ad2121813dcd6859d.tar.zst weznix-8d2ef7b4634ea4c2b9f2998ad2121813dcd6859d.zip | |
Fixed up the code
| -rw-r--r-- | README.md | 3 | ||||
| -rw-r--r-- | flake.lock | 114 | ||||
| -rw-r--r-- | flake.nix | 49 | ||||
| -rw-r--r-- | modules/flake-module.nix | 51 | ||||
| -rw-r--r-- | overlays/default.nix | 6 | ||||
| -rw-r--r-- | pkgs/weznix.nix | 61 |
6 files changed, 284 insertions, 0 deletions
diff --git a/README.md b/README.md new file mode 100644 index 0000000..99f46f0 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# WezNix + +Nix wrapper for [wezterm](https://github.com/wezterm/wezterm) à la [nixCats-nvim](https://github.com/BirdeeHub/nixCats-nvim), though nowhere near as sophisticated. diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..429c4fc --- /dev/null +++ b/flake.lock @@ -0,0 +1,114 @@ +{ + "nodes": { + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1760948891, + "narHash": "sha256-TmWcdiUUaWk8J4lpjzu4gCGxWY6/Ok7mOK4fIFfBuU4=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "864599284fc7c0ba6357ed89ed5e2cd5040f0c04", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "nixToLua": { + "flake": false, + "locked": { + "lastModified": 1748756411, + "narHash": "sha256-jmfRRsxCVV+/2KnDVrMG/RBKFOARDpSrYICqQ6vnSjw=", + "owner": "BirdeeHub", + "repo": "nixToLua", + "rev": "a701038ccfe76833f678e3c643a2b0f4291c1cea", + "type": "github" + }, + "original": { + "owner": "BirdeeHub", + "repo": "nixToLua", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1761140869, + "narHash": "sha256-n74HHkvFqgmngWwN4armXSnfymHaQwOIcGFdqlzjVQ0=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "d3eb3d6ce5955bd345a57830921818a68832f485", + "type": "github" + }, + "original": { + "owner": "nixos", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1754788789, + "narHash": "sha256-x2rJ+Ovzq0sCMpgfgGaaqgBSwY+LST+WbZ6TytnT9Rk=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "a73b9c743612e4244d865a2fdee11865283c04e6", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "nixToLua": "nixToLua", + "nixpkgs": "nixpkgs", + "systems": "systems", + "treefmt-nix": "treefmt-nix" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1760945191, + "narHash": "sha256-ZRVs8UqikBa4Ki3X4KCnMBtBW0ux1DaT35tgsnB1jM4=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "f56b1934f5f8fcab8deb5d38d42fd692632b47c2", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..a9cf2e1 --- /dev/null +++ b/flake.nix @@ -0,0 +1,49 @@ +{ + description = "Wezterm configuration a la nixCats"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs"; + flake-parts.url = "github:hercules-ci/flake-parts"; + systems.url = "github:nix-systems/default"; + treefmt-nix = { + url = "github:numtide/treefmt-nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + nixToLua = { + url = "github:BirdeeHub/nixToLua"; + flake = false; + }; + }; + + outputs = inputs@{ self, flake-parts, ... }: flake-parts.lib.mkFlake { inherit inputs self; } { + systems = import inputs.systems; + + imports = [ + inputs.treefmt-nix.flakeModule + ]; + + flake = { + overlays.default = import ./overlays { nixToLua = import inputs.nixToLua; }; + flakeModules.default = import ./modules/flake-module.nix; + }; + + perSystem = { system, pkgs, config, ... }: { + treefmt = { + programs.nixfmt = { + enable = true; + strict = true; + }; + }; + + devShells.default = pkgs.mkShellNoCC { + inputsFrom = [ config.treefmt.devShell ]; + nativeBuildInputs = with pkgs; [ + nixd + statix + deadnix + ]; + }; + }; + + }; +} diff --git a/modules/flake-module.nix b/modules/flake-module.nix new file mode 100644 index 0000000..c43be76 --- /dev/null +++ b/modules/flake-module.nix @@ -0,0 +1,51 @@ +{ lib, flake-parts-lib, inputs, ... }: +let + inherit (lib) mkOption mkPackageOption types; + inherit (flake-parts-lib) mkPerSystemOptions; +in { + perSystem = mkPerSystemOptions ({ pkgs, config, ... }: { + options = { + weznix = { + wezterm = mkPackageOption pkgs "wezterm" {}; + configDirectory = mkOption { + type = types.str; + default = "~/.config/wezterm"; + }; + luaPath = mkOption { + type = types.path; + description = "Path to wezterm config directory"; + }; + wrapConfig = mkOption { + type = types.either types.bool types.str; + default = "WEZDEV"; + }; + extraPATH = mkOption { + type = types.listOf types.package; + default = []; + description = "Extra packages to add to wezterm's $PATH"; + }; + extraWrapperArgs = mkOption { + type = types.listOf types.str; + default = []; + description = "Extra arguments to pass to `wrapProgram`"; + }; + pass = mkOption { + type = types.lazyAttrsOf types.anything; + default = {}; + description = "Anything else to pass into the lua config"; + }; + }; + }; + + config = { + packages = { + weznix = pkgs.callPackage ./pkgs/weznix.nix { + inherit (config.weznix) wezterm; + nixToLua = import inputs.nixToLua; + } { + inherit (config.weznix) configDirectory luaPath wrapConfig extraPATH extraWrapperArgs pass; + }; + }; + }; + }); +} diff --git a/overlays/default.nix b/overlays/default.nix new file mode 100644 index 0000000..9789980 --- /dev/null +++ b/overlays/default.nix @@ -0,0 +1,6 @@ +{ nixToLua, ... }: +_final: prev: { + weznix = prev.callPackage ../pkgs/weznix.nix { + inherit nixToLua; + }; +} diff --git a/pkgs/weznix.nix b/pkgs/weznix.nix new file mode 100644 index 0000000..0996dff --- /dev/null +++ b/pkgs/weznix.nix @@ -0,0 +1,61 @@ +{ wezterm, + makeWrapper, + writeText, + nixToLua, + lib, +}: +{ + configDirectory ? "~/.config/wezterm", + wrapConfig ? "WEZDEV", + luaPath, + extraWrapperArgs ? [], + extraPATH ? [], + pass ? {}, +}: let + inherit (nixToLua) toLua; + passables = { + inherit configDirectory wrapConfig luaPath; + wezterm = builtins.toString wezterm; + } // pass; + + wezinit = writeText "wezterm.lua" # lua + '' + package.preload["weznix"] = function() + return ${toLua passables} + end + + weznix = require('weznix') + + local cfgDir = weznix.luaPath + if (weznix.wrapConfig == false) or (type(weznix.wrapConfig) == "string" and os.getenv(weznix.wrapConfig == 1) then + cfgDir = weznix.configDirectory + end + + + require('wezterm').config_dir = cfgDir + + package.path = package.path .. ';' .. cfgDir .. '/?.lua' + package.cpath = package.cpath .. ';' .. cfgDir .. '/?.so' + + + return require('init') + ''; + + wrapperArgs = [ + # "--prefix" "PATH" ":" (lib.makeBinPath extraPATH) + "--set" "WEZTERM_CONFIG_FILE" (toString wezinit) + ] ++ extraWrapperArgs; + +in wezterm.overrideAttrs ({ postInstall ? "", nativeBuildInputs ? [], buildInputs ? [], ... }: { + nativeBuildInputs = nativeBuildInputs ++ [ makeWrapper ]; + + buildInputs = buildInputs ++ extraPATH; + + postInstall = postInstall ++ #bash + '' + + for bin in $out/bin/wezterm*; do + wrapProgram "$bin" ${lib.escapeShellArgs wrapperArgs} + done + ''; + }) |
