From 24bc7e92844be8145f73920c130406c1382b0480 Mon Sep 17 00:00:00 2001 From: willemml Date: Sat, 4 Feb 2023 10:59:10 -0800 Subject: [PATCH] add firefox + chromium + browserpass --- darwin/default.nix | 42 +++++++++++++++++- emacs.nix | 21 ++++----- flake.lock | 10 ++--- flake.nix | 15 ++++--- home.nix | 27 ++++-------- overlays/chromium-mac.nix | 27 ++++++++++++ overlays/default.nix | 2 + overlays/firefox-mac.nix | 12 ++++++ overlays/mk-mac-binpkg.nix | 25 +++++++++++ overlays/qbittorrent-mac.nix | 26 ++--------- overlays/vlc-mac.nix | 34 ++++----------- packages.nix | 3 +- programs.nix | 83 ++++++++++++++++++++++-------------- 13 files changed, 203 insertions(+), 124 deletions(-) create mode 100644 overlays/chromium-mac.nix create mode 100644 overlays/firefox-mac.nix create mode 100644 overlays/mk-mac-binpkg.nix diff --git a/darwin/default.nix b/darwin/default.nix index 18b78aa..1ba4e43 100644 --- a/darwin/default.nix +++ b/darwin/default.nix @@ -1,8 +1,48 @@ { config, pkgs, lib, inputs, ... }: -{ +let + inherit (lib) mkIf; + inherit (pkgs) stdenv; + appCommands = { + calibre = "Calibre"; + discord = "Discord"; + email = "Mail"; + ical = "Calendar"; + im = "Messages"; + maps = "Maps"; + music = "Music"; + settings = "System Settings"; + spotify = "Spotify"; + web = "Safari"; + zotero = "Zotero"; + }; +in { imports = [ ./launchd.nix ./apps.nix ]; + home.file.".gnupg/gpg-agent.conf".text = mkIf stdenv.isDarwin '' + pinentry-program "${pkgs.pinentry-touchid}/bin/pinentry-touchid" + default-cache-ttl 30 + max-cache-ttl 600 + ''; + + home.file.".config/zsh/am.sh" = mkIf stdenv.isDarwin { + executable = true; + source = builtins.fetchurl { + url = "https://raw.githubusercontent.com/mcthomas/Apple-Music-CLI-Player/27353ec55abac8b5d73b8a061fb87f305c663adb/src/am.sh"; + sha256 = "sha256-78zRpNg7/OR7p8dpsJt6Xc4j0Y+8zSUtm/PT94nf03M="; + }; + }; + + programs.zsh.shellAliases = mkIf stdenv.isDarwin ({ + am = lib.mkIf pkgs.stdenv.isDarwin "zsh ~/.config/zsh/am.sh"; + o = "open"; + oa = "open -a"; + pinentry = "pinentry-mac"; + } // lib.attrsets.mapAttrs (name: value: "open -a " + value) appCommands); + + programs.firefox.package = mkIf stdenv.isDarwin pkgs.firefox-mac; + programs.chromium.package = mkIf stdenv.isDarwin pkgs.chromium-mac; + targets.darwin = { defaults = { "com.googlecode.iterm2" = import ./iterm2.nix; diff --git a/emacs.nix b/emacs.nix index 10ab081..83c46f6 100644 --- a/emacs.nix +++ b/emacs.nix @@ -463,9 +463,7 @@ in { enable = true; after = [ "org" ]; init = '' - ; -*-emacs-lisp-*- (setq org-babel-octave-shell-command "${pkgs.octave}/bin/octave -q") - (setq org-babel-matlab-shell-command "~/Applications/MATLAB_R2022b.app/bin/matlab -nosplash") ''; }; @@ -523,7 +521,6 @@ in { ''; init = '' ; -*-emacs-lisp-*- - (defvar my/org-dir "~/Documents/org/") (require 'oc) (require 'oc-basic) (require 'oc-csl) @@ -537,7 +534,7 @@ in { (setq org-export-with-tags nil) (setq org-publish-project-alist '(("root" - :base-directory (expand-file-name my/org-dir) + :base-directory "${config.home.sessionVariables.ORGDIR}" :publishing-function org-html-publish-to-html :publishing-directory (expand-file-name "~/public_html") :section-numbers nil @@ -551,8 +548,8 @@ in { (setq org-html-head-include-default-style nil) (setq org-html-head "") (setq org-html-section) - (setq bibtex-completion-notes-path (expand-file-name "notes.org" my/org-dir)) - (setq org-cite-global-bibliography '("~/Documents/org/zotero.bib")) + (setq bibtex-completion-notes-path "${config.home.sessionVariables.ORGDIR}/notes.org") + (setq org-cite-global-bibliography '("${config.home.sessionVariables.ORGDIR}/zotero.bib")) (setq org-cite-export-processors '((t basic))) (setq org-cite-follow-processor 'ivy-bibtex-org-cite-follow) (setq org-cite-csl-styles-dir "~/Zotero/styles") @@ -566,7 +563,7 @@ in { (setq org-export-latex-format-toc-function 'org-export-latex-no-toc) (setq org-latex-pdf-process '("latexmk -pdflatex='pdflatex -interaction nonstopmode' -pdf -bibtex -f %f")) - (add-to-list 'exec-path "/Users/willem/.nix-profile/bin") + (add-to-list 'exec-path "${config.home.homeDirectory}/.nix-profile/bin") (add-to-list 'org-latex-classes '("apa6" "\\documentclass{apa6}" @@ -583,7 +580,7 @@ in { ("\\subsubsection{%s}" . "\\subsubsection*{%s}") ("\\paragraph{%s}" . "\\paragraph*{%s}") ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))) - (setq org-agenda-files '("~/Documents/org" "~/Documents/org/ubc")) + (setq org-agenda-files '("${config.home.sessionVariables.ORGDIR}" "${config.home.sessionVariables.UBCDIR}")) ''; hook = [ "(org-babel-after-execute . org-redisplay-inline-images)" @@ -606,7 +603,7 @@ in { enable = true; init = '' (require 'org-download) - (setq-default org-download-image-dir "~/Documents/org/images") + (setq-default org-download-image-dir "${config.home.sessionVariables.ORGDIR}/images") ''; hook = [ "(dired-mode-hook . org-download-enable)" ]; }; @@ -618,8 +615,8 @@ in { (setq org-ref-insert-cite-function (lambda () (org-cite-insert nil))) - (setq org-ref-default-bibliography "~/Documents/org/zotero.bib") - (setq bibtex-completion-bibliography '("~/Documents/org/zotero.bib")) + (setq org-ref-default-bibliography "${config.home.sessionVariables.ORGDIR}/zotero.bib") + (setq bibtex-completion-bibliography '("${config.home.sessionVariables.ORGDIR}/zotero.bib")) (require 'org-ref) (require 'org-ref-ivy) ''; @@ -690,7 +687,7 @@ in { yasnippet = { enable = true; config = '' - (setq yas-snippet-dirs '("~/Documents/org/snippets")) + (setq yas-snippet-dirs '("${config.home.sessionVariables.ORGDIR}/snippets")) (yas-global-mode 1) ''; }; diff --git a/flake.lock b/flake.lock index 71d915d..603d9dd 100644 --- a/flake.lock +++ b/flake.lock @@ -53,13 +53,13 @@ "type": "github" } }, - "nur": { + "nurrepo": { "locked": { - "lastModified": 1675104428, - "narHash": "sha256-u0ivGegUvyfd76yuDpL2qAT8hGZQAlJ3s1nLXuFFrw4=", + "lastModified": 1675529301, + "narHash": "sha256-upLPV9gqFnfkwwZQfKEJDLXMv5lyeIpTOXCXFjPN2zA=", "owner": "nix-community", "repo": "NUR", - "rev": "f784e280fb43d0a95edfdc4f35b20fdb3dd8b720", + "rev": "ac7a6f0e289c4690f808f0865a0e7f766670bdfe", "type": "github" }, "original": { @@ -73,7 +73,7 @@ "home-manager": "home-manager", "nixpkgs-22_11": "nixpkgs-22_11", "nixpkgs-unstable": "nixpkgs-unstable", - "nur": "nur" + "nurrepo": "nurrepo" } }, "utils": { diff --git a/flake.nix b/flake.nix index 737f42f..d8e8e8f 100644 --- a/flake.nix +++ b/flake.nix @@ -8,11 +8,11 @@ url = "github:nix-community/home-manager"; inputs.nixpkgs.follows = "nixpkgs-22_11"; }; - nur.url = "github:nix-community/NUR"; + nurrepo.url = "github:nix-community/NUR"; }; outputs = - { self, nixpkgs-unstable, nixpkgs-22_11, home-manager, nur, ... }@inputs: + { self, nixpkgs-unstable, nixpkgs-22_11, home-manager, nurrepo, ... }@inputs: let system = "aarch64-darwin"; @@ -28,7 +28,12 @@ ]; }; - nurNoPkgs = import nur { + nur = import nurrepo { + nurpkgs = pkgs; + pkgs = pkgs; + }; + + nurNoPkgs = import nurrepo { nurpkgs = pkgs; pkgs = throw "nixpkgs eval"; }; @@ -38,11 +43,11 @@ # Specify your home configuration modules here, for example, # the path to your home.nix. - modules = [ nur.hmModules.nur ./home.nix ]; + modules = [ nurrepo.hmModules.nur ./home.nix ]; # Optionally use extraSpecialArgs # to pass through arguments to home.nix - extraSpecialArgs = { inherit nurNoPkgs; }; + extraSpecialArgs = { inherit nur nurNoPkgs; }; }; }; } diff --git a/home.nix b/home.nix index a641c08..3316bae 100644 --- a/home.nix +++ b/home.nix @@ -1,11 +1,11 @@ -{ config, pkgs, lib, inputs, ... }: +{ config, pkgs, lib, inputs, nur, ... }: let inherit (pkgs) stdenv; inherit (lib) mkIf; emacsCommand = "emacsclient -c -nw"; homeDirectory = config.home.homeDirectory; -in { +in rec { home = { username = "willem"; homeDirectory = "/Users/willem"; @@ -18,22 +18,6 @@ in { builders-use-substitutes = true ''; - home.file.".gnupg/gpg-agent.conf".text = mkIf stdenv.isDarwin '' - pinentry-program "${pkgs.pinentry-touchid}/bin/pinentry-touchid" - default-cache-ttl 30 - max-cache-ttl 600 - ''; - - home.file.".config/zsh/am.sh" = mkIf stdenv.isDarwin { - executable = true; - source = let rev = "27353ec55abac8b5d73b8a061fb87f305c663adb"; - in builtins.fetchurl { - url = - "https://raw.githubusercontent.com/mcthomas/Apple-Music-CLI-Player/${rev}/src/am.sh"; - sha256 = "sha256-78zRpNg7/OR7p8dpsJt6Xc4j0Y+8zSUtm/PT94nf03M="; - }; - }; - home.keyboard = { layout = "us"; variant = "colemak"; @@ -45,9 +29,11 @@ in { ctype = "en_US.UTF-8"; }; - home.sessionVariables = { + home.sessionVariables = rec { EDITOR = emacsCommand; VISUAL = emacsCommand; + ORGDIR = "${home.homeDirectory}/Documents/org"; + UBCDIR = "${ORGDIR}/ubc"; }; imports = @@ -57,6 +43,9 @@ in { allowUnfree = true; allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) [ "discord" "unrar" "zoom" ]; + packageOverrides = pkgs: { + nur = nur; + }; }; nixpkgs.overlays = [ (import ./overlays) ]; diff --git a/overlays/chromium-mac.nix b/overlays/chromium-mac.nix new file mode 100644 index 0000000..9969a36 --- /dev/null +++ b/overlays/chromium-mac.nix @@ -0,0 +1,27 @@ +{ stdenv, pkgs, fetchurl, ... }: + +let + versions = { + aarch64-darwin = "1101351"; + x86_64-darwin = "1101350"; + }; + + version = versions.${stdenv.hostPlatform.system}; + + pname = "chromium"; + appName = "Chromium"; + + srcs = { + aarch64-darwin = fetchurl { + url = "https://commondatastorage.googleapis.com/chromium-browser-snapshots/Mac_Arm/${version}/chrome-mac.zip"; + sha256 = "sha256-LlbYlJmFLzyHIiygofa0Btm7NAOvWXXhmbjMHldVoGo="; + name = "${pname}_aarch64_${version}.zip"; + }; + x86_64-darwin = fetchurl { + url = "https://commondatastorage.googleapis.com/chromium-browser-snapshots/Mac/${version}/chrome-mac.zip"; + sha256 = "sha256-O+OnjakEpjCRbSjDysEA6RKKaKaSMw+LSO2ZLcxz2vM="; + name = "${pname}_x86_64_${version}.zip"; + }; + }; + src = srcs.${stdenv.hostPlatform.system}; +in import ./mk-mac-binpkg.nix { inherit pkgs src pname appName version; srcsubdir = "chrome-mac"; } diff --git a/overlays/default.nix b/overlays/default.nix index 1c8bb03..f5289d9 100644 --- a/overlays/default.nix +++ b/overlays/default.nix @@ -1,4 +1,6 @@ self: super: { + chromium-mac = super.callPackage ./chromium-mac.nix { pkgs = super; }; + firefox-mac = super.callPackage ./firefox-mac.nix { pkgs = super; }; pinentry-touchid = super.callPackage ./pinentry-touchid.nix { pkgs = super; }; qbittorrent-mac = super.callPackage ./qbittorrent-mac.nix { pkgs = super; }; spotify-mac = super.callPackage ./spotify-mac.nix { pkgs = super; }; diff --git a/overlays/firefox-mac.nix b/overlays/firefox-mac.nix new file mode 100644 index 0000000..a2f18ca --- /dev/null +++ b/overlays/firefox-mac.nix @@ -0,0 +1,12 @@ +{ pkgs, fetchurl, ... }: + +let + version = "109.0.1"; + pname = "firefox"; + appName = "Firefox"; + src = fetchurl { + url = "https://download-installer.cdn.mozilla.net/pub/firefox/releases/${version}/mac/en-CA/Firefox%20${version}.dmg"; + sha256 = "sha256-V/8W3qqYhJmte2tq/ZSPtYChdhv8WFQoSORYRaxva9Y="; + name = "${pname}_${version}.dmg"; + }; +in import ./mk-mac-binpkg.nix { inherit pkgs src pname appName version; } diff --git a/overlays/mk-mac-binpkg.nix b/overlays/mk-mac-binpkg.nix new file mode 100644 index 0000000..f1ab824 --- /dev/null +++ b/overlays/mk-mac-binpkg.nix @@ -0,0 +1,25 @@ +{ src, version, pname, appName, pkgs, srcsubdir ? ".", ... }: + +pkgs.stdenv.mkDerivation { + inherit version src; + + name = pname; + + nativeBuildInputs = [ pkgs.undmg pkgs.unzip pkgs.makeWrapper ]; + + sourceRoot = "."; + + installPhase = '' + runHook preInstall + + mkdir -p $out/Applications + + cp -r "${srcsubdir}/${appName}.app" $out/Applications + + # wrap executable to $out/bin + mkdir -p $out/bin + makeWrapper "$out/Applications/${appName}.app/Contents/MacOS/${appName}" "$out/bin/${pname}" + + runHook postInstall + ''; +} diff --git a/overlays/qbittorrent-mac.nix b/overlays/qbittorrent-mac.nix index ead2bf0..080df1f 100644 --- a/overlays/qbittorrent-mac.nix +++ b/overlays/qbittorrent-mac.nix @@ -1,33 +1,13 @@ -{ stdenv, fetchurl, pkgs, ... }: +{ pkgs, fetchurl, ... }: let version = "4.4.5"; appName = "qBittorrent"; pname = "qbittorrent"; -in stdenv.mkDerivation { - inherit pname; - name = pname; src = fetchurl { - url = - "https://phoenixnap.dl.sourceforge.net/project/qbittorrent/qbittorrent-mac/qbittorrent-${version}/qbittorrent-${version}.dmg"; + url = "https://phoenixnap.dl.sourceforge.net/project/qbittorrent/qbittorrent-mac/qbittorrent-${version}/qbittorrent-${version}.dmg"; sha256 = "sha256-9h+gFAEU0tKrltOjnOKLfylbbBunGZqvPzQogdP9uQM="; }; +in import ./mk-mac-binpkg.nix { inherit pkgs src pname appName version; } - nativeBuildInputs = [ pkgs.undmg pkgs.makeWrapper ]; - - sourceRoot = "."; - - installPhase = '' - runHook preInstall - - mkdir -p $out/Applications - cp -r "${appName}.app" $out/Applications - - # wrap executable to $out/bin - mkdir -p $out/bin - makeWrapper "$out/Applications/${appName}.app/Contents/MacOS/${pname}" "$out/bin/${pname}" - - runHook postInstall - ''; -} diff --git a/overlays/vlc-mac.nix b/overlays/vlc-mac.nix index 0dfc98a..e990d02 100644 --- a/overlays/vlc-mac.nix +++ b/overlays/vlc-mac.nix @@ -1,39 +1,21 @@ { stdenv, pkgs, fetchurl, ... }: let + appName = "VLC"; + pname = "vlc"; version = "3.0.18"; srcs = { aarch64-darwin = fetchurl { - url = - "http://get.videolan.org/vlc/${version}/macosx/vlc-${version}-arm64.dmg"; + url = "http://get.videolan.org/vlc/${version}/macosx/vlc-${version}-arm64.dmg"; sha256 = "sha256-mcJZvbxSIf1QgX9Ri3Dpv57hdeiQdDkDyYB7x3hmj0c="; + name = "${pname}_aarch64_${version}.dmg"; }; x86_64-darwin = fetchurl { - url = - "http://get.videolan.org/vlc/${version}/macosx/vlc-${version}-intel64.dmg"; + url = "http://get.videolan.org/vlc/${version}/macosx/vlc-${version}-intel64.dmg"; sha256 = "sha256-iO3N/Os70vaANn2QCdOKDBR/p1jy3TleQ0EsHgjOHMs="; + name = "${pname}_x86_64_${version}.dmg"; }; }; - pname = "vlc"; -in stdenv.mkDerivation { - name = pname; - - src = srcs.${stdenv.hostPlatform.system}; + src = srcs.${stdenv.hostPlatform.system}; +in import ./mk-mac-binpkg.nix { inherit stdenv pkgs fetchurl src pname appName version; } - nativeBuildInputs = [ pkgs.undmg pkgs.makeWrapper ]; - - sourceRoot = "."; - - installPhase = '' - runHook preInstall - - mkdir -p $out/Applications - cp -r "VLC.app" $out/Applications - - # wrap executable to $out/bin - mkdir -p $out/bin - makeWrapper "$out/Applications/VLC.app/Contents/MacOS/VLC" "$out/bin/vlc" - - runHook postInstall - ''; -} diff --git a/packages.nix b/packages.nix index c4bbd40..df7c477 100644 --- a/packages.nix +++ b/packages.nix @@ -18,6 +18,7 @@ let 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 ]; + octave-wp = pkgs.octave.withPackages (p: with p; [ symbolic ]); in { home.packages = with pkgs; [ @@ -44,7 +45,7 @@ in { nixfmt nix-review nmap - octave + octave-wp openssh pass-extended plantuml diff --git a/programs.nix b/programs.nix index 5aada58..a8d4762 100644 --- a/programs.nix +++ b/programs.nix @@ -2,6 +2,22 @@ { programs = { + browserpass = { + enable = true; + browsers = [ + "chromium" + "firefox" + ]; + }; + + chromium = { + enable = true; + extensions = [ + { id = "naepdomgkenhinolocfifgehidddafch"; } # browserpass + { id = "cjpalhdlnbpafiamejdnhcphjbkeiagm"; } # ublock origin + ]; + }; + direnv = { enable = true; nix-direnv = { enable = true; }; @@ -12,6 +28,12 @@ enableAliases = true; }; + firefox = { + enable = true; + extensions = [ + ]; + }; + git = { enable = true; delta = { enable = true; }; @@ -109,33 +131,33 @@ autocd = true; defaultKeymap = "emacs"; envExtra = '' -#!/usr/bin/env zsh -export GPG_TTY=$(tty) -eval $(gpg-agent --daemon -q 2>/dev/null) + #!/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 gsearch() { + open -a Safari "https://google.com/search?q=$(echo $@ | sed -e 's/ /%20/g')" + } -function plistxml2nix() { - tail -n +4 | + 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" | + -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"; history = { @@ -144,19 +166,16 @@ function plistxml2nix() { ignoreDups = true; }; shellAliases = { - emw = "emacs"; + cd = "z"; + e = "emacsclient -c -nw"; em = "emacs -nw"; ew = "emacsclient -c"; - e = "emacsclient -c -nw"; - np = "nix-shell -p"; hms = "home-manager switch"; - cd = "z"; l = "ls -1"; - web = "open -a Safari"; - email = "open -a Mail"; - o = "open -a"; - am = lib.mkIf pkgs.stdenv.isDarwin "zsh ~/.config/zsh/am.sh"; - pinentry = "pinentry-mac"; + np = "nix-shell -p"; + org = "z ${config.home.sessionVariables.ORGDIR}"; + ubc = "z ${config.home.sessionVariables.UBCDIR}"; + emw = "emacs"; }; };