User Tools

Site Tools


configuration.nix

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
configuration.nix [2026/06/01 22:35] – created samconfiguration.nix [2026/06/29 14:27] (current) – tweaks sam
Line 1: Line 1:
 ====== My Nix Configuration ====== ====== My Nix Configuration ======
 +
 +In order to edit the configuration without root permissions, it is convenient to symlink ''configuration.nix'' to my user's home directory, like this:
 +<code>
 +mkdir ~/etc
 +sudo mv /etc/nixos/ ~/etc/
 +sudo chown -R $(id -un):users ~/etc/nixos/
 +sudo ln -s ~/etc/nixos/ /etc/
 +</code>
 +
 +===== The Configuration =====
  
 <code> <code>
Line 6: Line 16:
 # and in the NixOS manual (accessible by running ‘nixos-help’). # and in the NixOS manual (accessible by running ‘nixos-help’).
  
-{ config, pkgs, ... }:+{ config, pkgs, lib, ... }:
  
 let let
   home-manager = builtins.fetchTarball https://github.com/nix-community/home-manager/archive/release-26.05.tar.gz;   home-manager = builtins.fetchTarball https://github.com/nix-community/home-manager/archive/release-26.05.tar.gz;
 +
 +  # Given a list of attribute sets, union them into a single attribute
 +  # set, preferring keys earlier in the list.
 +  unionsAttrs = lib.foldAttrs lib.const {};
 in in
 { {
Line 31: Line 45:
   # Enable networking   # Enable networking
   networking.networkmanager.enable = true;   networking.networkmanager.enable = true;
 +
 +  # Enable bluetooth
 +  hardware.bluetooth = {
 +    enable = true;
 +    powerOnBoot = false;
 +  };
  
   # Set your time zone.   # Set your time zone.
Line 49: Line 69:
     LC_TIME = "en_US.UTF-8";     LC_TIME = "en_US.UTF-8";
   };   };
 +
 +  # Add swap
 +  swapDevices = [{
 +    device = "/var/lib/swapfile";
 +    size = 16*1024; # 16 GiB
 +  }];
  
   # Define a user account. Don't forget to set a password with ‘passwd’.   # Define a user account. Don't forget to set a password with ‘passwd’.
Line 65: Line 91:
   security.pam.services = {   security.pam.services = {
     greetd.enableGnomeKeyring = true;     greetd.enableGnomeKeyring = true;
 +    # Necessary for swaylock to work correctly.
 +    swaylock = {};
   };   };
  
Line 76: Line 104:
       };       };
     };     };
 +  };
 +
 +  services.logind.settings.Login = {
 +    # don’t shutdown when power button is short-pressed. We want sway
 +    # to handle that key instead.
 +    HandlePowerKey = "ignore";
 +  };
 +
 +  # CPU frequency scaling. This is meant to extend battery life.
 +  services.auto-cpufreq = {
 +    enable = true;
 +    settings = {
 +      battery = {
 +        governor = "powersave";
 +        turbo = "never";
 +      };
 +      charger = {
 +        governor = "performance";
 +        turbo = "auto";
 +      };
 +    };
 +  };
 +  # Tries to keep the CPU at a reasonable temperature by throttling
 +  # when necessary.
 +  services.thermald.enable = true;
 +
 +  # A service which automatically mounts external storage devices.
 +  services.udisks2.enable = true;
 +
 +  ## Printing ##########
 +
 +  # NOTE: see http://localhost:631 to configure printers.
 +  services.printing.enable = true;
 +
 +  # The below is for automatic discovery of network printers using
 +  # the IPP Everywhere protocol.
 +  services.avahi = {
 +    enable = true;
 +    nssmdns4 = true;
 +    openFirewall = true;
   };   };
  
   # Fonts   # Fonts
   fonts.packages = with pkgs; [   fonts.packages = with pkgs; [
-    nerd-fonts.aurulent-sans-mono+    hack-font
   ];   ];
  
