From 32a4fc9430d007dc31b9b56582fab7fe8cc62356 Mon Sep 17 00:00:00 2001 From: willemml Date: Wed, 8 Feb 2023 13:07:50 -0800 Subject: [PATCH] more darwin config, fix freecad --- home/darwin/launchd.nix | 6 +++ home/packages.nix | 5 +- home/programs.nix | 75 ++++++++++++++++------------- overlays/darwin-zsh-completions.nix | 32 ++++++++++++ overlays/default.nix | 1 + overlays/freecad-mac.nix | 8 +-- system/darwin.nix | 49 ++++++++++++++++++- 7 files changed, 136 insertions(+), 40 deletions(-) create mode 100644 overlays/darwin-zsh-completions.nix diff --git a/home/darwin/launchd.nix b/home/darwin/launchd.nix index 07cb2a1..c32ff9e 100644 --- a/home/darwin/launchd.nix +++ b/home/darwin/launchd.nix @@ -33,6 +33,12 @@ "${pkgs.pass}/bin/pass 'music/spotify' | head -n1" "--backend" "portaudio" + "--bitrate" + "320" + "--device-type" + "computer" + "--volume_controller" + "softvol" ]; KeepAlive = true; UserName = "${config.home.username}"; diff --git a/home/packages.nix b/home/packages.nix index 4712e6c..b555890 100644 --- a/home/packages.nix +++ b/home/packages.nix @@ -14,7 +14,7 @@ let spotify-mac vlc-mac ]; - linux = with pkgs; [ vlc qbittorrent ]; + linux = with pkgs; [ vlc qbittorrent freecad spotify ]; pass-extended = pkgs.pass.withExtensions (exts: [ exts.pass-genphrase exts.pass-otp exts.pass-import ]); python-wp = pkgs.python310.withPackages (p: with p; [ setuptools pyaml requests latexify-py ]); node-packages = with pkgs.nodePackages; [ bash-language-server ]; @@ -44,6 +44,7 @@ in htop jq nix-review + nix-zsh-completions nixfmt nixpkgs-fmt nmap @@ -59,6 +60,7 @@ in rsync rustup shellcheck + shfmt spotify-tui spotifyd sqlite @@ -71,6 +73,7 @@ in unzip wget yq + zsh-completions ] ++ lib.optionals stdenv.isDarwin darwin ++ lib.optionals stdenv.isLinux linux diff --git a/home/programs.nix b/home/programs.nix index e1b4f42..dc64768 100644 --- a/home/programs.nix +++ b/home/programs.nix @@ -2,6 +2,8 @@ { programs = { + bash.enableCompletion = true; + browserpass = { enable = true; browsers = [ @@ -138,57 +140,62 @@ zsh = { enable = true; - enableCompletion = true; - enableSyntaxHighlighting = true; - enableVteIntegration = true; + autocd = true; defaultKeymap = "emacs"; - envExtra = '' - #!/usr/bin/env zsh - export GPG_TTY=$(tty) - eval $(gpg-agent --daemon -q 2>/dev/null) - - function gsearch() { - open -a Safari "https://google.com/search?q=$(echo $@ | sed -e 's/ /%20/g')" - } - - function plistxml2nix() { - tail -n +4 | - sed -e "s//{/g" \ - -e "s/<\/dict>/\}\;/g" \ - -e "s//\"/g" \ - -e "s/<\/key>/\"=/g" \ - -e "s///g" \ - -e "s/<\/real>/;/g" \ - -e "s///g" \ - -e "s/<\/integer>/;/g" \ - -e "s//\"/g" \ - -e "s/<\/string>/\"\;/g" \ - -e "s//\[/g" \ - -e "s/<\/array>/\];/g" \ - -e "s//true;/g" \ - -e "s//false;/g" \ - -e "$ d" | - sed \-e "$ s/;//" - } - ''; dotDir = ".config/zsh"; + enableAutosuggestions = true; + enableCompletion = true; + enableSyntaxHighlighting = true; + enableVteIntegration = true; + history = { path = "$HOME/.local/zsh/history"; extended = true; ignoreDups = true; }; + + historySubstringSearch.enable = true; + + loginExtra = '' + #!/usr/bin/env zsh + export GPG_TTY=$(tty) + eval $(gpg-agent --daemon -q 2>/dev/null) + function gsearch() { + open -a Safari "https://google.com/search?q=$(echo $@ | sed -e 's/ /%20/g')" + } + function plistxml2nix() { + tail -n +4 | + sed -e "s//{/g" \ + -e "s/<\/dict>/\}\;/g" \ + -e "s//\"/g" \ + -e "s/<\/key>/\"=/g" \ + -e "s///g" \ + -e "s/<\/real>/;/g" \ + -e "s///g" \ + -e "s/<\/integer>/;/g" \ + -e "s//\"/g" \ + -e "s/<\/string>/\"\;/g" \ + -e "s//\[/g" \ + -e "s/<\/array>/\];/g" \ + -e "s//true;/g" \ + -e "s//false;/g" \ + -e "$ d" | + sed \-e "$ s/;//" + } + ''; + shellAliases = { cd = "z"; + drs = "darwin-rebuild switch --flake ${config.home.homeDirectory}/.config/dotfiles.nix#"; e = "emacsclient -c -nw"; em = "emacs -nw"; + emw = "emacs"; ew = "emacsclient -c"; - drs = "darwin-rebuild switch --flake ${config.home.homeDirectory}/.config/dotfiles.nix#"; l = "ls -1"; np = "nix-shell -p"; org = "z ${config.home.sessionVariables.ORGDIR}"; ubc = "z ${config.home.sessionVariables.UBCDIR}"; - emw = "emacs"; }; }; diff --git a/overlays/darwin-zsh-completions.nix b/overlays/darwin-zsh-completions.nix new file mode 100644 index 0000000..7f4b473 --- /dev/null +++ b/overlays/darwin-zsh-completions.nix @@ -0,0 +1,32 @@ +# taken from nix-darwin repo +# https://github.com/LnL7/nix-darwin/blob/87b9d090ad39b25b2400029c64825fc2a8868943/modules/examples/lnl.nix +{ pkgs, stdenv, ... }: + +stdenv.runCommand "darwin-zsh-completions-0.0.0" +{ preferLocalBuild = true; } + '' + mkdir -p $out/share/zsh/site-functions + cat <<-'EOF' > $out/share/zsh/site-functions/_darwin-rebuild + #compdef darwin-rebuild + #autoload + _nix-common-options + local -a _1st_arguments + _1st_arguments=( + 'switch:Build, activate, and update the current generation'\ + 'build:Build without activating or updating the current generation'\ + 'check:Build and run the activation sanity checks'\ + 'changelog:Show most recent entries in the changelog'\ + ) + _arguments \ + '--list-generations[Print a list of all generations in the active profile]'\ + '--rollback[Roll back to the previous configuration]'\ + {--switch-generation,-G}'[Activate specified generation]'\ + '(--profile-name -p)'{--profile-name,-p}'[Profile to use to track current and previous system configurations]:Profile:_nix_profiles'\ + '1:: :->subcmds' && return 0 + case $state in + subcmds) + _describe -t commands 'darwin-rebuild subcommands' _1st_arguments + ;; + esac + EOF + '' diff --git a/overlays/default.nix b/overlays/default.nix index 9af41ba..5eb498d 100644 --- a/overlays/default.nix +++ b/overlays/default.nix @@ -1,5 +1,6 @@ self: super: { chromium-mac = super.callPackage ./chromium-mac.nix { pkgs = super; }; + darwin-zsh-completions = import ./darwin-zsh-completions.nix { pkgs = super; }; firefox-mac = super.callPackage ./firefox-mac.nix { pkgs = super; }; freecad-mac = super.callPackage ./freecad-mac.nix { pkgs = super; }; pinentry-touchid = super.callPackage ./pinentry-touchid.nix { pkgs = super; }; diff --git a/overlays/freecad-mac.nix b/overlays/freecad-mac.nix index 799ec71..873ea5b 100644 --- a/overlays/freecad-mac.nix +++ b/overlays/freecad-mac.nix @@ -1,15 +1,15 @@ { pkgs, fetchurl, ... }: let - version = "31483"; - date = "2022-12-31"; + version = "0.20.2"; + date = "2022-12-27"; appName = "FreeCAD"; pname = "freecad"; src = fetchurl { url = - "https://github.com/FreeCAD/FreeCAD-Bundle/releases/download/weekly-builds/FreeCAD_weekly-builds-${version}-${date}-conda-macOS-arm-py311.dmg"; - sha256 = "sha256-dm6QbAazx1vFrkakkCsfCqyGzRED9guI7yFMQ24mU9o="; + "https://github.com/FreeCAD/FreeCAD/releases/download/${version}/FreeCAD_${version}-${date}-conda-macOS-x86_64-py310.dmg"; + sha256 = "sha256-OAi98HUacHcLHVYSadnQFPnEhutJvE4YfRBtPSZk00c="; }; in pkgs.stdenv.mkDerivation { diff --git a/system/darwin.nix b/system/darwin.nix index d92940b..b736da3 100644 --- a/system/darwin.nix +++ b/system/darwin.nix @@ -1,6 +1,22 @@ { pkgs, ... }: { + environment.etc."nix/user-sandbox.sb".text = '' + (version 1) + (allow default) + (deny file-write* + (subpath "/nix")) + (allow file-write* + (subpath "/nix/var/nix/gcroots/per-user") + (subpath "/nix/var/nix/profiles/per-user")) + (allow process-exec + (literal "/bin/ps") + (with no-sandbox)) + ''; + + environment.loginShell = "${pkgs.zsh}/bin/zsh -l"; + environment.variables.SHELL = "${pkgs.zsh}/bin/zsh"; + environment.variables.LANG = "en_US.UTF-8"; environment.systemPackages = with pkgs; [ ]; nix = { @@ -15,8 +31,39 @@ }; programs.bash.enable = true; - + + programs.nix-index.enable = true; + programs.zsh.enable = true; + programs.zsh.enableBashCompletion = true; + programs.zsh.enableFzfCompletion = true; + programs.zsh.enableFzfGit = true; + programs.zsh.enableFzfHistory = true; + programs.zsh.loginShellInit = '' + reexec() { + unset __NIX_DARWIN_SET_ENVIRONMENT_DONE + unset __ETC_ZPROFILE_SOURCED __ETC_ZSHENV_SOURCED __ETC_ZSHRC_SOURCED + exec $SHELL -c 'echo >&2 "reexecuting shell: $SHELL" && exec $SHELL -l' + } + reexec-sandbox() { + unset __NIX_DARWIN_SET_ENVIRONMENT_DONE + unset __ETC_ZPROFILE_SOURCED __ETC_ZSHENV_SOURCED __ETC_ZSHRC_SOURCED + export IN_NIX_SANDBOX=1 + exec /usr/bin/sandbox-exec -f /etc/nix/user-sandbox.sb $SHELL -l + } + ''; + programs.zsh.promptInit = '' + autoload -U promptinit && promptinit + setopt PROMPTSUBST + _prompt_nix() { + [ -z "$IN_NIX_SHELL" ] || echo "%F{yellow}%B[''${name:+$name}]%b%f " + } + PS1='%F{red}%B%(?..%? )%b%f%# ' + RPS1='$(_prompt_nix)%F{green}%~%f' + if [ -n "$IN_NIX_SANDBOX" ]; then + PS1+='%F{red}[sandbox]%f ' + fi + ''; services.nix-daemon.enable = true;