From 99e466a74262a173d5233773eade74dc2667d0be Mon Sep 17 00:00:00 2001 From: Raito Bezarius Date: Tue, 17 Sep 2024 16:35:33 +0200 Subject: [PATCH] feat: add environment variables and prompt customization in login shells This way, we can configure a bit our prompt. Signed-off-by: Raito Bezarius --- modules/base.nix | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/modules/base.nix b/modules/base.nix index 41550e6..0d507a7 100644 --- a/modules/base.nix +++ b/modules/base.nix @@ -4,11 +4,13 @@ { lib, pkgs, config, ...}: let - inherit (lib) mkEnableOption mkOption types isDerivation hasAttr ; + inherit (lib) mkEnableOption mkOption types isDerivation hasAttr concatStringsSep; inherit (pkgs.pseudofile) dir symlink; inherit (pkgs.liminix.networking) address interface; inherit (pkgs.liminix.services) bundle; + # TODO: escape shell argument. + exportVar = name: value: "export ${name}=\"${value}\""; type_service = pkgs.liminix.lib.types.service; in { @@ -22,6 +24,24 @@ in { /run/current-system, we just add the paths in /etc/profile ''; }; + + environmentVariables = mkOption { + type = types.attrsOf types.str; + description = '' + Attribute set of environment variables to make available + in a login shell. + + The value is assumed to be escaped and the name to be valid. + ''; + }; + + prompt = mkOption { + type = types.str; + default = "$(whoami)@$(hostname) # "; + description = '' + Prompt string (PS1) for the shell. + ''; + }; }; services = mkOption { type = types.attrsOf type_service; @@ -111,6 +131,8 @@ in { defaultProfile.packages = with pkgs; [ s6 s6-init-bin execline s6-linux-init s6-rc ]; + # Set the useful PS1 prompt by default. + defaultProfile.environmentVariables.PS1 = lib.mkDefault config.defaultProfile.prompt; boot.commandLine = [ "panic=10 oops=panic init=/bin/init loglevel=8" @@ -181,9 +203,10 @@ in { etc = let profile = symlink (pkgs.writeScript ".profile" '' - PATH=${lib.makeBinPath config.defaultProfile.packages}:/bin + PATH=${lib.makeBinPath config.defaultProfile.packages}:/bin export PATH - ''); + ${concatStringsSep "\n" (map exportVar config.defaultProfile.environmentVariables)} + ''); in dir { inherit profile; ashrc = profile;