Line 89: Line 157:
       # Permits adjustment of audio volume via pactl       # Permits adjustment of audio volume via pactl
       pactl = "${pkgs.pulseaudio}/bin/pactl";       pactl = "${pkgs.pulseaudio}/bin/pactl";
 +      # Permits locking the screen
 +      swaylock = "${pkgs.swaylock}/bin/swaylock";
     in {     in {
       home.packages = with pkgs; [       home.packages = with pkgs; [
-        kdePackages.falkon 
- 
         # For keeping track of passwords:         # For keeping track of passwords:
         pass         pass
Line 106: Line 174:
         # we will start this program as a systemd service.         # we will start this program as a systemd service.
         davmail         davmail
 +
 +        # dokoff (locally defined)
 +        (callPackage /home/sam/Projects/dokoff/dokoff.nix { })
 +
 +        # For taking screenshots
 +        grim
       ];       ];
  
       programs.bash = {       programs.bash = {
         enable = true;         enable = true;
 +        enableCompletion = true;
         bashrcExtra = "eval \"$(direnv hook bash)\"";         bashrcExtra = "eval \"$(direnv hook bash)\"";
       };       };
Line 125: Line 200:
           user.name = "Sam Cohen";           user.name = "Sam Cohen";
           user.email = "sbcohen2000@gmail.com";           user.email = "sbcohen2000@gmail.com";
 +          rebase.autoSquash = true;
         };         };
       };       };
Line 136: Line 212:
         enable = true;         enable = true;
         pinentry.package = pkgs.pinentry-qt;         pinentry.package = pkgs.pinentry-qt;
 +        defaultCacheTtl = 1800; # Only ask for a password half an hour after inactivity
       };       };
  
Line 143: Line 220:
         enable = true;         enable = true;
         themeFile = "AtomOneLight";         themeFile = "AtomOneLight";
-        font.name = "AurulentSansM Nerd Font";+        font.name = "Hack";
         font.size = 10;         font.size = 10;
 +        # Make the text render a lot thicker, more similar to emacs
 +        # text rendering:
 +        extraConfig = "text_composition_strategy 1.5 15";
 +      };
 +
 +      programs.rofi = {
 +        enable = true;
 +        modes = [ "drun" ];
 +        theme = "dmenu";
 +      };
 +
 +      # Client for udisks2
 +      services.udiskie = {
 +        enable = true;
       };       };
  
Line 155: Line 246:
         # it later.         # it later.
         MU4E = "${pkgs.mu.mu4e}";         MU4E = "${pkgs.mu.mu4e}";
 +        EDITOR = "emacsclient";
       };       };
  
Line 168: Line 260:
           ];           ];
           modifier = "Mod4";           modifier = "Mod4";
