From cd209ea82020081ef378d7bdd5e2f06d3847f03b Mon Sep 17 00:00:00 2001 From: mat ess Date: Mon, 10 Oct 2022 17:54:15 -0400 Subject: [PATCH] Tarsnap, nix shell tweaks, services --- darwin/homebrew.nix | 5 ++-- flake.nix | 5 +++- home/dark-mode-notify-service.nix | 20 -------------- home/files.nix | 22 +++++++++++---- home/fish.nix | 30 ++++++++++++-------- home/programs.nix | 3 +- home/services/dark-mode-notify.nix | 22 +++++++++++++++ home/services/tarsnap.nix | 44 ++++++++++++++++++++++++++++++ 8 files changed, 109 insertions(+), 42 deletions(-) delete mode 100644 home/dark-mode-notify-service.nix create mode 100644 home/services/dark-mode-notify.nix create mode 100644 home/services/tarsnap.nix diff --git a/darwin/homebrew.nix b/darwin/homebrew.nix index ffbb5a8..a43ae77 100644 --- a/darwin/homebrew.nix +++ b/darwin/homebrew.nix @@ -48,7 +48,7 @@ in homebrew.masApps = { Bitwarden = 1352778147; Spark = 1176895641; - Wireguard = 1451685025; + Tailscale = 1475387142; Xcode = 497799835; }; @@ -89,7 +89,7 @@ in # Configuration related to casks environment.variables.SSH_AUTH_SOCK = mkIfCaskPresent "secretive" - "/Users/${config.users.primaryUser.username}/Library/Containers/com.maxgoedjen.Secretive.SecretAgent/Data/socket.ssh"; + "${config.home.homeDirectory}/Library/Containers/com.maxgoedjen.Secretive.SecretAgent/Data/socket.ssh"; # For cli packages that aren't currently available for macOS in `nixpkgs`.Packages should be # installed in `../home/default.nix` whenever possible. @@ -98,6 +98,7 @@ in "fileicon" "fzf" "gifsicle" + "tarsnap" "unison-language" ]; } diff --git a/flake.nix b/flake.nix index e6bd099..462ba6d 100644 --- a/flake.nix +++ b/flake.nix @@ -274,7 +274,10 @@ # configs configs-starship-symbols = import ./home/configs/starship-symbols.nix; copyApplications = import ./home/copyApplications.nix; - dark-mode-notify-service = import ./home/dark-mode-notify-service.nix; + # services + dark-mode-notify-service = import ./home/services/dark-mode-notify.nix; + tarsnap-service = import ./home/services/tarsnap.nix; + # etc files = import ./home/files.nix; fish = import ./home/fish.nix; git = import ./home/git.nix; diff --git a/home/dark-mode-notify-service.nix b/home/dark-mode-notify-service.nix deleted file mode 100644 index 5748e20..0000000 --- a/home/dark-mode-notify-service.nix +++ /dev/null @@ -1,20 +0,0 @@ -{ pkgs, ... }: { - # dark-mode-notify configuration - # {{{ - launchd.agents.dark-mode-notify = { - enable = true; - config = { - Label = "ke.bou.dark-mode-notify"; - KeepAlive = true; - StandardErrorPath = null; - StandardOutPath = null; - ProgramArguments = [ - "${pkgs.dark-mode-notify}/bin/dark-mode-notify" - "${pkgs.fish}/bin/fish" - "-c" - "set-background-to-env DARKMODE" - ]; - }; - }; - # }}} -} diff --git a/home/files.nix b/home/files.nix index ab30d59..ef7551b 100644 --- a/home/files.nix +++ b/home/files.nix @@ -5,11 +5,21 @@ enable = true; }; - home.file.".pijulconfig".text = '' - [author] - name = "mat" - full_name = "${config.programs.git.userName}" - email = "${config.programs.git.userEmail}" - ''; + home.file = { + ".pijulconfig".text = '' + [author] + name = "${config.home.primaryUser.username}" + full_name = "${config.home.primaryUser.fullName}" + email = "${config.home.primaryUser.email}" + ''; + ".tarsnaprc".text = '' + cachedir ${config.xdg.cacheHome} + keyfile ${config.xdg.configHome}/tarsnap/read-write-delete.key + nodump + print-stats + checkpoint-bytes 1G + humanize-numbers + ''; + }; # }}} } diff --git a/home/fish.nix b/home/fish.nix index a9a999f..574ff0f 100644 --- a/home/fish.nix +++ b/home/fish.nix @@ -6,9 +6,7 @@ programs.fish.enable = true; # Add Fish plugins - home.packages = with pkgs.fishPlugins; [ - done - ]; + home.packages = with pkgs.fishPlugins; [ done ]; programs.fish.plugins = [ { @@ -154,7 +152,7 @@ }; darwin-rebuild-edit-with = { - argumentNames = [ "file" "editor" ]; + argumentNames = [ "editor" "file" ]; body = '' if test -z "$file" set file flake.nix @@ -162,6 +160,13 @@ from-nix $editor $file ''; }; + + nix-unfree = { + argumentNames = [ "cmd" ]; + body = '' + env NIX_ALLOW_UNFREE=1 nix $cmd --impure + ''; + }; }; # }}} @@ -170,11 +175,11 @@ # Aliases programs.fish.shellAliases = let - nixConfigDir = "${config.home.homeDirectory}/dotfiles.nix"; + inherit (config.home.primaryUser) nixConfigDirectory; in with pkgs; { # Nix related - from-nix = "from-dir ${nixConfigDir}"; + from-nix = "from-dir ${nixConfigDirectory}"; # darwin-rebuild build drb = "from-nix darwin-rebuild build --flake ."; # darwin-rebuild switch full @@ -182,19 +187,22 @@ # darwin-rebuild switch (no homebrew) drs = "from-nix darwin-rebuild switch --flake . --override-input homebrew-enabled github:boolean-option/false"; # edit darwin-rebuild config in code/codium - drc = "code ${nixConfigDir}"; + drc = "code ${nixConfigDirectory}"; # edit darwin-rebuild config in vim - drv = "vim ${nixConfigDir}"; + drv = "vim ${nixConfigDirectory}"; # edit darwin-rebuild config in helix drh = "darwin-rebuild-edit-with hx"; - flakeup = "nix flake update ${nixConfigDir}/"; + flakeup = "nix flake update ${nixConfigDirectory}/"; nb = "nix build"; nd = "nix develop"; nf = "nix flake"; nr = "nix run"; + nru = "nix-unfree run"; ns = "nix search nixpkgs"; nsh = "nix shell"; - nrp = "nix repl --expr '{pkgs=(import {});}'"; + nshu = "nix-unfree shell"; + nrp = "nix repl --expr '{ pkgs = (import { }); }'"; + nrpu = "nix repl --expr '{ pkgs = (import { config.allowUnfree = true; }); }' --impure"; # Other ".." = "cd .."; @@ -212,7 +220,7 @@ tb = "toggle-background"; } // lib.optionalAttrs stdenv.isDarwin { sb = "set-background-to-macOS"; - conda-init = "eval /opt/homebrew/Caskroom/miniforge/base/bin/conda 'shell.fish' 'hook' $argv | source"; + conda-init = "eval /opt/homebrew/bin/conda 'shell.fish' 'hook' $argv | source"; }; # Configuration that should be above `loginShellInit` and `interactiveShellInit`. diff --git a/home/programs.nix b/home/programs.nix index 13812b5..f2b0a0a 100644 --- a/home/programs.nix +++ b/home/programs.nix @@ -51,8 +51,7 @@ UseKeychain = "yes"; AddKeysToAgent = "yes"; } // lib.optionalAttrs pkgs.stdenv.isDarwin { - # TODO: gate this behind a check if the cask is present - IdentityAgent = "~/Library/Containers/com.maxgoedjen.Secretive.SecretAgent/Data/socket.ssh"; + IdentityAgent = "${config.home.homeDirectory}/Library/Containers/com.maxgoedjen.Secretive.SecretAgent/Data/socket.ssh"; }; }; # vscode diff --git a/home/services/dark-mode-notify.nix b/home/services/dark-mode-notify.nix new file mode 100644 index 0000000..f4e1653 --- /dev/null +++ b/home/services/dark-mode-notify.nix @@ -0,0 +1,22 @@ +{ pkgs, ... }: { + # dark-mode-notify configuration + # {{{ + launchd.agents.dark-mode-notify = + let logPath = "/var/log/dark-mode-notify"; in + { + enable = true; + config = { + Label = "ke.bou.dark-mode-notify"; + KeepAlive = true; + StandardErrorPath = "${logPath}/error.log"; + StandardOutPath = "${logPath}/out.log"; + ProgramArguments = [ + "${pkgs.dark-mode-notify}/bin/dark-mode-notify" + "${pkgs.fish}/bin/fish" + "-c" + "set-background-to-env DARKMODE" + ]; + }; + }; + # }}} +} diff --git a/home/services/tarsnap.nix b/home/services/tarsnap.nix new file mode 100644 index 0000000..096ec93 --- /dev/null +++ b/home/services/tarsnap.nix @@ -0,0 +1,44 @@ +{ config, pkgs, ... }: { + # tarsnap periodic backup configuration + # {{{ + launchd.agents.tarsnap = + let + logPath = "/var/log/tarsnap"; + tarsnapBackup = pkgs.writeShellScriptBin "tarsnap-backup-helper" '' + /opt/homebrew/bin/tarsnap -v -c \ + --configfile ${config.home.homeDirectory}/.tarsnaprc \ + -f $(uname -n)-$(date -u +%Y-%m-%dT%H:%M:%SZ) \ + ${config.home.homeDirectory}/{dotfiles.nix,Desktop,Development,Documents,Downloads} + ''; + in + { + enable = true; + config = { + Label = "com.tarsnap.tarsnap"; + StandardErrorPath = "${logPath}/error.log"; + StandardOutPath = "${logPath}/out.log"; + StartCalendarInterval = [ + { + # every sunday + Weekday = 0; + # at midnight + Hour = 0; + Minute = 0; + } + { + # every wednesday + Weekday = 3; + # at noon + Hour = 12; + Minute = 0; + } + ]; + Program = "${tarsnapBackup}/bin/tarsnap-backup-helper"; + }; + }; + # }}} +} + + + +