diff options
author | Karel Kočí <cynerd@email.cz> | 2022-06-11 22:05:17 +0200 |
---|---|---|
committer | Karel Kočí <cynerd@email.cz> | 2022-06-11 22:29:52 +0200 |
commit | f6b661ebf0cbd9ecae64eb1f757dc1b4073b1d73 (patch) | |
tree | 9a6d19a0e248f07133b4b0efa57e47dd2f125baa | |
parent | fe900d86a3ade098bad9d99d7c53806df32a9077 (diff) | |
download | shellrc-f6b661ebf0cbd9ecae64eb1f757dc1b4073b1d73.tar.gz shellrc-f6b661ebf0cbd9ecae64eb1f757dc1b4073b1d73.tar.bz2 shellrc-f6b661ebf0cbd9ecae64eb1f757dc1b4073b1d73.zip |
Allow using in nix develop and use prompt to signal it
-rw-r--r-- | bashrc.d/prompt | 4 | ||||
-rw-r--r-- | flake.lock | 21 | ||||
-rw-r--r-- | flake.nix | 98 |
3 files changed, 75 insertions, 48 deletions
diff --git a/bashrc.d/prompt b/bashrc.d/prompt index dee3e53..6632037 100644 --- a/bashrc.d/prompt +++ b/bashrc.d/prompt @@ -1,8 +1,10 @@ # vim: ft=sh PS1='$( -if [ `id -u` -eq "0" ]; then +if [ "$(id -u)" -eq "0" ]; then echo -n "\[\e[1;31m\]\u@\h:\[\e[1;34m\]\W\[\e[1;31m\]\$\[\e[0m\] " +elif [ "${_SHELLRC:-}" = "develop" ]; then + echo -n "\[\e[1;33m\]\u@\h:\[\e[1;34m\]\W\[\e[1;33m\]\$\[\e[0m\] " else echo -n "\[\e[1;32m\]\u@\h:\[\e[1;34m\]\W\[\e[1;32m\]\$\[\e[0m\] " fi)' @@ -1,12 +1,26 @@ { "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1653893745, + "narHash": "sha256-0jntwV3Z8//YwuOjzhV2sgJJPt+HY6KhU7VZUL0fKZQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "1ed9fb1935d260de5fe1c2f7ee0ebaae17ed2fa1", + "type": "github" + }, + "original": { + "id": "flake-utils", + "type": "indirect" + } + }, "nixpkgs": { "locked": { - "lastModified": 1648219316, - "narHash": "sha256-Ctij+dOi0ZZIfX5eMhgwugfvB+WZSrvVNAyAuANOsnQ=", + "lastModified": 1654875595, + "narHash": "sha256-Vairke3ryPSFpgQdaYicPPhPWMGhtzm6V+1uF2Tefbk=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "30d3d79b7d3607d56546dd2a6b49e156ba0ec634", + "rev": "3f909fb574d9b9d7294e544981c62a4a5e4599fc", "type": "github" }, "original": { @@ -16,6 +30,7 @@ }, "root": { "inputs": { + "flake-utils": "flake-utils", "nixpkgs": "nixpkgs" } } @@ -1,11 +1,20 @@ { description = "Cynerd's shell configuration"; - outputs = { self, nixpkgs }: { + outputs = { self, flake-utils, nixpkgs }: + let - nixosModule = { config, lib, pkgs, ... }: - with lib; - let + loadrc = dir: '' + for sh in ${dir}/*; do + [ -r "$sh" ] && . "$sh" + done + ''; + commonrc = loadrc ./shellrc.d; + desktoprc = loadrc ./shellrc-desktop.d; + bashrc = loadrc ./bashrc.d; + zshrc = loadrc ./zshrc.d; + + packages = pkgs: rec { shellrc-completion = pkgs.stdenv.mkDerivation rec { name = "shellrc-completion"; src = ./.; @@ -18,56 +27,57 @@ installShellCompletion --zsh --name "$${comp##*/}" "$comp" done ''; + shellHook = commonrc + bashrc + '' + export _SHELLRC=develop + ''; }; - in { + default = shellrc-completion; + }; - options = { - programs.shellrc = { - enable = mkOption { - type = types.bool; - default = true; - description = "If shellrc should be enabled."; - }; - desktop = mkOption { - type = types.bool; - default = false; - description = "If shellrc's desktop specific files should be used."; + in { + + overlays = { + shellrc = final: prev: packages prev; + default = self.overlay.shellrc; + }; + + nixosModules = { + shellrc = { config, lib, pkgs, ... }: with lib; { + options = { + programs.shellrc = { + enable = mkOption { + type = types.bool; + default = true; + description = "If shellrc should be enabled."; + }; + desktop = mkOption { + type = types.bool; + default = false; + description = "If shellrc's desktop specific files should be used."; + }; }; }; - }; - config = mkIf config.programs.shellrc.enable { - environment.interactiveShellInit = '' - for sh in ${./shellrc.d}/*; do - [ -r "$sh" ] && . "$sh" - done - '' + optionalString config.programs.shellrc.desktop '' - for sh in ${./shellrc-desktop.d}/*; do - [ -r "$sh" ] && . "$sh" - done - ''; + config = mkIf config.programs.shellrc.enable { - programs.bash.interactiveShellInit = '' - for sh in ${./bashrc.d}/*; do - [ -r "$sh" ] && . "$sh" - done - ''; - programs.bash.promptInit = ""; # Disable default prompt as we have our own + environment.interactiveShellInit = commonrc + optionalString config.programs.shellrc.desktop desktoprc; - programs.zsh.interactiveShellInit = mkIf config.programs.zsh.enable '' - for sh in ${./zshrc.d}/*; do - [ -r "$sh" ] && . "$sh" - done - ''; - programs.zsh.promptInit = ""; # Disable default prompt as we have our own + programs.bash.interactiveShellInit = bashrc; + programs.bash.promptInit = ""; # Disable default prompt as we have our own - environment.systemPackages = [ - shellrc-completion - ]; + programs.zsh.interactiveShellInit = mkIf config.programs.zsh.enable zshrc; + programs.zsh.promptInit = ""; # Disable default prompt as we have our own - }; + nixpkgs.overlays = [ self.overlays.shellrc ]; + environment.systemPackages = [ pkgs.shellrc-completion ]; + }; + }; + default = self.nixosModules.shellrc; }; - }; + } // (flake-utils.lib.eachDefaultSystem (system: { + packages = packages nixpkgs.legacyPackages.${system}; + })); + } |