-         keybindings = { +          keybindings = let 
-            # Navigation +            workspaces [1 2 3 4];
-            "${modifier}+0" "workspace number 10"; +
-            "${modifier}+1" = "workspace number 1"; +
-            "${modifier}+2" = "workspace number 2"; +
-            "${modifier}+3" = "workspace number 3"; +
-            "${modifier}+4" = "workspace number 4"; +
-            "${modifier}+5" = "workspace number 5"; +
-            "${modifier}+6" = "workspace number 6"; +
-            "${modifier}+7" = "workspace number 7"; +
-            "${modifier}+8" = "workspace number 8"; +
-            "${modifier}+9" = "workspace number 9"; +
-            "${modifier}+Shift+0" = "move container to workspace number 10"; +
-            "${modifier}+Shift+1" = "move container to workspace number 1"; +
-            "${modifier}+Shift+2" = "move container to workspace number 2"; +
-            "${modifier}+Shift+3" = "move container to workspace number 3"; +
-            "${modifier}+Shift+4" = "move container to workspace number 4"; +
-            "${modifier}+Shift+5" = "move container to workspace number 5"; +
-            "${modifier}+Shift+6" = "move container to workspace number 6"; +
-            "${modifier}+Shift+7" = "move container to workspace number 7"; +
-            "${modifier}+Shift+8" = "move container to workspace number 8"; +
-            "${modifier}+Shift+9" = "move container to workspace number 9"; +
-            "${modifier}+Left" = "focus left"; +
-            "${modifier}+Right" = "focus right"; +
-            "${modifier}+Up" = "focus up"; +
-            "${modifier}+Down" = "focus down"; +
-            "${modifier}+Shift+Left" = "move left"; +
-            "${modifier}+Shift+Right" = "move right"; +
-            "${modifier}+Shift+Up" = "move up"; +
-            "${modifier}+Shift+Down" = "move down";+
  
-            "${modifier}+q" = "kill"; +            # Setup two bindings for each workspace, one which moves 
-            "${modifier}+a" = "focus parent"; +            # to the workspace, and one which moves the current 
-            "${modifier}+f" = "fullscreen toggle"; +            # container to the workspace: 
-            "${modifier}+space" = "layout toggle split"; +            bindings = lib.listToAttrs 
-            "${modifier}+Shift+space" = "floating toggle";+              (lib.concatMap (n: 
 +                let 
 +                  ns = toString n; 
 +                in [ 
 +                  { "name""${modifier}+${ns}";       value = "workspace number ${ns}"; 
 +                  { "name" = "${modifier}+Shift+${ns}"; value = "move container to workspace number ${ns}";
 +                ]) workspaces); 
 +          in 
 +            unionsAttrs [ 
 +              bindings 
 +              { 
 +                "${modifier}+Left" = "focus left"; 
 +                "${modifier}+Right" = "focus right"; 
 +                "${modifier}+Up" = "focus up"; 
 +                "${modifier}+Down" = "focus down"; 
 +                "${modifier}+Shift+Left" = "move left"; 
 +                "${modifier}+Shift+Right" = "move right"; 
 +                "${modifier}+Shift+Up" = "move up"; 
 +                "${modifier}+Shift+Down" = "move down";
  
-           # Brightness Controls +                "${modifier}+r" = "mode resize"; 
-           "XF86MonBrightnessDown" = "exec ${brightnessctls 10%-"; +                "${modifier}+q" = "kill"; 
-            "XF86MonBrightnessUp" = "exec ${brightnessctl+10%";+                "${modifier}+a" = "focus parent"; 
 +                "${modifier}+f" = "fullscreen toggle"; 
 +                "${modifier}+space" = "layout toggle split"; 
 +                "${modifier}+Shift+space" = "floating toggle";
  
-            Volume Controls +                Brightness Controls 
-            "XF86AudioRaiseVolume" = "exec ${pactlset-sink-volume @DEFAULT_SINK@ +5%"; +                "XF86MonBrightnessDown" = "exec ${brightnessctl5%-"; 
-            "XF86AudioLowerVolume" = "exec ${pactlset-sink-volume @DEFAULT_SINK@ -5%"; +                "XF86MonBrightnessUp" = "exec ${brightnessctls +5%";
-            "XF86AudioMute" = "exec ${pactl} set-sink-mute @DEFAULT_SINK@ toggle";+
  
-            # Launching +                # Volume Controls 
-            "${modifier}+Return" = "exec kitty"; +                "XF86AudioRaiseVolume" = "exec ${pactl} set-sink-volume @DEFAULT_SINK@ +5%"; 
-            "${modifier}+e" = "exec emacsclient -c"; +                "XF86AudioLowerVolume" = "exec ${pactl} set-sink-volume @DEFAULT_SINK@ -5%"; 
-            "${modifier}+b" = "exec falkon"; +                "XF86AudioMute" = "exec ${pactl} set-sink-mute @DEFAULT_SINK@ toggle"; 
-         }; + 
-         input = { +                # Launching 
-           "type:keyboard" = { +                "${modifier}+d" = "exec rofi -show"; 
-             xkb_options = "ctrl:nocaps"; +                "${modifier}+Return" = "exec kitty"; 
-             repeat_delay = "250"; +                "${modifier}+e" = "exec emacsclient -c"; 
-             repeat_rate = "30"; +                "${modifier}+b" = "exec firefox"; 
-           }; + 
-           "type:touchpad" = { +                # Locking 
-             tap = "enabled"; +                "XF86PowerOff" = "exec ${swaylock}"
-             # Prevent an odd feature where after tapping you can drag +              } 
-             # the mouse to create a selection. +            ]; 
-             drag = "disabled"; + 
-             drag_lock = "disabled";+          input = { 
 +            "type:keyboard" = { 
 +              xkb_options = "ctrl:nocaps"; 
 +              repeat_delay = "250"; 
 +              repeat_rate = "30"; 
 +            }; 
 +            "type:touchpad" = { 
 +              tap = "enabled"; 
 +              # Prevent an odd feature where after tapping you can drag 
 +              # the mouse to create a selection. 
 +              drag = "disabled"; 
 +              drag_lock = "disabled";
  
               # Change scroll direction.               # Change scroll direction.
-             natural_scroll = "enabled";+              natural_scroll = "enabled";
  
               # Disable trackpad while typing.               # Disable trackpad while typing.
-             dwt = "enabled"; +              dwt = "enabled"; 
-           }; +            }; 
-         };+          };
         };         };
       };       };
