From d345455cc91df176b2b1ec7d50e67967c3f18c0c Mon Sep 17 00:00:00 2001 From: Stefan Weigl-Bosker Date: Wed, 5 Mar 2025 15:05:06 -0500 Subject: more improvements to service management --- modules/default.nix | 2 +- modules/global.nix | 1 + modules/services/default.nix | 34 ++++++++++++++++++++++++++---- modules/zsh.nix | 27 ------------------------ modules/zsh/default.nix | 41 +++++++++++++++++++++++++++++++++++++ modules/zsh/themes/stefan.zsh-theme | 9 ++++++++ 6 files changed, 82 insertions(+), 32 deletions(-) delete mode 100644 modules/zsh.nix create mode 100644 modules/zsh/default.nix create mode 100644 modules/zsh/themes/stefan.zsh-theme (limited to 'modules') diff --git a/modules/default.nix b/modules/default.nix index f924c45..a0510dc 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -4,7 +4,7 @@ ./foot.nix ./mako.nix ./neovide.nix - ./zsh.nix + ./zsh ./sway ./neovim ./qutebrowser diff --git a/modules/global.nix b/modules/global.nix index 5565476..adedc50 100644 --- a/modules/global.nix +++ b/modules/global.nix @@ -31,6 +31,7 @@ in qutebrowser = { wrapWithNixGL = cfg.notNixOS; }; + zsh.enable = true; }; nixGL = lib.mkIf cfg.notNixOS { diff --git a/modules/services/default.nix b/modules/services/default.nix index 7409c59..b0d9d9a 100644 --- a/modules/services/default.nix +++ b/modules/services/default.nix @@ -3,11 +3,16 @@ let cfg = config.modules.services; inherit (lib) mkOption types listOf; - runFile = name: value: { + mkService = name: value: { ${"service/" + name + "/run"} = { text = value.run; executable = true; }; + ${"service/" + name + "/log/run"} = { + enable = value.log != ""; + text = value.log; + executable = true; + }; }; in { @@ -20,6 +25,12 @@ in default = false; description = "Whether to enable the user service manager module."; }; + coreServices = mkOption { + type = types.listOf types.str; + description = "List of services to start first"; + example = [ "dbus" ]; + default = []; + }; services = mkOption { description = "List of user services to run on login"; type = types.attrsOf (types.submodule { @@ -27,18 +38,33 @@ in run = mkOption { type = types.str; description = "The 'run' script for the service"; - example = '' - #!/bin/sh + example = + ''#!/bin/sh exec chpst -e "$TURNSTILE_ENV_DIR" foo ''; }; + log = mkOption { + type = types.nullOr types.str; + description = "The log/run script for the service. A pipe is opened from the output of the 'run' process to this script"; + example = + ''#!/bin/sh + + exec vlogger -t dbus-$(id -u) -p daemon + ''; + default = ""; + }; }; }); }; }; config = lib.mkIf cfg.enable { - xdg.configFile = (lib.concatMapAttrs runFile cfg.services); + xdg.configFile = (lib.concatMapAttrs mkService cfg.services) + // { + "service/turnstile-ready/conf" = { + text = ''core_services="${lib.strings.concatStringsSep " " cfg.coreServices}''; + }; + }; }; } diff --git a/modules/zsh.nix b/modules/zsh.nix deleted file mode 100644 index 5085263..0000000 --- a/modules/zsh.nix +++ /dev/null @@ -1,27 +0,0 @@ -{ config, lib, pkgs, ... }: -let - cfg = config.modules.zsh; -in -{ - options.modules.zsh = { - enable = lib.mkEnableOption "zsh"; - }; - - config = { - home.packages = with pkgs; [ - zsh - oh-my-zsh - zsh-autosuggestions - ]; - - programs.zsh = lib.mkIf cfg.enable { - enable = true; - enableCompletion = true; - autosuggestion.enable = true; - oh-my-zsh = { - enable = true; - theme = "lambda"; - }; - }; - }; -} diff --git a/modules/zsh/default.nix b/modules/zsh/default.nix new file mode 100644 index 0000000..b1ed82e --- /dev/null +++ b/modules/zsh/default.nix @@ -0,0 +1,41 @@ +{ config, lib, pkgs, ... }: +let + cfg = config.modules.zsh; + + inherit (lib) mkEnableOption mkOption mkIf types; +in +{ + options.modules.zsh = { + enable = mkEnableOption "zsh"; + theme = mkOption { + type = types.str; + description = "name of zsh theme to apply"; + default = "stefan"; + }; + }; + + config = mkIf cfg.enable { + home.packages = with pkgs; [ + zsh + oh-my-zsh + zsh-autosuggestions + ]; + + home.file.".oh-my-zsh/themes" = { + source = ./themes; + recursive = true; + }; + + programs.zsh = { + enable = true; + enableCompletion = true; + autosuggestion.enable = true; + oh-my-zsh = { + enable = true; + }; + initExtra = '' + source ~/.oh-my-zsh/themes/${cfg.theme}.zsh-theme + ''; + }; + }; +} diff --git a/modules/zsh/themes/stefan.zsh-theme b/modules/zsh/themes/stefan.zsh-theme new file mode 100644 index 0000000..4d71d9c --- /dev/null +++ b/modules/zsh/themes/stefan.zsh-theme @@ -0,0 +1,9 @@ +function virtualenv_info { + [ $VIRTUAL_ENV ] && echo '('`basename $VIRTUAL_ENV`') ' +} + +NEWLINE=$'\n' +PROMPT="%F{magenta}%~% %f% %F{yellow}% ${NEWLINE}λ %b%f%" +RPROMPT='$(virtualenv_info)% $(git_prompt_info)' +ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[green]%}" +ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}" -- cgit v1.2.3