aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--flake.nix54
-rw-r--r--modules/flake-module.nix137
-rw-r--r--overlays/default.nix6
-rw-r--r--pkgs/weznix.nix86
5 files changed, 181 insertions, 103 deletions
diff --git a/.gitignore b/.gitignore
index 726d2d6..7e8dd8e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
result
.direnv
+.envrc
diff --git a/flake.nix b/flake.nix
index 6ab086f..f38ee8d 100644
--- a/flake.nix
+++ b/flake.nix
@@ -1,5 +1,5 @@
{
- description = "Wezterm configuration a la nixCats";
+ description = "Wezterm configuration à la nixCats";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs";
@@ -15,9 +15,13 @@
};
};
- outputs = inputs@{ self, flake-parts, ... }: let
- weznix = import ./modules/flake-module.nix;
- in flake-parts.lib.mkFlake { inherit inputs self; } {
+ outputs =
+ inputs@{ flake-parts, ... }:
+ let
+ weznix = import ./modules/flake-module.nix;
+ nixToLua = import inputs.nixToLua;
+ in
+ flake-parts.lib.mkFlake { inherit inputs; } {
systems = import inputs.systems;
imports = [
@@ -26,33 +30,35 @@
];
flake = {
- overlays.default = import ./overlays { nixToLua = import inputs.nixToLua; };
+ overlays.default = _final: prev: { weznix = prev.callPackage ./pkgs/weznix { inherit nixToLua; }; };
flakeModules.default = weznix;
};
- perSystem = { system, pkgs, config, ... }: {
- treefmt = {
- programs.nixfmt = {
- enable = true;
- strict = true;
+ perSystem =
+ { pkgs, config, ... }:
+ {
+ treefmt = {
+ programs.nixfmt = {
+ enable = true;
+ strict = true;
+ };
};
- };
- devShells.default = pkgs.mkShellNoCC {
- inputsFrom = [ config.treefmt.devShell ];
- nativeBuildInputs = with pkgs; [
- nixd
- statix
- deadnix
- ];
- };
+ devShells.default = pkgs.mkShellNoCC {
+ inputsFrom = [ config.treefmt.build.devShell ];
+ nativeBuildInputs = with pkgs; [
+ nixd
+ statix
+ deadnix
+ ];
+ };
- weznix = {
- wrapConfig = true;
- luaPath = ./test;
- };
+ weznix = {
+ wrapConfig = true;
+ luaPath = ./test;
+ };
- };
+ };
};
}
diff --git a/modules/flake-module.nix b/modules/flake-module.nix
index af1e799..341e048 100644
--- a/modules/flake-module.nix
+++ b/modules/flake-module.nix
@@ -1,51 +1,102 @@
-{ lib, flake-parts-lib, inputs, ... }:
+{
+ lib,
+ flake-parts-lib,
+ inputs,
+ ...
+}:
let
inherit (lib) mkOption mkPackageOption types;
inherit (flake-parts-lib) mkPerSystemOption;
-in {
- options.perSystem = mkPerSystemOption ({ 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";
+in
+{
+ options.perSystem = mkPerSystemOption (
+ { pkgs, config, ... }:
+ {
+ options = {
+ weznix = {
+ wezterm = mkPackageOption pkgs "wezterm" { };
+ configDirectory = mkOption {
+ type = types.str;
+ default = "~/.config/wezterm";
+ description = ''
+ Location of wezterm config directory (see config.weznix.wrapConfig).
+ '';
+ };
+ luaPath = mkOption {
+ type = types.path;
+ description = ''
+ Path to wezterm config directory.
+ This path is copied into the nix store.
+ '';
+ };
+ mainFile = mkOption {
+ type = types.str;
+ default = "init";
+ apply = lib.removeSuffix ".lua";
+ description = "Name of the main *.lua file to load";
+ };
+ wrapConfig = mkOption {
+ type = types.either types.bool types.str;
+ default = "WEZDEV";
+ description = ''
+ true -> use config in nix store
+ false -> use config in ${config.weznix.configDirectory}
+ ENVVAR -> if $ENVVAR == 1
+ then use config in ${config.weznix.configDirectory}
+ else use config in nix store
+ '';
+ };
+ extraLuaInit = mkOption {
+ type = types.lines;
+ default = "";
+ description = ''
+ Extra lua code to place in the generated wezterm.lua.
+ This is likely unnecessary.
+ '';
+ };
+ 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.
+ These values can then be accessed in your lua config from the table `require('weznix')`.
+ '';
+ };
};
};
- };
- 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;
- };
+ config = {
+ packages = {
+ weznix =
+ pkgs.callPackage ../pkgs/weznix.nix
+ {
+ inherit (config.weznix) wezterm;
+ nixToLua = import inputs.nixToLua;
+ }
+ {
+ inherit (config.weznix)
+ configDirectory
+ luaPath
+ wrapConfig
+ mainFile
+ extraLuaInit
+ extraPATH
+ extraWrapperArgs
+ pass
+ ;
+ };
+ };
};
- };
- });
+ }
+ );
}
diff --git a/overlays/default.nix b/overlays/default.nix
deleted file mode 100644
index 9789980..0000000
--- a/overlays/default.nix
+++ /dev/null
@@ -1,6 +0,0 @@
-{ nixToLua, ... }:
-_final: prev: {
- weznix = prev.callPackage ../pkgs/weznix.nix {
- inherit nixToLua;
- };
-}
diff --git a/pkgs/weznix.nix b/pkgs/weznix.nix
index 333488e..5339e32 100644
--- a/pkgs/weznix.nix
+++ b/pkgs/weznix.nix
@@ -1,4 +1,5 @@
-{ wezterm,
+{
+ wezterm,
makeWrapper,
writeText,
nixToLua,
@@ -8,46 +9,70 @@
configDirectory ? "~/.config/wezterm",
wrapConfig ? "WEZDEV",
luaPath,
- extraWrapperArgs ? [],
- extraPATH ? [],
- pass ? {},
-}: let
+ mainFile ? "init",
+ extraLuaInit ? "",
+ extraWrapperArgs ? [ ],
+ extraPATH ? [ ],
+ pass ? { },
+}:
+let
inherit (nixToLua) toLua;
passables = {
inherit configDirectory wrapConfig luaPath;
wezterm = builtins.toString wezterm;
- } // pass;
+ mainFile =
+ if (mainFile == "wezterm" || mainFile == "weznix") then
+ throw "mainFile cannot be named 'wezterm' or 'weznix'"
+ else
+ mainFile;
+ }
+ // pass;
- wezinit = writeText "wezterm.lua" # lua
- ''
- package.preload["weznix"] = function()
- return ${toLua passables}
- end
+ wezinit =
+ writeText "wezterm.lua" # lua
+ ''
+ package.preload["weznix"] = function()
+ return ${toLua passables}
+ end
- weznix = require('weznix')
+ local 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
+ local cfgDir = weznix.luaPath
+ if (weznix.wrapConfig == false) or (type(weznix.wrapConfig) == "string" and os.getenv(weznix.wrapConfig) == "1") then
+ cfgDir = weznix.configDirectory
+ end
- wezterm = require('wezterm')
- wezterm.config_dir = cfgDir
+ local wezterm = require('wezterm')
+ wezterm.config_dir = cfgDir
- package.path = cfgDir .. '/?.lua'
- package.cpath = package.cpath .. ';' .. cfgDir .. '/?.so'
+ package.path = cfgDir .. '/?.lua'
+ package.cpath = package.cpath .. ';' .. cfgDir .. '/?.so'
+ ${extraLuaInit}
- return require('init')
- '';
+ return require(weznix.mainFile)
+ '';
wrapperArgs = [
- "--set" "WEZTERM_CONFIG_FILE" (toString wezinit)
- ] ++ lib.optionals (extraPATH != []) [
- "--prefix" "PATH" ":" (lib.makeBinPath extraPATH)
- ] ++ extraWrapperArgs;
-
-in wezterm.overrideAttrs ({ nativeBuildInputs ? [], ... }: {
+ "--set"
+ "WEZTERM_CONFIG_FILE"
+ (builtins.toString wezinit)
+ ]
+ ++ lib.optionals (extraPATH != [ ]) [
+ "--prefix"
+ "PATH"
+ ":"
+ (lib.makeBinPath extraPATH)
+ ]
+ ++ extraWrapperArgs;
+
+in
+wezterm.overrideAttrs (
+ {
+ nativeBuildInputs ? [ ],
+ ...
+ }:
+ {
nativeBuildInputs = nativeBuildInputs ++ [ makeWrapper ];
separateDebugInfo = false;
@@ -78,7 +103,8 @@ in wezterm.overrideAttrs ({ nativeBuildInputs ? [], ... }: {
sed "s|${wezterm.out}|$out|g" "$src" > "$dsk"
done
- shopt -u nullglob # Revert nullglob back to its normal default state
+ shopt -u nullglob
'';
- })
+ }
+)