Line 252: Line 347:
             resumeCommand = "${brightnessctl} -r"; # Restore the previous brightness.             resumeCommand = "${brightnessctl} -r"; # Restore the previous brightness.
           }           }
-         +          
-           timeout = 5 * 60; +            timeout = 5 * 60; 
-           command = "${pkgs.systemd}/bin/systemctl suspend"; +            command = "${pkgs.systemd}/bin/systemctl suspend"; 
-         }+          }
         ];         ];
         events = {         events = {
-          "after-resume" = "${brightnessctl} -r"; # Restore the previous brightness.;+          # Restore the previously saved brightness. 
 +          "after-resume" = "${brightnessctl} -r"; 
 +          "before-sleep" = "${swaylock}";
         };         };
 +      };
 +
 +      # Locks the screen when power button is pressed.
 +      programs.swaylock = {
 +        enable = true;
 +      };
 +
 +      # Displays notifications when called upon.
 +      services.mako = {
 +        enable = true;
 +        settings = {
 +          default-timeout = 5000; # 5 seconds.
 +        };
 +      };
 +
 +      programs.firefox = {
 +        enable = true;
       };       };
  
Line 287: Line 401:
   # $ nix search wget   # $ nix search wget
   environment.systemPackages = with pkgs; [   environment.systemPackages = with pkgs; [
-    pkgs.direnv +    libnotify          # Send notifications to the notification daemon. 
-  ];+    wl-clipboard       # Copy/Paste from the terminal (`wl-copy/paste`). 
 +    direnv 
 +    kdePackages.okular # A PDF viewer 
 +    darktable          # Raw image editor 
 +    gphoto2            # A command-line program to communicate with cameras
  
-  Some programs need SUID wrappers, can be configured further or are +    ## In Service of Emacs ##########
-  started in user sessions. +
-  programs.mtr.enable = true; +
-  programs.gnupg.agent = { +
-    enable = true; +
-    enableSSHSupport = true; +
-  };+
  
-  List services that you want to enable: +    Ghostscript is necessary to interpret PDF files in emacs' 
- +    document viewer
-  Enable the OpenSSH daemon+    ghostscript 
-  # services.openssh.enable = true; +    ispell             A spell-checking program
- +    ripgrep            A better grep
-  Open ports in the firewall+  ];
-  networking.firewall.allowedTCPPorts = [ ... ]; +
-  # networking.firewall.allowedUDPPorts = [ ... ]+
-  # Or disable the firewall altogether. +
-  # networking.firewall.enable = false;+
  
   # This value determines the NixOS release from which the default   # This value determines the NixOS release from which the default
configuration.nix.1780353359.txt.gz · Last modified: by sam