From fcfded4893dc445d04b304fb2aa8d6f9d4f96d59 Mon Sep 17 00:00:00 2001 From: Giulio De Pasquale Date: Sun, 19 Mar 2023 12:23:48 -0700 Subject: [PATCH] common: pastebinit optional on Darwin --- roles/home/common.nix | 10 +++++++- roles/home/zsh.nix | 55 +++++++++++++++++++++++++++++++++++-------- 2 files changed, 54 insertions(+), 11 deletions(-) diff --git a/roles/home/common.nix b/roles/home/common.nix index 434b4e0..d2bb1ce 100644 --- a/roles/home/common.nix +++ b/roles/home/common.nix @@ -4,7 +4,15 @@ imports = [ ./zsh.nix ./git.nix ./helix.nix ]; home = { - packages = with pkgs; [ rizin sshfs victor-mono home-manager ripgrep pastebinit ]; + packages = with pkgs; [ + rizin + sshfs + victor-mono + home-manager + ripgrep + ] + ++ lib.optional (!stdenv.isDarwin) [ pastebinit ]; + stateVersion = "22.11"; }; } diff --git a/roles/home/zsh.nix b/roles/home/zsh.nix index f3b962f..ad9233d 100644 --- a/roles/home/zsh.nix +++ b/roles/home/zsh.nix @@ -1,4 +1,41 @@ -{ config, pkgs, lib, ... }: { +{ config, pkgs, lib, optionalString, ... }: + +let + inherit (pkgs.lib) optionalString; + + # not having the attribute users means + # we cannot change the default shell (e.g. this is not a NixOS host) + exec_zsh = '' + if [ -f "$HOME/.bashrc" ]; then + . "$HOME/.bashrc" + fi + + exec ${pkgs.zsh}/bin/zsh + ''; + + nix_run_fn = '' + function _nr { + if [ "$#" -lt 1 ]; then + echo "Usage: _nr " + return + fi + + quoted_args=() + local pkg=$1 + shift 1 + + for a in "$@"; do + quoted_args+=("\"$a\"") + done + + echo ''${quoted_args[@]} + +# `nix run nixpkgs#$pkg -- ''${quoted_args[@]}` + exec nix run nixpkgs#$pkg "$@" + } + ''; +in +{ programs.zsh = { enable = true; @@ -9,14 +46,12 @@ }; }; - home.file.".bash_profile".text = - # not having the attribute users means - # we cannot change the default shell (e.g. this is not a NixOS host) - if ! builtins.hasAttr "users" config then '' - if [ -f "$HOME/.bashrc" ]; then - . "$HOME/.bashrc" - fi + home.file.".bashrc".text = '' + ${nix_run_fn} + + ${optionalString (!builtins.hasAttr "users" config) "${exec_zsh}"} + ''; - exec ${pkgs.zsh}/bin/zsh - '' else null; + home.file.".zshrc".text = nix_run_fn; } +