/ systems / modules / desktop / base.nix
base.nix
  1  { config, lib, pkgs, ... }:
  2  let
  3    inherit (lib) mkIf mkEnableOption mkDefault mkOption types;
  4    cfg = config.modules.desktop;
  5  in
  6  {
  7    options = {
  8      modules.desktop = {
  9        enable = mkEnableOption "desktop configuration";
 10        plymouth = {
 11          theme = mkOption {
 12            default = "deus_ex";
 13            description = "Plymouth theme to use for boot (hexagon, green_loader, deus_ex, cuts, sphere, spinner_alt)";
 14            type = types.str;
 15          };
 16          themePackage = mkOption {
 17            default = pkgs.my.adi1090x-plymouth;
 18            description = "Plymouth theme package to use";
 19            type = types.package;
 20          };
 21        };
 22      };
 23    };
 24    config = mkIf cfg.enable {
 25      # Putting this in desktop for now
 26      programs = {
 27        nix-ld = {
 28          enable = true;
 29          # put whatever libraries you think you might need
 30          # nix-ld includes a strong sane-default as well
 31          # in addition to these
 32          libraries = with pkgs; [
 33            acl
 34            alsa-lib
 35            at-spi2-atk
 36            at-spi2-core
 37            atk
 38            attr
 39            bzip2
 40            cairo
 41            curl
 42            dbus
 43            expat
 44            fontconfig
 45            freetype
 46            fuse3
 47            gdk-pixbuf
 48            glib
 49            glibc
 50            gtk3
 51            icu
 52            libGL
 53            libappindicator-gtk3
 54            libdrm
 55            libglvnd
 56            libnotify
 57            libpulseaudio
 58            libsecret
 59            libsodium
 60            libssh
 61            libunwind
 62            libusb1
 63            libuuid
 64            libxkbcommon
 65            mesa
 66            nspr
 67            nss
 68            openssl
 69            pango
 70            pipewire
 71            systemd
 72            stdenv.cc.cc # .lib
 73            util-linux
 74            # vulkan-loader
 75            # xorg.libX11
 76            # xorg.libXScrnSaver
 77            # xorg.libXcomposite
 78            # xorg.libXcursor
 79            # xorg.libXdamage
 80            # xorg.libXext
 81            # xorg.libXfixes
 82            # xorg.libXi
 83            # xorg.libXrandr
 84            # xorg.libXrender
 85            # xorg.libXtst
 86            # xorg.libxcb
 87            # xorg.libxkbfile
 88            # xorg.libxshmfence
 89            zlib
 90            zstd
 91          ];
 92        };
 93      };
 94  
 95      services = {
 96        envfs = {
 97          enable = true;
 98        };
 99      };
100  
101      modules.services.avahi.enable = true;
102      # Enable netbootxyz if systemd-boot is enabled
103      boot = {
104        loader.systemd-boot.netbootxyz.enable = config.core.boot.systemd-boot;
105        # /tmp to be tmpfs
106        tmp = {
107          useTmpfs = true;
108          cleanOnBoot = true;
109        };
110        # Enable Plymouth on desktops
111        plymouth = {
112          enable = true;
113          themePackages = [ cfg.plymouth.themePackage ];
114          theme = cfg.plymouth.theme;
115        };
116      };
117  
118      # Configure some fonts
119      fonts = {
120        # enableFontDir = true;
121        fontDir.enable = true;
122        enableGhostscriptFonts = true;
123        packages = with pkgs; [
124          cascadia-code
125          corefonts
126          dejavu_fonts
127          # emojione
128          feh
129          fira
130          fira-code
131          fira-code-symbols
132          fira-mono
133          font-awesome
134          go-font
135          hack-font
136          inconsolata
137          jetbrains-mono
138          liberation_ttf
139          nerd-fonts.jetbrains-mono
140          nerd-fonts.inconsolata
141          nerd-fonts.fira-code
142          nerd-fonts.fira-mono
143          nerd-fonts.caskaydia-cove
144          nerd-fonts.caskaydia-mono
145          nerd-fonts.overpass
146          nerd-fonts.ubuntu
147          nerd-fonts.ubuntu-mono
148          nerd-fonts.ubuntu-sans
149          noto-fonts
150          noto-fonts-cjk-sans
151          noto-fonts-emoji
152          noto-fonts-extra
153          overpass
154          symbola
155          twemoji-color-font
156          ubuntu_font_family
157          unifont
158          recursive
159        ];
160      };
161  
162      # Enable NetkworManager by default
163      networking.networkmanager = {
164        enable = mkDefault true;
165        unmanaged = [
166          "interface-name:br-*"
167          "interface-name:ve-*" # FIXME are those docker's or libvirt's
168          "interface-name:veth-*" # FIXME are those docker's or libvirt's
169        ]
170        # Do not manager wireguard
171        ++ lib.optionals config.networking.wireguard.enable [ "interface-name:wg0" ]
172        # Do not manage docker interfaces
173        ++ lib.optionals config.virtualisation.docker.enable [ "interface-name:docker0" ]
174        # Do not manager libvirt interfaces
175        ++ lib.optionals config.virtualisation.libvirtd.enable [ "interface-name:virbr*" ];
176        plugins = with pkgs; [ networkmanager-openvpn ];
177        # dispatcherScripts = [{
178        #   # https://askubuntu.com/questions/1271491/disable-wifi-if-lan-is-connected
179        #   source = pkgs.writeText "wifi-wired-exclusive" ''
180        #     #!${pkgs.bash}/bin/bash
181        #     export LC_ALL=C
182        # 
183        #     enable_disable_wifi ()
184        #     {
185        #         result=$(${pkgs.networkmanager}/bin/nmcli dev | ${pkgs.gnugrep}/bin/grep "ethernet" | ${pkgs.gnugrep}/bin/grep -w "connected")
186        #         if [ -n "$result" ]; then
187        #             ${pkgs.networkmanager}/bin/nmcli radio wifi off
188        #         else
189        #             ${pkgs.networkmanager}/bin/nmcli radio wifi on
190        #         fi
191        #     }
192        # 
193        #     if [ "$2" = "up" ]; then
194        #         enable_disable_wifi
195        #     fi
196        # 
197        #     if [ "$2" = "down" ]; then
198        #         enable_disable_wifi
199        #     fi
200        #   '';
201        #   type = "basic";
202        # }];
203      };
204  
205      nix = {
206        # Enable SSH-serving nix packages
207        sshServe.enable = mkDefault true;
208      };
209  
210      services = {
211        udisks2.enable = true;
212  
213        # Make `/run/user/X` larger.
214        logind.extraConfig = ''
215          RuntimeDirectorySize=20%
216        '';
217  
218        # Enable printing by default too
219        printing = {
220          enable = true;
221          drivers = [ pkgs.gutenprint ];
222        };
223      };
224    };
225  }