common: pastebinit optional on Darwin

This commit is contained in:
Giulio De Pasquale 2023-03-19 12:23:48 -07:00
parent 73f5f403f7
commit fcfded4893
2 changed files with 54 additions and 11 deletions

View File

@ -4,7 +4,15 @@
imports = [ ./zsh.nix ./git.nix ./helix.nix ]; imports = [ ./zsh.nix ./git.nix ./helix.nix ];
home = { 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"; stateVersion = "22.11";
}; };
} }

View File

@ -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 <pkg>"
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 = { programs.zsh = {
enable = true; enable = true;
@ -9,14 +46,12 @@
}; };
}; };
home.file.".bash_profile".text = home.file.".bashrc".text = ''
# not having the attribute users means ${nix_run_fn}
# we cannot change the default shell (e.g. this is not a NixOS host)
if ! builtins.hasAttr "users" config then '' ${optionalString (!builtins.hasAttr "users" config) "${exec_zsh}"}
if [ -f "$HOME/.bashrc" ]; then '';
. "$HOME/.bashrc"
fi
exec ${pkgs.zsh}/bin/zsh home.file.".zshrc".text = nix_run_fn;
'' else null;
} }