flake: { pkgs }: with pkgs.lib; let mapAttrsToLines = mapping: attrs: concatStringsSep "\n" (mapAttrsToList mapping attrs); fmt = rec { codeBlock = code: text: ''"\e[${code}m"${escapeShellArg text}"\e[0m"''; keyword = codeBlock "1;36"; section = codeBlock "4;35"; printSectionTitle = title: ''echo -e "\n"${section title}''; }; in rec { ifSomeAttrs = attrs: f: pkgs.lib.optionalString (attrs != {}) (f attrs); ifSomeList = list: f: pkgs.lib.optionalString (list != []) (f list); exportEnvVar = k: v: '' export ${escapeShellArg k}="${v}" ''; exportEnvVars = mapAttrsToLines exportEnvVar; printEnvVar = k: v: '' echo -e ${fmt.keyword ("$" + k)}: ${escapeShellArg v} ''; printEnvVars = envVars: '' ${fmt.printSectionTitle "ENVIRONMENT VARIABLES"} ${mapAttrsToLines printEnvVar envVars} ''; printBins = packagePaths: '' ${fmt.printSectionTitle "ENVIRONMENT PROGRAMS"} ls "${pkgs.symlinkJoin { name = "env"; paths = packagePaths; }}/bin" ''; # Use the default user shell instead of Bash startUserShell = '' $(${pkgs.finger_bsd}/bin/finger $USER \ | ${pkgs.gnugrep}/bin/grep -oP 'Shell: \K.*') ''; }