aboutsummaryrefslogtreecommitdiffstats
path: root/home/default.nix
blob: 0c2f1088e22e1fb2f4e75b71364c2836710fcb61 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
{
  inputs,
  config,
  vars,
  pkgs,
  ...
}:
let
  unstable = import inputs.nixpkgs-unstable {
    system = pkgs.stdenv.hostPlatform.system;
    config.allowUnfree = true;
  };
in
{
  imports = [
    # ./alacritty
    # ./conky
    # ./helix
    # ./lf
    # ./quickshell
    ./cargo
    ./chawan
    ./dunst
    ./firefox
    ./fish
    ./git
    ./hyprland
    ./hyprlock
    ./mail
    ./dav
    ./mpv
    ./newsboat
    (import ./nvim { inherit unstable; })
    ./tenere
    ./ticker
    ./vale
    ./walker
    ./wallpapers
    ./waybar
  ];

  home.file = {
    "Calendar/radicale/.keep".text = "";
    "Contacts/radicale/.keep".text = "";
  };

  age = {
    identityPaths = [ "${config.home.homeDirectory}/.ssh/id_ed25519" ];
    secrets = {
      miniflux_api_key = {
        path = "${config.home.homeDirectory}/.secrets/miniflux_api_key";
        file = ../secrets/miniflux_api_key.age;
      };
      openai_auth_token.file = ../secrets/openai_auth_token.age;
      relesoft_cargo_token.file = ../secrets/relesoft_cargo_token.age;
      shiori_password.file = ../secrets/shiori_password.age;
      radicale = {
        path = "${config.home.homeDirectory}/.secrets/radicale";
        file = ../secrets/radicale.age;
      };
      unsplash_access_key.file = ../secrets/unsplash_access_key.age;
      gmail = {
        file = ../secrets/gmail.age;
        path = "${config.home.homeDirectory}/.secrets/gmail";
        mode = "600";
      };
      relesoft = {
        file = ../secrets/relesoft.age;
        path = "${config.home.homeDirectory}/.secrets/relesoft";
        mode = "600";
      };
    };
  };

  gtk = {
    enable = true;
    theme = {
      package = pkgs.whitesur-gtk-theme;
      name = "WhiteSur-Dark";
    };
    iconTheme = {
      package = pkgs.nordzy-icon-theme;
      name = "Nordzy";
    };
    font = {
      package = pkgs.roboto-flex;
      name = "Roboto Flex 11";
    };
  };

  qt = {
    enable = false;
    style = {
      package = pkgs.darkly;
      name = "Darkly";
    };
  };

  programs = {
    element-desktop = {
      enable = true;
      settings = {
        "m.homeserver" = {
          base_url = "https://matrix.relesoft.io";
          server_name = "relesoft.io";
        };
        default_theme = "dark";
      };
    };
    zellij = {
      # modern tmux
      enable = true;
      enableFishIntegration = false;
    };
    zoxide = {
      # smarter cd command
      enable = true;
      enableFishIntegration = true;
      enableNushellIntegration = true;
    };
    fastfetch = {
      enable = true;
      settings = {
        logo = {
          source = "nixos_small";
          padding = {
            right = 1;
          };
        };
        display = {
          size = {
            binaryPrefix = "si";
          };
          color = "blue";
          separator = "";
        };
        modules = [
          {
            type = "os";
            key = " OS";
            keyColor = "blue";
          }
          {
            type = "kernel";
            key = "󰌽 Kernel";
            keyColor = "blue";
          }
          "break"
          {
            type = "font";
            key = "󰛖 Font";
          }
          {
            type = "theme";
            key = "󰏘 Theme";
          }
          {
            type = "icons";
            key = "󰚝 Icons";
          }
          {
            type = "shell";
            key = "󰞷 Shell";
          }
          {
            type = "terminal";
            key = "󰆍 Terminal";
          }
          "break"
          {
            type = "display";
            key = "󰹑 Display";
            keyColor = "blue";
          }
          {
            type = "gpu";
            key = "󰢮 GPU";
            driverSpecific = true;
            temp = false;
            keyColor = "blue";
          }
          {
            type = "cpu";
            key = "󰍛 CPU";
            showPeCoreCount = true;
            temp = false;
            keyColor = "blue";
          }
          {
            type = "memory";
            key = " RAM";
            keyColor = "blue";
          }
          {
            type = "swap";
            key = " Swap";
            keyColor = "blue";
          }
          {
            type = "disk";
            key = "󰋊 Disk";
            keyColor = "blue";
          }
          {
            type = "uptime";
            key = "󰄉 Uptime";
            keyColor = "blue";
          }
          "break"
          {
            type = "localip";
            key = "󰩠 Local";
            showIpv6 = false;
            showMac = false;
            showSpeed = false;
            showMtu = false;
            showLoop = false;
            showFlags = false;
            showAllIps = false;
          }
          {
            type = "publicip";
            key = "󰩟 Externe";
            timeout = 1000;
          }
          "break"
          "colors"
        ];
      };
    };
    nushell = {
      enable = true;
      extraConfig = ''
        $env.config.hooks.command_not_found = source ${pkgs.nix-index}/etc/profile.d/command-not-found.nu
        let carapace_completer = {|spans|
        carapace $spans.0 nushell ...$spans | from json
        }
        $env.config = {
         show_banner: false,
         completions: {
         case_sensitive: false # case-sensitive completions
         quick: true    # set to false to prevent auto-selecting completions
         partial: true    # set to false to prevent partial filling of the prompt
         algorithm: "fuzzy"    # prefix or fuzzy
         external: {
             enable: true
             max_results: 100
             completer: $carapace_completer # check 'carapace_completer'
           }
         }
        }
        $env.PATH = ($env.PATH |
        split row (char esep) |
        prepend /home/petri/.apps |
        append /usr/bin/env
        )
      '';
    };
    carapace = {
      enable = true;
      enableNushellIntegration = true;
      enableFishIntegration = true;
    };
    gpg = {
      enable = true;
      settings = {
        no-comments = true;
      };
    };
    fzf = {
      enable = true;
      enableFishIntegration = true; # use CTRL+t for files, CTRL + r for history
      defaultOptions = [
        "--style full"
        "--preview '${pkgs.pistol}/bin/pistol {}'"
      ];
    };
    yazi = {
      # file browser
      enable = true;
      enableNushellIntegration = true;
      enableFishIntegration = true;
      settings = {
        mgr = {
          show_hidden = true;
          show_symlink = true;
          sort_by = "mtime";
          sort_dir_first = true;
          sort_reverse = true;
        };
        preview = {
          image_filter = "lanczos3";
          image_quality = 90;
        };
      };
    };
    atuin = {
      enable = true;
      enableFishIntegration = true;
      enableNushellIntegration = true;
      daemon = {
        enable = true;
      };
      settings = {
        auto_sync = true;
        sync_address = "https://atuin.tammi.cc";
        sync_frequency = "5m";
        style = "compact";
        workspaces = true;
      };
    };
    starship = {
      enable = true;
      enableFishIntegration = true;
      enableTransience = true;
      enableNushellIntegration = true;
    };
    eza = {
      enable = true;
      enableFishIntegration = true;
      enableNushellIntegration = true;
      git = true;
      icons = "auto";
      extraOptions = [
        "--color=always"
        "--tree"
        "--level=1"
        "--group-directories-first"
        "--dereference"
      ];
    };
    nix-index = {
      enable = true;
      enableFishIntegration = true;
    };
    pistol.enable = true;
    ghostty = {
      enable = true;
      systemd = {
        enable = true;
      };
      installVimSyntax = true;
      enableFishIntegration = true;
      settings = {
        font-family = "Iosevka Nerd Font";
        font-size = 12;
        mouse-hide-while-typing = true;
        copy-on-select = true;
        theme = "nord";
      };
      themes = {
        nord = {
          background = "#2e3440";
          foreground = "#d8dee9";
          selection-background = "#3f4758";
          selection-foreground = "#d8dee9";
          cursor-color = "#d8dee9";
          cursor-text = "#2e3440";
          palette = [
            "0=#3b4252"
            "1=#bf616a"
            "2=#a3be8c"
            "3=#ebcb8b"
            "4=#81a1c1"
            "5=#b48ead"
            "6=#88c0d0"
            "7=#e5e9f0"
            "8=#4c566a"
            "9=#bf616a"
            "10=#a3be8c"
            "11=#ebcb8b"
            "12=#81a1c1"
            "13=#b48ead"
            "14=#8fbcbb"
            "15=#eceff4"
          ];
        };
      };
    };
    ssh = {
      enableDefaultConfig = false;
      enable = true;
      matchBlocks."*" = {
        serverAliveInterval = 1;
        compression = true;
        controlMaster = "auto";
        controlPersist = "10m";
      };
    };

    chromium = {
      enable = true;
      package = pkgs.chromium;
      commandLineArgs = [
        "--load-media-router-component-extension=1"
        "--enable-features=VaapiVideoDecodeLinuxGL,VaapiVideoEncoder,Vulkan,VulkanFromANGLE,DefaultANGLEVulkan,VaapiIgnoreDriverChecks,VaapiVideoDecoder,PlatformHEVCDecoderSupport,UseMultiPlaneFormatForHardwareVideo"
        "--enable-features=UseOzonePlatform --ozone-platform=wayland"
        "--enable-media-router"
        "--enable-smooth-scrolling"
        "--force-dark-mode"
      ];
      dictionaries = [ pkgs.hunspellDictsChromium.en_US ];
      extensions = [
        # vimium
        # https://chromewebstore.google.com/detail/vimium/dbepggeogbaibhgnhhndojpepiihcmeb
        "dbepggeogbaibhgnhhndojpepiihcmeb"

        # bitwarden
        # https://chromewebstore.google.com/detail/bitwarden-password-manage/nngceckbapebfimnlniiiahkandclblb
        "nngceckbapebfimnlniiiahkandclblb"

        # ublock origin lite
        # https://chromewebstore.google.com/detail/ublock-origin-lite/ddkjiahejlhfcafbddmgiahcphecmpfh
        "ddkjiahejlhfcafbddmgiahcphecmpfh"

        # decentraleyes
        # https://chromewebstore.google.com/detail/decentraleyes/ldpochfccmkkmhdbclfhpagapcfdljkj
        "ldpochfccmkkmhdbclfhpagapcfdljkj"

        # redeck
        # https://chromewebstore.google.com/detail/readeck/jnmcpmfimecibicbojhopfkcbmkafhee?pli=1
        "jnmcpmfimecibicbojhopfkcbmkafhee"
      ];
    };

    home-manager.enable = true;
  };

  services = {
    mpd-mpris.enable = true;
    mpd = {
      enable = true;
      musicDirectory = "/media/skydrive/Music/";
      # extraArgs = [ "--verbose" ];
      network = {
        listenAddress = "any";
        startWhenNeeded = true;
        port = 6600;
      };
    };

    psd = {
      enable = true;
      backupLimit = 5;
    };
    gpg-agent = {
      defaultCacheTtl = 1800;
      enable = true;
      enableFishIntegration = true;
      enableSshSupport = true;
      pinentry.package = pkgs.pinentry-gnome3;
    };
    mpris-proxy.enable = true;
    clipse = {
      enable = true;
    };
  };

  manual = {
    html.enable = true;
    json.enable = true;
  };

  home = {
    enableNixpkgsReleaseCheck = true;
    stateVersion = "25.05";
    shell = {
      enableFishIntegration = true;
      enableNushellIntegration = true;
    };
    username = "${vars.user}";
    sessionVariables = {
      CC = "clang";
      BROWSER = "${pkgs.firefox}/bin/firefox";
      CARGO_REGISTRIES_RELESOFT_CREDENTIAL_PROVIDER = "cargo:token";
      CARGO_REGISTRIES_RELESOFT_INDEX = "sparse+https://git.relesoft.io/api/packages/relesoft/cargo/";
      CARGO_REGISTRIES_RELESOFT_IO_PROTOCOL = "sparse";
      CARGO_REGISTRIES_RELESOFT_TOKEN = "$(${pkgs.coreutils}/bin/cat ${config.age.secrets.relesoft_cargo_token.path})";
      CURSOR_SIZE = "16";
      DEFAULT_BROWSER = "${pkgs.firefox}/bin/firefox";
      ELECTRON_OZONE_PLATFORM_HINT = "auto";
      GDK_SCALE = "1";
      MOZ_USE_XINPUT2 = "1";
      NIXOS_OZONE_WL = "1";
      PAGER = "${pkgs.nvimpager}/bin/nvimpager";
      PISTOL_CHROMA_FORMATTER = "terminal256";
      PISTOL_CHROMA_STYLE = "monokai";
      VISUAL = "${pkgs.neovim}/bin/nvim";
      OPENAI_API_KEY = "$(${pkgs.coreutils}/bin/cat ${config.age.secrets.openai_auth_token.path})";
      SHIORI_PASSWORD = "$(${pkgs.coreutils}/bin/cat ${config.age.secrets.shiori_password.path})";
      UNSPLASH_ACCESS_KEY = "$(${pkgs.coreutils}/bin/cat ${config.age.secrets.unsplash_access_key.path})";
      TERMCMD = "${pkgs.ghostty}/bin/ghostty";
    };

    pointerCursor = {
      package = pkgs.bibata-cursors;
      gtk.enable = true;
      name = "Bibata-Modern-Ice";
      size = 22;
    };

    homeDirectory = "/home/${vars.user}";
    packages = with pkgs; [
      # tui tools
      bluetui # bluetooth management
      chawan # browser, currently crashes
      clipse # clipboard management
      impala # iwd terminal ui
      lux # youtube-downloader
      unstable.nom # rss reader
      rmpc # tui for mpd
      rtorrent # torrent
      starship # shell aid
      systemctl-tui
      tenere # llm tui
      ticker # stock ticker
      wthrr # weather forecast from openmeteo

      # gui
      bitwarden-desktop # password mananger
      ghostty # terminal emulator
      hypridle
      hyprlock
      hyprpaper
      libreoffice
      lxqt.pavucontrol-qt
      obsidian # note taking application
      sqlitebrowser # sqlite
      swayimg # image viewer
      walker # launcher
      wireshark
      zathura # pdf viewer

      # spell checking
      aspell
      aspellDicts.en # english aspell dictionary
      aspellDicts.en-computers
      aspellDicts.en-science
      aspellDicts.fi # finnish aspell dictionary
      enchant # spell cherker interface
      hunspell
      hunspellDicts.en-us
      libvoikko # finnish spelling
      nuspell # spell checker

      # support
      ethtool # ethernet driver info
      ffmpeg
      libcamera # source camera stack
      libnotify # send notifications
      libwebp
      material-icons
      material-symbols
      mermaid-cli # diagrams
      wl-clipboard
      wttrbar # weather bar

      # cli-tools
      appimage-run
      attic-client # nix cache client
      brightnessctl
      cloc # count llines of code
      dmidecode # memory information
      espflash # ESP32 flasher
      espup # ESP32 development
      eza # modern file list
      fd # find files by filenames
      file # show the type of file
      font-awesome # icons
      forgejo-cli # forgejo-cli
      gat # cat but with extra features
      grim # screen capture
      inxi # system innformation
      jq # commandline json parser
      kramdown-asciidoc # command to convert markdown to asciidoc
      minio-client
      moor # less replacement
      ntfy-sh # notifications
      nvimpager # use neovim as pager
      pistol # file preview
      pkg-config # needed for compilation
      playerctl
      poppler-utils # pdf utilities
      rdrview # extract content from web page
      reader # extract web page and pipe
      ripgrep # faster grep
      slurp # screen are capture
      sqlite # simple database
      timg # show image in shell
      unstable.goose-cli # llm cli
      unstable.vale # spellcheck
      unstable.valeStyles.microsoft # spellcheck linters
      unstable.valeStyles.write-good # spellcheck linters
      whisper-cpp # tts
      wlogout # logout helper
      xdg-utils
      xh # curl replacement
      xxd # view binary files
      zellij # terminal multiplexer

      # Development
      antora # documentation tool for asciidoc
      asciidoctor-with-extensions # asciidoc is a markdown replacement
      clang # c and rust
      cmake # c
      couchbase-shell # couchbase
      d2 # graphs
      gnumake # makefile
      lean4 # theorem prover - broken
      lld # c and rust linker
      nodePackages.jsdoc # javascript documentation
      unstable.go
      unstable.golint # linter for go
      uv # python package installer
    ];
  };

  fonts = {
    fontconfig = {
      enable = true;
      defaultFonts = {
        serif = [ "Roboto Serif" ];
        sansSerif = [ "Roboto Flex" ];
        monospace = [ "Iosevka Nerd Font" ];
        emoji = [ "Twitter Color Emoji" ];
      };
    };
  };

  xdg = {
    enable = true;
    autostart.enable = true;
    portal = {
      enable = true;
      config.common = {
        default = [ "*" ];
        "org.freedesktop.impl.portal.FileChooser" = "termfilechooser";
      };
      xdgOpenUsePortal = true;
      extraPortals = with pkgs; [
        xdg-desktop-portal-wlr
        xdg-desktop-portal-termfilechooser
      ];
    };
    desktopEntries = {
      nvim = {
        name = "nvim";
        genericName = "Editor";
        exec = ''${pkgs.neovim}/bin/nvim'';
        terminal = true;
        categories = [ ];
        comment = "A text editor";
      };
    };

    mimeApps = {
      enable = true;
      defaultApplications = {
        "application/pdf" = [ "org.pwmt.zathura.desktop" ];
        "inode/directory" = "yazi.desktop";
        "image/jpeg" = [ "swayimg.desktop" ];
        "image/png" = [ "swayimg.desktop" ];
        "image/webp" = [ "swayimg.desktop" ];
        "text/html" = [ "firefox.desktop" ];
        "text/json" = [ "nvim.desktop" ];
        "text/markdown" = "nvim.desktop";
        "text/plain" = "nvim.desktop";
        "video/mp4" = "mpv.desktop";
        "video/webm" = "mpv.desktop";
        "x-scheme-handler/about" = "firefox.desktop";
        "x-scheme-handler/http" = "firefox.desktop";
        "x-scheme-handler/https" = "firefox.desktop";
        "x-scheme-handler/unknown" = "firefox.desktop";
      };
    };
  };
  wayland.windowManager.hyprland.systemd.variables = [ "--all" ];
  systemd.user = {
    startServices = "sd-switch";
  };

  xdg.configFile."nom/config.yml".text = ''
    autoread: true
    ordering: desc
    showread: false
    openers:
    - regex: "youtube"
      cmd: "mpv %s"
    - regex: ".*"
      cmd: "${pkgs.firefox}/bin/firefox %s"
    refreshinterval: 5
    filtering:
      defaultIncludeFeedName: true
    backends:
      miniflux:
        host: https://flux.tammi.cc
        api_key: $(${pkgs.coreutils}/bin/cat ${config.age.secrets.miniflux_api_key.path})
  '';

  systemd.user.services.ntfy-client = {
    Unit = {
      Description = "ntfy client subscriber";
      After = [ "graphical.target" ];
    };

    Install = {
      WantedBy = [ "default.target" ];
    };

    Service = {
      ExecStart = "${pkgs.ntfy-sh}/bin/ntfy subscribe --config /home/petri/.config/ntfy/client.yml --from-config";
      Restart = "on-failure";
      RestartSec = "10s";
      ProtectSystem = "strict";
      ProtectHome = "read-only";
      PrivateTmp = true;
      NoNewPrivileges = true;
      RestrictRealtime = true;
      LockPersonality = true;
    };
  };

  xdg.configFile."xdg-desktop-portal-termfilechooser/config".source =
    (pkgs.formats.toml { }).generate "termfilechooser-config"
      {
        filechooser = {
          cmd = "yazi-wrapper.sh";
          open_mode = "suggested";
          save_mode = "last";
          default_dir = "/home/petri/Downloads";
        };
      };

  xdg.configFile."xdg-desktop-portal-termfilechooser/yazi-wrapper.sh" = {
    force = true;
    executable = true;
    source = pkgs.writeShellScript "yazi-wrapper" ''
      # This wrapper script is invoked by xdg-desktop-portal-termfilechooser.
      # For more information about input/output arguments read `xdg-desktop-portal-termfilechooser(5)`
      set -e

      if [ "$6" -ge 4 ]; then
        set -x
      fi

      multiple="$1"
      directory="$2"
      save="$3"
      path="$4"
      out="$5"

      # Build yazi arguments
      yazi_args=""
      if [ "$save" = "1" ]; then
        # save a file
        yazi_args="--chooser-file=$out $path"
      elif [ "$directory" = "1" ]; then
        # upload files from a directory
        yazi_args="--chooser-file=$out --cwd-file=$out.1 $path"
      elif [ "$multiple" = "1" ]; then
        # upload multiple files
        yazi_args="--chooser-file=$out $path"
      else
        # upload only 1 file
        yazi_args="--chooser-file=$out $path"
      fi

      # Execute ghostty with yazi
      ${pkgs.ghostty}/bin/ghostty -e ${pkgs.yazi}/bin/yazi $yazi_args

      # Handle directory case output
      if [ "$directory" = "1" ]; then
        if [ ! -s "$out" ] && [ -s "$out.1" ]; then
          ${pkgs.coreutils}/bin/cat "$out.1" > "$out"
          rm -f "$out.1"
        else
          rm -f "$out.1"
        fi
      fi
    '';
  };

  systemd.user.services.bt-notify = {
    Unit = {
      Description = "Bluetooth Connection & Battery Notifications";
      After = [ "graphical-session.target" ];
      ConditionPathExists = "${config.home.homeDirectory}/.local/bin/bt-notify.sh";
    };
    Install = {
      WantedBy = [ "graphical-session.target" ];
    };
    Service = {
      Type = "simple";
      ExecStart = "${config.home.homeDirectory}/.local/bin/bt-notify.sh";
      Restart = "always";
      RestartSec = 5;
    };
  };

  home.file."/.local/bin/bt-notify.sh" = {
    executable = true;
    source = pkgs.writeShellScript "bt-notify" ''
      set -euo pipefail

      # Temporary file to remember which devices were connected last loop
      STATE_FILE="/tmp/bt-connected-state"

      # Ensure the file exists
      touch "$STATE_FILE"

      # Listen to BlueZ D-Bus signals AND poll for battery (some devices only report on poll)
      (
        # D-Bus listener (connection events)
        ${pkgs.dbus}/bin/dbus-monitor "interface=org.bluez.Device1,member=PropertiesChanged" --system &

        # Polling loop for battery (runs in background)
        while true; do
          ${pkgs.bluez}/bin/bluetoothctl devices | cut -f2 -d' ' | while read -r mac; do
            info=$(${pkgs.bluez}/bin/bluetoothctl info "$mac")
            name=$(echo "$info" | grep -i "Alias" | cut -d' ' -f2-)
            connected=$(echo "$info" | grep -i "Connected" | awk '{print $2}')
            battery_line=$(echo "$info" | grep -i "Battery Percentage" || true)
            battery=$(echo "$battery_line" | awk '{print $3}' | tr -d '()')

            # --- Connection change detection ---
            if [[ "$connected" == "yes" ]] && ! grep -q "^$mac$" "$STATE_FILE"; then
              ${pkgs.libnotify}/bin/notify-send -a "Bluetooth" "Connected" "$name"
              echo "$mac" >> "$STATE_FILE"
            elif [[ "$connected" == "no" ]] && grep -q "^$mac$" "$STATE_FILE"; then
              ${pkgs.libnotify}/bin/notify-send -a "Bluetooth" "Disconnected" "$name"
              sed -i "/^$mac$/d" "$STATE_FILE"
            fi

            # --- Low battery warning ---
            if [[ -n "$battery" && "$battery" -lt 20 ]]; then
              ${pkgs.libnotify}/bin/notify-send -u critical -a "Bluetooth" "Low Battery" "$name: ''${battery}%"
            fi
          done
          sleep 10
        done &
      ) | while read -r line; do
        # Parse D-Bus PropertiesChanged for Connected
        if echo "$line" | grep -q '"Connected"'; then
          path=$(echo "$line" | grep -oP 'path="\K[^"]+')
          mac=$(basename "$path")
          info=$(${pkgs.bluez}/bin/bluetoothctl info "$mac")
          name=$(echo "$info" | grep -i "Alias" | cut -d' ' -f2-)
          connected=$(echo "$info" | grep -i "Connected" | awk '{print $2}')

          if [[ "$connected" == "yes" ]] && ! grep -q "^$mac$" "$STATE_FILE"; then
            ${pkgs.libnotify}/bin/notify-send -a "Bluetooth" "Connected" "$name"
            echo "$mac" >> "$STATE_FILE"
          elif [[ "$connected" == "no" ]] && grep -q "^$mac$" "$STATE_FILE"; then
            ${pkgs.libnotify}/bin/notify-send -a "Bluetooth" "Disconnected" "$name"
            sed -i "/^$mac$/d" "$STATE_FILE"
          fi
        fi
      done
    '';
  };

  xdg.configFile."goose/config.yaml".source = (pkgs.formats.yaml { }).generate "goose-config" {
    OPENAI_BASE_PATH = "v1/chat/completions";
    extensions = {
      developer = {
        available_tools = [ ];
        bundled = true;
        description = null;
        display_name = "Developer";
        enabled = true;
        name = "developer";
        timeout = 300;
        type = "builtin";
      };
      computercontroller = {
        bundled = true;
        display_name = "Computer Controller";
        enabled = true;
        name = "computercontroller";
        timeout = 300;
        type = "builtin";
      };
      memory = {
        available_tools = [ ];
        bundled = true;
        description = "Tools to save and retrieve durable memories";
        display_name = "Memory";
        enabled = true;
        name = "memory";
        timeout = 80;
        type = "builtin";
      };
      todo = {
        available_tools = [ ];
        bundled = true;
        description = "Enable a todo list for Goose so it can keep track of what it is doing";
        enabled = true;
        name = "todo";
        type = "platform";
      };
      chatrecall = {
        available_tools = [ ];
        bundled = true;
        description = "Search past conversations and load session summaries for contextual memory";
        enabled = true;
        name = "chatrecall";
        type = "platform";
      };
      extensionmanager = {
        available_tools = [ ];
        bundled = true;
        description = "Enable extension management tools for discovering, enabling, and disabling extensions";
        enabled = true;
        name = "Extension Manager";
        type = "platform";
      };
      autovisualiser = {
        available_tools = [ ];
        bundled = true;
        description = "Data visualisation and UI generation tools";
        display_name = "Auto Visualiser";
        enabled = true;
        name = "autovisualiser";
        timeout = 300;
        type = "builtin";
      };
    };
    GOOSE_MODE = "auto";
    GOOSE_PROVIDER = "openai";
    GOOSE_MODEL = "gpt-4.1-mini";
    OPENAI_HOST = "https://api.openai.com";
  };

  xdg.configFile."ntfy/client.yml".source = (pkgs.formats.yaml { }).generate "ntfy-client-config" {
    "default-host" = "https://ntfy.tammi.cc";
    subscribe = [
      {
        topic = "77WxlkfsTzGrbYFw";
        host = "https://ntfy.tammi.cc";
        since = "1h";
        persist = true;
        keepalive = "45s";
        format = "markdown";
      }
    ];
  };
}