···44, pkgs
55, unstable ? import <nixos-unstable> { } # backwards compat for non-flake
66, homeDirectory ? "/home/${config.home.user}"
77+, host
78, ...
89}:
910let
···1415 user = config.home.user or "ianchamberlain";
1516in
1617{
1717- imports = [
1818+ imports = self.lib.existingPaths [
1819 ./macos-defaults.nix
1920 ./default-apps.nix
2121+ # This is kinda janky but I guess it works...
2222+ # https://github.com/nix-community/home-manager/issues/1906
2323+ ./${if host.wsl then "" else "non-"}wsl.nix
2024 # ./firefox.nix # TODO
2125 ];
2226···3236 # https://github.com/nix-community/home-manager/issues/5602
33373438 nix.settings = {
3535- repl-overlays = "/${config.xdg.configHome}/nix/repl-overlays.nix";
3939+ repl-overlays = "${config.xdg.configHome}/nix/repl-overlays.nix";
3640 # Use extra- to avoid overwriting settings from nix-darwin
3741 extra-experimental-features = [
3842 "repl-flake"
3939- # TODO: lix doesn't seem to be taking effect properly in nixos-wsl
4040- # "pipe-operator"
4343+ "pipe-operator"
4144 ];
42454346 # TODO: try out default-flake
···5558 home-manager.enable = true;
56595760 bat.enable = true;
6161+ direnv = {
6262+ enable = true;
6363+ nix-direnv.enable = true;
6464+ };
5865 fd.enable = true;
5966 fish.enable = true;
6067 git.enable = true;
···111118 # };
112119113120 # syncthing.enable = true;
114114-115121 # For commit signing, git-crypt, etc.
116122 gpg-agent = {
117123 # https://github.com/nix-community/home-manager/issues/3864
118124 # TODO: it would be nice to setup gpg-agent.conf on macOS properly
119125 # during activation... Maybe nix-darwin has something?
120126 enable = stdenv.isLinux;
121121-122127 defaultCacheTtl = 432000; # 5 days
123128 maxCacheTtl = 432000;
124124- pinentryPackage = pkgs.pinentry-curses;
129129+ pinentryPackage = lib.mkIf (!host.wsl) pkgs.pinentry-curses;
125130 };
126131 };
127132128133 # See services.gpg-agent - manually set up conf file on macos instead
129129- home.file.".gnupg/gpg-agent.conf" = lib.mkIf stdenv.isDarwin {
130130- text = ''
131131- # Use nix-packaged pinentry-mac
132132- pinentry-program ${pkgs.pinentry_mac}/bin/pinentry-mac
133133- # Set TTL to 5 days for GPG passphrase prompt
134134- default-cache-ttl 432000
135135- max-cache-ttl 432000
136136- '';
134134+ home.file = {
135135+ ".gnupg/gpg-agent.conf" = lib.mkIf stdenv.isDarwin {
136136+ text = ''
137137+ # Use nix-packaged pinentry-mac
138138+ pinentry-program ${pkgs.pinentry_mac}/bin/pinentry-mac
139139+ # Set TTL to 5 days for GPG passphrase prompt
140140+ default-cache-ttl 432000
141141+ max-cache-ttl 432000
142142+ '';
143143+ };
137144 };
138145139146 home.packages = with pkgs; [
140147 buildifier
141148 clang-tools
149149+ comby
150150+ difftastic
142151 docker
143152 docker-compose
144153 docker-credential-helpers
154154+ file
145155 gh
146156 git-crypt
147157 git-lfs
+42
.config/home-manager/wsl.nix
···11+{ pkgs, lib, ... }:
22+let
33+ pinentry-injector = pkgs.buildGoModule {
44+ pname = "pinentry-injector";
55+ version = "0.1.0";
66+ meta.mainProgram = "pinentry-injector";
77+88+ # Since it's just a single-file zero-dependency app, generate go.mod on the fly
99+ # and pretend its dependencies are vendored.
1010+ src = ./wsl/pinentry-injector;
1111+ patchPhase = ''
1212+ go mod init ian-h-chamberlain.com/pinentry-injector
1313+ '';
1414+ vendorHash = null;
1515+ };
1616+1717+ # Request pinentry via Git-bash's GPG instead of pinentry-curses
1818+ pinentry-wrapper = pkgs.writeShellApplication {
1919+ name = "pinentry-win";
2020+ # TODO: PR these as inputs for nixpkgs#wslu itself?
2121+ runtimeInputs = with pkgs; [ wslu coreutils gnused pinentry-injector ];
2222+ # TODO: if I write a real program to intercept stdin/stdout I can inject
2323+ # a SETTITLE command using the key name for AutoType to work nicer. Ideally
2424+ # cross-platform enough to work on native windows too
2525+ text = /*bash*/ ''
2626+ # Add wslpath to PATH (for wslu to work properly)
2727+ export PATH=/bin:$PATH
2828+ # Gpg4Win's pinentry-qt seems better behaved than plain pinentry from Git for Windows
2929+ real_pinentry="$(wslpath "$(wslvar -s USERPROFILE)")/scoop/apps/gpg4win/current/Gpg4win/bin/pinentry.exe"
3030+ exec "$real_pinentry" "$@"
3131+ '';
3232+ };
3333+in
3434+{
3535+ services.gpg-agent.pinentryPackage = pinentry-wrapper;
3636+3737+ home.file.".local/bin/xdg-open".source = lib.getExe' pkgs.wslu "wslview";
3838+ home.packages = with pkgs; [
3939+ wslu
4040+ pinentry-wrapper
4141+ ];
4242+}
+1-1
.config/nix-darwin/configuration.nix
···3232 ];
33333434 shells = [ pkgs.fish ];
3535- loginShell = "${pkgs.fish}/bin/fish";
3535+ loginShell = "${lib.getExe pkgs.fish}";
36363737 etc = let homeDir = config.users.users.${host.user}.home; in {
3838 # Symlink to dotfiles flake for easier activation