diff --git a/Makefile b/Makefile index a6b8a463..8e11fd18 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,9 @@ NIXOS_VERSION := 19.09 NIXOS_PREFIX := $(PREFIX)/etc/nixos - -FLAGS := -I "my=$(PWD)" $(FLAGS) COMMAND := test +FLAGS := -I "nixpkgs-overlays=$$(pwd)/overlays.nix" \ + -I "config=$$(pwd)/config" \ + -I "modules=$$(pwd)/modules" $(FLAGS) # The real Labowski all: channels @@ -36,7 +37,7 @@ channels: $(NIXOS_PREFIX)/configuration.nix: @sudo nixos-generate-config --root "$(PREFIX)" - @echo "import $(PWD)/dotfiles \"$(HOST)\"" | sudo tee "$(NIXOS_PREFIX)/configuration.nix" + @echo "(import /etc/dotfiles \"$$(hostname)\")" | sudo tee "$(NIXOS_PREFIX)/configuration.nix" # Convenience aliases @@ -45,4 +46,4 @@ s: switch up: upgrade -.PHONY: update config channels test upgrade install +.PHONY: config diff --git a/config/zsh/.zshenv b/config/zsh/.zshenv index f2edf311..430d11c3 100644 --- a/config/zsh/.zshenv +++ b/config/zsh/.zshenv @@ -1,8 +1,5 @@ -export ZGEN_DIR="$XDG_CACHE_HOME/zgen" -export ZGEN_SOURCE="$ZGEN_DIR/zgen.zsh" - -## TODO -source $ZDOTDIR/extra.zshenv +## Auto-generated by my nix config +[ -f "${0:a:h}/extra.zshenv" ] && source "${0:a:h}/extra.zshenv" # If you have host-local configuration, this is where you'd put it [ -f ~/.zshenv ] && source ~/.zshenv diff --git a/config/zsh/.zshrc b/config/zsh/.zshrc index 259a4afe..cb2cdb35 100644 --- a/config/zsh/.zshrc +++ b/config/zsh/.zshrc @@ -1,26 +1,21 @@ -[ -d "$ZGEN_DIR" ] || \ - git clone https://github.com/tarjoilija/zgen "$ZGEN_DIR" -source $ZGEN_SOURCE +export ZGEN_DIR="$XDG_CACHE_HOME/zgen" +export ZGEN_SOURCE="$ZGEN_DIR/zgen.zsh" +[ -d "$ZGEN_DIR" ] || git clone https://github.com/tarjoilija/zgen "$ZGEN_DIR" +source $ZGEN_SOURCE if ! zgen saved; then echo "Initializing zgen" - zgen load hlissner/zsh-autopair autopair.zsh zgen load zsh-users/zsh-history-substring-search zgen load zdharma/history-search-multi-word zgen load zsh-users/zsh-completions src zgen load junegunn/fzf shell - - if [ -z "$SSH_CONNECTION" ]; then - zgen load zdharma/fast-syntax-highlighting - fi - + [ -z "$SSH_CONNECTION" ] && zgen load zdharma/fast-syntax-highlighting zgen save fi source $ZDOTDIR/config.zsh if [[ $TERM != dumb ]]; then - source $ZDOTDIR/prompt.zsh source $ZDOTDIR/keybinds.zsh source $ZDOTDIR/completion.zsh source $ZDOTDIR/aliases.zsh @@ -47,7 +42,7 @@ if [[ $TERM != dumb ]]; then fi _cache fasd --init posix-alias zsh-{hook,{c,w}comp{,-install}} - ## TODO + ## Auto-generated by my nix config source $ZDOTDIR/extra.zshrc ## diff --git a/default.nix b/default.nix index cca376c5..a8eb183a 100644 --- a/default.nix +++ b/default.nix @@ -1,4 +1,4 @@ -# ... +# default.nix --- my dotfile bootstrapper device: { pkgs, options, lib, config, ... }: @@ -6,39 +6,27 @@ device: networking.hostName = lib.mkDefault device; imports = [ - - /etc/nixos/hardware-configuration.nix - - ./options/my.nix - "${./machines}/${device}.nix" + ./options.nix + "${./hosts}/${device}" ]; - ### - nix = { - nixPath = options.nix.nixPath.default ++ [ - "my=/etc/dotfiles" - ]; - autoOptimiseStore = true; - trustedUsers = [ "root" ]; - }; - - nixpkgs.config = { - allowUnfree = true; # forgive me Stallman senpai - # Occasionally, "stable" packages are broken or incomplete, so access to the - # bleeding edge is necessary, as a last resort. - packageOverrides = pkgs: { - unstable = import { - config = config.nixpkgs.config; - }; - }; - }; - - environment.systemPackages = with pkgs; [ - # cached-nix-shell, for instant nix-shell scripts - (callPackage - (builtins.fetchTarball - https://github.com/xzfc/cached-nix-shell/archive/master.tar.gz) {}) + ### NixOS + nix.autoOptimiseStore = true; + nix.nixPath = options.nix.nixPath.default ++ [ + # So we can use absolute import paths + "config=/etc/dotfiles/config" + "modules=/etc/dotfiles/modules" + # We define nixpkgs-overlays so our overlays will be available to + # nix-shell/nix-build outside of rebuilding... + "nixpkgs-overlays=/etc/dotfiles/overlays.nix" ]; + # ...but we still need to set nixpkgs.overlays to make them visible to the + # rebuild process, however... + nixpkgs.overlays = import ./overlays.nix; + nixpkgs.config.allowUnfree = true; # forgive me Stallman senpai + + # For instant nix-shell scripts + environment.systemPackages = [ pkgs.my.cached-nix-shell ]; # This value determines the NixOS release with which your system is to be # compatible, in order to avoid breaking some software such as database diff --git a/deploy b/deploy old mode 100644 new mode 100755 index 3a53f502..be3e3865 --- a/deploy +++ b/deploy @@ -8,7 +8,7 @@ if [ $EUID -nq 0 ]; then fi USER=${USER:-hlissner} -HOST=${1:-${HOST:-kuro}} +HOST=${1:-${HOST:-$(hostname)}} DOTFILES="/home/$USER/.dotfiles" if [ ! -d /etc/dotfiles ]; then @@ -21,9 +21,4 @@ if [ ! -f "$DOTFILES/machines/$HOST.nix" ]; then >&2 echo "No configuration exists for host '$HOST'" exit 1 fi - -if [ -n "$LINODE" ]; then - ARGS="\"$HOST\"" - HOST=linode -fi make -C "$DOTFILES" install diff --git a/machines/aka.nix b/hosts/aka/default.nix similarity index 57% rename from machines/aka.nix rename to hosts/aka/default.nix index 75430e67..54da94b3 100644 --- a/machines/aka.nix +++ b/hosts/aka/default.nix @@ -5,10 +5,12 @@ imports = [ ./. # import common settings - - ./modules/services/plex.nix - # - + + + + + # + ]; networking.networkmanager.enable = true; diff --git a/machines/ao.nix b/hosts/ao/default.nix similarity index 93% rename from machines/ao.nix rename to hosts/ao/default.nix index 2d6ce619..a7c458d1 100644 --- a/machines/ao.nix +++ b/hosts/ao/default.nix @@ -1,17 +1,17 @@ # Ao -- my home development and user-facing server -{ config, ... }: +{ pkgs, config, ... }: { imports = [ ./. # import common settings - - - - + + + + - - + + ]; networking.networkmanager.enable = true; @@ -155,4 +155,18 @@ SSH_DOMAIN = v0.io ''; }; + + services.fail2ban = { + enable = true; + jails.DEFAULT = '' + ignoreip = 127.0.0.1/8,192.168.1.0/24 + bantime = 3600 + maxretry = 5 + ''; + jails.sshd = '' + filter = sshd + action = iptables[name=ssh, port=22, protocl=tcp] + enabled = true + ''; + }; } diff --git a/hosts/default.nix b/hosts/default.nix new file mode 100644 index 00000000..1dfb4822 --- /dev/null +++ b/hosts/default.nix @@ -0,0 +1,32 @@ +# hosts/default.nix --- settings common to all my systems + +{ pkgs, ... }: +{ + # Just the bear necessities~ + environment.systemPackages = with pkgs; [ + coreutils + git + killall + unzip + vim + wget + sshfs + ]; + + + ### My user settings + my.username = "hlissner"; + my.env.PATH = [ ../bin ]; + my.user = { + isNormalUser = true; + uid = 1000; + extraGroups = [ "wheel" "video" "networkmanager" ]; + shell = pkgs.zsh; + }; + my.alias.nix-env = "NIXPKGS_ALLOW_UNFREE=1 nix-env"; + my.alias.nsh = "nix-shell"; + my.alias.nen = "nix-env"; + my.alias.sc = "systemctl"; + my.alias.ssc = "sudo systemctl"; + my.alias.dots = "make -C ~/.dotfiles"; +} diff --git a/hosts/kuro/default.nix b/hosts/kuro/default.nix new file mode 100644 index 00000000..805ce5ce --- /dev/null +++ b/hosts/kuro/default.nix @@ -0,0 +1,39 @@ +# Kuro -- my desktop + +{ pkgs, ... }: +{ + imports = [ + ../personal.nix # common settings + ./hardware-configuration.nix + ## Desktop/shell environment + + ## Apps + # + + + + + + + + + + + + + ## Project-based + # # discord, mainly + # recording video & audio + # making music + # playing music + # art & design + # virtualbox for testing + ## Services + + ## Theme + + ]; + + networking.networkmanager.enable = true; + time.timeZone = "America/Toronto"; +} diff --git a/hosts/kuro/hardware-configuration.nix b/hosts/kuro/hardware-configuration.nix new file mode 100644 index 00000000..d36b5631 --- /dev/null +++ b/hosts/kuro/hardware-configuration.nix @@ -0,0 +1,75 @@ +{ config, pkgs, lib, ... }: +{ + imports = [ + + ]; + + boot.initrd.availableKernelModules = [ "xhci_pci" "ehci_pci" "ahci" "usbhid" "uas" "usb_storage" "sd_mod" ]; + boot.initrd.kernelModules = [ ]; + boot.kernelModules = [ "kvm-intel" ]; + boot.extraModulePackages = [ ]; + + ### CPU + nix.maxJobs = lib.mkDefault 8; + powerManagement.cpuFreqGovernor = "performance"; + + ## SSDs + services.fstrim.enable = true; + + ## Ergodox + my.packages = [ pkgs.teensy-loader-cli ]; + my.alias.teensyload = "sudo teensy-loader-cli -w -v --mcu=atmega32u4"; + + ## GPU + services.xserver.videoDrivers = [ "nvidia" ]; + hardware.opengl.enable = true; + # Respect XDG conventions, damn it! + environment.systemPackages = with pkgs; [ + (writeScriptBin "nvidia-settings" '' + #!${stdenv.shell} + exec ${config.boot.kernelPackages.nvidia_x11}/bin/nvidia-settings --config="$XDG_CONFIG_HOME/nvidia/settings" + '') + ]; + + ## Tablet + # For my intuos4 pro. Doesn't work for cintiqs. + services.xserver.wacom.enable = true; + # TODO Move this to udev + # my.init = '' + # # lock tablet to main display + # if xinput list --id-only "Wacom Intuos Pro S Pen stylus" 2>&1 >/dev/null; then + # xinput map-to-output $(xinput list --id-only "Wacom Intuos Pro S Pen stylus") DVI-I-1 + # xinput map-to-output $(xinput list --id-only "Wacom Intuos Pro S Pen eraser") DVI-I-1 + # xinput map-to-output $(xinput list --id-only "Wacom Intuos Pro S Pen cursor") DVI-I-1 + # fi + # ''; + + ### Harddrives + fileSystems = { + "/" = { + device = "/dev/disk/by-label/nixos"; + fsType = "ext4"; + options = [ "noatime" ]; + }; + "/boot" = { + device = "/dev/disk/by-label/BOOT"; + fsType = "vfat"; + }; + "/mnt/projects" = { + device = "/dev/disk/by-label/projects"; + fsType = "ext4"; + options = [ "noatime" ]; + }; + "/mnt/archive" = { + device = "/dev/disk/by-label/archive"; + fsType = "ext4"; + options = [ "noatime" ]; + }; + "/mnt/local" = { + device = "/dev/disk/by-label/local"; + fsType = "ext4"; + options = [ "noatime" ]; + }; + }; + swapDevices = [ { device = "/dev/disk/by-label/swap"; } ]; +} diff --git a/modules/linode.nix b/hosts/linode.nix similarity index 89% rename from modules/linode.nix rename to hosts/linode.nix index fea78024..4090d5d5 100644 --- a/modules/linode.nix +++ b/hosts/linode.nix @@ -33,11 +33,11 @@ with pkgs; [ inetutils mtr sysstat git ]; imports = [ - ../. - - - - + ./. + + + + ]; # GRUB @@ -62,6 +62,4 @@ networking.useDHCP = false; networking.usePredictableInterfaceNames = false; networking.interfaces.eth0.useDHCP = true; - - time.timeZone = "America/Toronto"; } diff --git a/machines/default.nix b/hosts/personal.nix similarity index 65% rename from machines/default.nix rename to hosts/personal.nix index 5224130b..203f2471 100644 --- a/machines/default.nix +++ b/hosts/personal.nix @@ -1,50 +1,32 @@ -# ... +# hosts/personal.nix --- settings common to my personal systems -{ config, options, lib, pkgs, ... }: +{ pkgs, ... }: { + imports = [ ./. ]; + + environment.systemPackages = with pkgs; [ + # Support for more filesystems + exfat + ntfs3g + hfsprogs + ]; + # Nothing in /tmp should survive a reboot boot.tmpOnTmpfs = true; # Use simple bootloader; I prefer the on-demand BIOs boot menu boot.loader.systemd-boot.enable = true; boot.loader.efi.canTouchEfiVariables = true; - # Just the bear necessities~ - environment.systemPackages = with pkgs; [ - coreutils - git - killall - unzip - vim - wget - # Support for extra filesystems - sshfs - exfat - ntfs3g - hfsprogs - ]; - - ### - # My user settings - my = { - username = "hlissner"; - env.PATH = [ ]; - user = { - isNormalUser = true; - uid = 1000; - extraGroups = [ "wheel" "video" "networkmanager" ]; - shell = pkgs.zsh; - }; - - alias.nix-env = "NIXPKGS_ALLOW_UNFREE=1 nix-env"; - alias.nen = "nix-env"; - alias.sc = "systemctl"; - alias.ssc = "sudo systemctl"; - alias.dots = "make -C ~/.dotfiles"; - }; - - ### Universal defaults networking.firewall.enable = true; + networking.hosts = { + "192.168.1.2" = [ "ao" ]; + "192.168.1.3" = [ "aka" ]; + "192.168.1.10" = [ "kuro" ]; + "192.168.1.11" = [ "shiro" ]; + "192.168.1.12" = [ "midori" ]; + }; + ### A tidy $HOME is a tidy mind. # Obey XDG conventions; @@ -57,7 +39,6 @@ XDG_DATA_HOME = "$HOME/.local/share"; XDG_BIN_HOME = "$HOME/.local/bin"; }; - # Conform more programs to XDG conventions. The rest are handled by their # respective modules. my.env = { diff --git a/hosts/shiro/default.nix b/hosts/shiro/default.nix new file mode 100644 index 00000000..f1419ef1 --- /dev/null +++ b/hosts/shiro/default.nix @@ -0,0 +1,57 @@ +# Shiro -- my laptop + +{ pkgs, ... }: +{ + imports = [ + ../personal.nix # common settings + ./hardware-configuration.nix + (let nixos-hardware = + builtins.fetchTarball + https://github.com/NixOS/nixos-hardware/archive/master.tar.gz; + in "${nixos-hardware}/dell/xps/13-9370") + ## Dekstop environment + + ## Apps + + + + + + + + + + ## Project-based + # # discord, mainly + # recording video & audio + # making music + # playing music + # art & design + # # virtualbox for testing + ## Services + + ## Theme + + ]; + + networking.wireless.enable = true; + hardware.opengl.enable = true; + + time.timeZone = "America/Toronto"; + # time.timeZone = "Europe/Copenhagen"; + + # Optimize power use + environment.systemPackages = [ pkgs.acpi ]; + powerManagement.powertop.enable = true; + # Monitor backlight control + programs.light.enable = true; + # Encrypted /home + boot.initrd.luks.devices = [ + { + name = "home"; + device = "/dev/nvme0n1p8"; + preLVM = true; + allowDiscards = true; + } + ]; +} diff --git a/machines/holo.nix b/machines/holo.nix deleted file mode 100644 index b35509c9..00000000 --- a/machines/holo.nix +++ /dev/null @@ -1,23 +0,0 @@ -# FIXME - -{ config, lib, pkgs, ... }: -{ - imports = [ - - ]; - - networking.hostName = "holo"; - time.timeZone = "America/Toronto"; - - services.nginx = { - # user = config.my.username; - virtualHosts = { - # "domain.com" = { - # default = true; - # enableACME = true; - # forceSSL = true; - # root = "..."; - # }; - }; - }; -} diff --git a/machines/kuro.nix b/machines/kuro.nix deleted file mode 100644 index 613a1df7..00000000 --- a/machines/kuro.nix +++ /dev/null @@ -1,49 +0,0 @@ -# Kuro -- my desktop - -{ config, lib, utils, pkgs, ... }: -{ - imports = [ - ./. # import common settings - - - - - - - # discord, mainly - # recording video & audio - # making music - # playing music - # art & design - # virtualbox for testing - - # - - - - - - - - - - - - - # Services - - - # Themes - - ]; - - networking.networkmanager.enable = true; - time.timeZone = "America/Toronto"; - - # Mouse settings - services.xserver.libinput = { - enable = true; - middleEmulation = true; - scrollButton = 3; - }; -} diff --git a/machines/shiro.nix b/machines/shiro.nix deleted file mode 100644 index 0ffb20a8..00000000 --- a/machines/shiro.nix +++ /dev/null @@ -1,60 +0,0 @@ -# Shiro -- my laptop - -{ config, lib, pkgs, ... }: - -let nixos-hardware = builtins.fetchTarball https://github.com/NixOS/nixos-hardware/archive/master.tar.gz; -in { - imports = [ - ./. # import common settings - - # Hardware specific - "${nixos-hardware}/dell/xps/13-9370" - - - - # discord, mainly - # recording video & audio - # making music - # playing music - # art & design - # # virtualbox for testing - - - - - - - - - - - - # Services - - - # Themes - - ]; - - theme.wallpaper = ; - networking.wireless.enable = true; - hardware.opengl.enable = true; - - time.timeZone = "America/Toronto"; - # time.timeZone = "Europe/Copenhagen"; - - # Optimize power use - environment.systemPackages = [ pkgs.acpi ]; - powerManagement.powertop.enable = true; - # Monitor backlight control - programs.light.enable = true; - # Encrypted /home - boot.initrd.luks.devices = [ - { - name = "home"; - device = "/dev/nvme0n1p8"; - preLVM = true; - allowDiscards = true; - } - ]; -} diff --git a/modules/browser/qutebrowser.nix b/modules/browser/qutebrowser.nix index 02f89434..9c22f972 100644 --- a/modules/browser/qutebrowser.nix +++ b/modules/browser/qutebrowser.nix @@ -9,11 +9,11 @@ my.env.BROWSER = "qutebrowser"; my.home.xdg = { configFile."qutebrowser" = { - source = ; + source = ; recursive = true; }; dataFile."qutebrowser/greasemonkey" = { - source = ; + source = ; recursive = true; }; }; diff --git a/modules/chat.nix b/modules/chat.nix index b81c2cb6..3dd06ce2 100644 --- a/modules/chat.nix +++ b/modules/chat.nix @@ -3,7 +3,7 @@ # Even neckbeards have a social life. Not that I have one. A neckbeard, I mean. # But when I do have either, then discord and weechat are my go-to. -{ config, lib, pkgs, ... }: +{ pkgs, ... }: { my.packages = with pkgs; [ # weechat # TODO For the real neckbeards diff --git a/modules/desktop/apps/redshift.nix b/modules/desktop/apps/redshift.nix new file mode 100644 index 00000000..3c7d6b7a --- /dev/null +++ b/modules/desktop/apps/redshift.nix @@ -0,0 +1,15 @@ +# modules/desktop/apps/redshift.nix + +{ config, lib, pkgs, ... }: +{ + services.redshift.enable = true; + + # For redshift + location = (if config.time.timeZone == "America/Toronto" then { + latitude = 43.70011; + longitude = -79.4163; + } else if config.time.timeZone == "Europe/Copenhagen" then { + latitude = 55.88; + longitude = 12.5; + } else {}); +} diff --git a/modules/desktop/rofi.nix b/modules/desktop/apps/rofi.nix similarity index 81% rename from modules/desktop/rofi.nix rename to modules/desktop/apps/rofi.nix index ec073673..d7fe469a 100644 --- a/modules/desktop/rofi.nix +++ b/modules/desktop/apps/rofi.nix @@ -2,10 +2,10 @@ { my = { - env.PATH = [ ]; + env.PATH = [ ]; # link recursively so other modules can link files in its folder home.xdg.configFile."rofi" = { - source = ; + source = ; recursive = true; }; @@ -18,21 +18,21 @@ # Fake rofi dmenu entries (makeDesktopItem { name = "rofi-browsermenu"; - desktopName = "Open Bookmark in Firefox"; + desktopName = "Open Bookmark in Browser"; icon = "bookmark-new-symbolic"; - exec = "${}/bin/rofi-browsermenu"; + exec = "${}/bin/rofi-browsermenu"; }) (makeDesktopItem { name = "rofi-filemenu"; desktopName = "Open Directory in Terminal"; icon = "folder"; - exec = "${}/bin/rofi-filemenu"; + exec = "${}/bin/rofi-filemenu"; }) (makeDesktopItem { name = "rofi-filemenu-scratch"; desktopName = "Open Directory in Scratch Terminal"; icon = "folder"; - exec = "${}/bin/rofi-filemenu -x"; + exec = "${}/bin/rofi-filemenu -x"; }) (makeDesktopItem { diff --git a/modules/desktop/thunar.nix b/modules/desktop/apps/thunar.nix similarity index 100% rename from modules/desktop/thunar.nix rename to modules/desktop/apps/thunar.nix diff --git a/modules/desktop/bspwm.nix b/modules/desktop/bspwm.nix index 03187b83..30f50b01 100644 --- a/modules/desktop/bspwm.nix +++ b/modules/desktop/bspwm.nix @@ -2,14 +2,14 @@ { imports = [ - ./. - # My launcher - ./rofi.nix + ./apps/rofi.nix # I often need a thumbnail browser to show off, peruse or organize photos, # design work, or digital art. - ./thunar.nix + ./apps/thunar.nix + + ./apps/redshift.nix ]; environment.systemPackages = with pkgs; [ @@ -21,56 +21,11 @@ pulseSupport = true; nlSupport = true; }) - - xst # st + nice-to-have extensions - (makeDesktopItem { - name = "xst"; - desktopName = "Suckless Terminal"; - genericName = "Default terminal"; - icon = "utilities-terminal"; - exec = "${xst}/bin/xst"; - categories = "Development;System;Utility"; - }) - - (writeScriptBin "st-scratch" '' - #!${stdenv.shell} - SCRID=st-scratch - focused=$(xdotool getactivewindow) - scratch=$(xdotool search --onlyvisible --classname $SCRID) - if [[ -n $scratch ]]; then - if [[ $focused == $scratch ]]; then - xdotool windowkill $scratch - else - xdotool windowactivate $scratch - fi - else - xst -t $SCRID -n $SCRID -c $SCRID \ - -f "$(xrdb -query | grep 'st-scratch\.font' | cut -f2)" \ - -g 100x26 \ - -e $SHELL - fi - '') - (writeScriptBin "st-calc" '' - #!${stdenv.shell} - SCRID=st-calc - scratch=$(xdotool search --onlyvisible --classname $SCRID) - [ -n "$scratch" ] && xdotool windowkill $scratch - xst -t $SCRID -n $SCRID -c $SCRID \ - -f "$(xrdb -query | grep 'st-scratch\.font' | cut -f2)" \ - -g 80x12 \ - -e $SHELL -c qalc - '') - (makeDesktopItem { - name = "st-calc"; - desktopName = "Calculator"; - icon = "calc"; - exec = "st-calc"; - categories = "Development"; - }) ]; services = { xserver = { + enable = true; desktopManager.xterm.enable = false; windowManager.bspwm.enable = true; displayManager.lightdm = { @@ -81,55 +36,19 @@ }; }; }; - - compton = { - enable = true; - backend = "glx"; - vSync = true; - opacityRules = [ - "100:class_g = 'Firefox'" - "100:class_g = 'Vivaldi-stable'" - "100:class_g = 'VirtualBox Machine'" - # Art/image programs where we need fidelity - "100:class_g = 'Gimp'" - "100:class_g = 'Inkscape'" - "100:class_g = 'aseprite'" - "100:class_g = 'krita'" - "100:class_g = 'feh'" - "100:class_g = 'mpv'" - ]; - settings.blur-background-exclude = [ - "window_type = 'dock'" - "window_type = 'desktop'" - "_GTK_FRAME_EXTENTS@:c" - ]; - }; + compton.enable = true; }; # For polybar - fonts.fonts = [ pkgs.siji ]; - my = { - env.PATH = [ ]; + env.PATH = [ ]; home.xdg.configFile = { - "sxhkd".source = ; + "sxhkd".source = ; # link recursively so other modules can link files in their folders "bspwm" = { - source = ; + source = ; recursive = true; }; }; - - env.XAUTHORITY = "/tmp/Xauthority"; - init = '' - [ -e ~/.Xauthority ] && mv -f ~/.Xauthority "$XAUTHORITY" - ''; }; - - system.activationScripts.clearHome = '' - pushd /home/${config.my.username} - rm -rf .compose-cache .nv .pki .dbus .fehbg - [ -s .xsession-errors ] || rm -f .xsession-errors* - popd - ''; } diff --git a/modules/desktop/default.nix b/modules/desktop/default.nix index a48befdd..9adb5e36 100644 --- a/modules/desktop/default.nix +++ b/modules/desktop/default.nix @@ -1,17 +1,115 @@ { config, lib, pkgs, ... }: { - my.packages = with pkgs; [ - libqalculate - xclip - xdotool - mpv # video player - feh # image viewer + services.compton = { + backend = "glx"; + vSync = true; + opacityRules = [ + "100:class_g = 'Firefox'" + "100:class_g = 'Vivaldi-stable'" + "100:class_g = 'VirtualBox Machine'" + # Art/image programs where we need fidelity + "100:class_g = 'Gimp'" + "100:class_g = 'Inkscape'" + "100:class_g = 'aseprite'" + "100:class_g = 'krita'" + "100:class_g = 'feh'" + "100:class_g = 'mpv'" + ]; + settings.blur-background-exclude = [ + "window_type = 'dock'" + "window_type = 'desktop'" + "_GTK_FRAME_EXTENTS@:c" + ]; + }; - # Useful apps - calibre # managing my ebooks - evince # pdf reader + my = { + env.XAUTHORITY = "/tmp/Xauthority"; + init = "[ -e ~/.Xauthority ] && mv -f ~/.Xauthority \"$XAUTHORITY\""; + + packages = with pkgs; [ + libqalculate + xclip + xdotool + mpv # video player + feh # image viewer + + # Useful apps + calibre # managing my ebooks + evince # pdf reader + + xst # st + nice-to-have extensions + (makeDesktopItem { + name = "xst"; + desktopName = "Suckless Terminal"; + genericName = "Default terminal"; + icon = "utilities-terminal"; + exec = "${xst}/bin/xst"; + categories = "Development;System;Utility"; + }) + + (writeScriptBin "st-scratch" '' + #!${stdenv.shell} + SCRID=st-scratch + focused=$(xdotool getactivewindow) + scratch=$(xdotool search --onlyvisible --classname $SCRID) + if [[ -n $scratch ]]; then + if [[ $focused == $scratch ]]; then + xdotool windowkill $scratch + else + xdotool windowactivate $scratch + fi + else + xst -t $SCRID -n $SCRID -c $SCRID \ + -f "$(xrdb -query | grep 'st-scratch\.font' | cut -f2)" \ + -g 100x26 \ + -e $SHELL + fi + '') + (writeScriptBin "st-calc" '' + #!${stdenv.shell} + SCRID=st-calc + scratch=$(xdotool search --onlyvisible --classname $SCRID) + [ -n "$scratch" ] && xdotool windowkill $scratch + xst -t $SCRID -n $SCRID -c $SCRID \ + -f "$(xrdb -query | grep 'st-scratch\.font' | cut -f2)" \ + -g 80x12 \ + -e $SHELL -c qalc + '') + (makeDesktopItem { + name = "st-calc"; + desktopName = "Calculator"; + icon = "calc"; + exec = "st-calc"; + categories = "Development"; + }) + ]; + }; + + fonts.enableFontDir = true; + fonts.enableGhostscriptFonts = true; + fonts.fonts = with pkgs; [ + ubuntu_font_family + dejavu_fonts + fira-code + fira-code-symbols + symbola + noto-fonts + noto-fonts-cjk + font-awesome-ttf + siji ]; + fonts.fontconfig.defaultFonts = { + sansSerif = ["Ubuntu"]; + monospace = ["Fira Code"]; + }; + + system.activationScripts.clearHome = '' + pushd /home/${config.my.username} + rm -rf .compose-cache .nv .pki .dbus .fehbg + [ -s .xsession-errors ] || rm -f .xsession-errors* + popd + ''; sound.enable = true; hardware.pulseaudio.enable = true; @@ -28,38 +126,4 @@ in lib.mkIf config.hardware.pulseaudio.enable "${paConfigFile}/default.pa"; - services = { - xserver.enable = true; - redshift.enable = true; - }; - - # For redshift - location = (if config.time.timeZone == "America/Toronto" then { - latitude = 43.70011; - longitude = -79.4163; - } else if config.time.timeZone == "Europe/Copenhagen" then { - latitude = 55.88; - longitude = 12.5; - } else {}); - - fonts = { - enableFontDir = true; - enableGhostscriptFonts = true; - - fonts = with pkgs; [ - ubuntu_font_family - dejavu_fonts - fira-code - fira-code-symbols - symbola - noto-fonts - noto-fonts-cjk - font-awesome-ttf - ]; - - fontconfig.defaultFonts = { - sansSerif = ["Ubuntu"]; - monospace = ["Fira Code"]; - }; - }; } diff --git a/modules/dev/python.nix b/modules/dev/python.nix index 581dd644..2a3279f6 100644 --- a/modules/dev/python.nix +++ b/modules/dev/python.nix @@ -26,7 +26,7 @@ env.PYTHON_EGG_CACHE = "$XDG_CACHE_HOME/python-eggs"; env.JUPYTER_CONFIG_DIR = "$XDG_CONFIG_HOME/jupyter"; - zsh.rc = lib.readFile ; + zsh.rc = lib.readFile ; alias.py = "python"; alias.py2 = "python2"; diff --git a/modules/dev/zsh.nix b/modules/dev/zsh.nix index 8ca54e4c..6f298297 100644 --- a/modules/dev/zsh.nix +++ b/modules/dev/zsh.nix @@ -9,6 +9,6 @@ { my.packages = with pkgs; [ shellcheck - (callPackage (import {})) + my.zunit ]; } diff --git a/modules/editors/emacs.nix b/modules/editors/emacs.nix index c3fc828b..86bf9e28 100644 --- a/modules/editors/emacs.nix +++ b/modules/editors/emacs.nix @@ -42,7 +42,7 @@ ]; env.PATH = [ "$HOME/.emacs.d/bin" ]; - zsh.rc = lib.readFile ; + zsh.rc = lib.readFile ; # My emacs config is too stateful to manage with nix init = '' diff --git a/modules/graphics.nix b/modules/graphics.nix index 311fde17..42d24a21 100644 --- a/modules/graphics.nix +++ b/modules/graphics.nix @@ -19,7 +19,7 @@ ]; home.xdg.configFile = { - "GIMP/2.10" = { source = ; recursive = true; }; + "GIMP/2.10" = { source = ; recursive = true; }; }; }; } diff --git a/modules/hardware/ergodox.nix b/modules/hardware/ergodox.nix deleted file mode 100644 index c87d225b..00000000 --- a/modules/hardware/ergodox.nix +++ /dev/null @@ -1,6 +0,0 @@ -{ config, lib, pkgs, ... }: - -{ - my.packages = [ pkgs.teensy-loader-cli ]; - my.alias.teensyload = "sudo teensy-loader-cli -w -v --mcu=atmega32u4"; -} diff --git a/modules/hardware/nvidia.nix b/modules/hardware/nvidia.nix deleted file mode 100644 index 28648b82..00000000 --- a/modules/hardware/nvidia.nix +++ /dev/null @@ -1,14 +0,0 @@ -{ config, lib, pkgs, ... }: - -{ - services.xserver.videoDrivers = [ "nvidia" ]; - hardware.opengl.enable = true; - - # Respect XDG conventions, damn it! - environment.systemPackages = with pkgs; [ - (pkgs.writeScriptBin "nvidia-settings" '' - #!${pkgs.stdenv.shell} - exec ${config.boot.kernelPackages.nvidia_x11}/bin/nvidia-settings --config="$XDG_CONFIG_HOME/nvidia/settings" - '') - ]; -} diff --git a/modules/hardware/tablet.nix b/modules/hardware/tablet.nix deleted file mode 100644 index 994f9aa2..00000000 --- a/modules/hardware/tablet.nix +++ /dev/null @@ -1,16 +0,0 @@ -{ config, lib, pkgs, ... }: - -{ - # For my intuos4 pro. Doesn't work for cintiqs. - services.xserver.wacom.enable = true; - - # TODO Move this to udev - # my.init = '' - # # lock tablet to main display - # if xinput list --id-only "Wacom Intuos Pro S Pen stylus" 2>&1 >/dev/null; then - # xinput map-to-output $(xinput list --id-only "Wacom Intuos Pro S Pen stylus") DVI-I-1 - # xinput map-to-output $(xinput list --id-only "Wacom Intuos Pro S Pen eraser") DVI-I-1 - # xinput map-to-output $(xinput list --id-only "Wacom Intuos Pro S Pen cursor") DVI-I-1 - # fi - # ''; -} diff --git a/modules/services/jellyfin.nix b/modules/services/jellyfin.nix index 100c4b71..be27b47f 100644 --- a/modules/services/jellyfin.nix +++ b/modules/services/jellyfin.nix @@ -3,7 +3,7 @@ { config, lib, pkgs, ... }: { - services.jellyfin = { enable = true; }; + services.jellyfin.enable = true; networking.firewall = { allowedTCPPorts = [ 8096 ]; diff --git a/modules/shell/git.nix b/modules/shell/git.nix index 54ac3824..bc1c6fc8 100644 --- a/modules/shell/git.nix +++ b/modules/shell/git.nix @@ -6,11 +6,11 @@ gitAndTools.hub gitAndTools.diff-so-fancy ]; - zsh.rc = lib.readFile ; + zsh.rc = lib.readFile ; # Do recursively, in case git stores files in this folder home.xdg.configFile = { - "git/config".source = ; - "git/ignore".source = ; + "git/config".source = ; + "git/ignore".source = ; }; }; } diff --git a/modules/shell/ncmpcpp.nix b/modules/shell/ncmpcpp.nix index d6f901ba..b7e982b2 100644 --- a/modules/shell/ncmpcpp.nix +++ b/modules/shell/ncmpcpp.nix @@ -13,7 +13,7 @@ my.alias.mpcsp = "mpc searchplay any"; my.home.xdg.configFile = { - "ncmpcpp/config".source = ; - "ncmpcpp/bindings".source = ; + "ncmpcpp/config".source = ; + "ncmpcpp/bindings".source = ; }; } diff --git a/modules/shell/tmux.nix b/modules/shell/tmux.nix index eb647bb8..48d7d80b 100644 --- a/modules/shell/tmux.nix +++ b/modules/shell/tmux.nix @@ -19,8 +19,8 @@ zsh.rc = '' _cache tmuxifier init - - ${lib.readFile } + ${lib.readFile } ''; - home.xdg.configFile."tmux" = { source = ; recursive = true; }; + home.xdg.configFile."tmux" = { source = ; recursive = true; }; }; } diff --git a/modules/shell/zsh.nix b/modules/shell/zsh.nix index b0edc8f7..fae492d8 100644 --- a/modules/shell/zsh.nix +++ b/modules/shell/zsh.nix @@ -1,8 +1,7 @@ -{ config, pkgs, libs, ... }: +# modules/shell/zsh.nix --- ... +{ pkgs, libs, ... }: { - imports = [ ./tmux.nix ]; - my = { packages = with pkgs; [ zsh @@ -19,22 +18,29 @@ env.ZDOTDIR = "$XDG_CONFIG_HOME/zsh"; env.ZSH_CACHE = "$XDG_CACHE_HOME/zsh"; - # Write it recursively so other modules can write files to it - home.xdg.configFile."zsh" = { - source = ; - recursive = true; - }; - alias.exa = "exa --group-directories-first"; alias.l = "exa -1"; alias.ll = "exa -l"; alias.la = "LC_COLLATE=C exa -la"; + + # Write it recursively so other modules can write files to it + home.xdg.configFile."zsh" = { + source = ; + recursive = true; + }; }; programs.zsh = { enable = true; enableCompletion = true; - enableGlobalCompInit = false; # I'll do it myself + # I init completion myself, because enableGlobalCompInit initializes it too + # soon, which means commands initialized later in my config won't get + # completion, and running compinit twice is slow. + enableGlobalCompInit = false; promptInit = ""; }; + + system.userActivationScripts.cleanupZgen = '' + rm -fv $XDG_CACHE_HOME/zsh/* + ''; } diff --git a/modules/themes/aquanaut/default.nix b/modules/themes/aquanaut/default.nix index aa4b5d83..a6777a96 100644 --- a/modules/themes/aquanaut/default.nix +++ b/modules/themes/aquanaut/default.nix @@ -1,6 +1,6 @@ # modules/themes/aquanaut/default.nix --- a sea-blue linux theme -{ config, pkgs, ... }: +{ config, lib, pkgs, ... }: { imports = [ ../. ]; # Load framework for themes @@ -32,6 +32,7 @@ nordic paper-icon-theme # for rofi ]; + my.zsh.rc = lib.readFile ./zsh/prompt.zsh; my.home.xdg.configFile = { "bspwm/rc.d/polybar".source = ./polybar/run.sh; "bspwm/rc.d/theme".source = ./bspwmrc; @@ -40,7 +41,6 @@ "rofi/theme" = { source = ./rofi; recursive = true; }; "tmux/theme".source = ./tmux.conf; "xtheme/90-theme".source = ./Xresources; - "zsh/prompt.zsh".source = ./zsh/prompt.zsh; # GTK "gtk-3.0/settings.ini".text = '' [Settings] diff --git a/modules/themes/default.nix b/modules/themes/default.nix index b715bbd8..439adb39 100644 --- a/modules/themes/default.nix +++ b/modules/themes/default.nix @@ -1,17 +1,13 @@ -{ config, lib, pkgs, ... }: +# modules/themes/default.nix +{ config, ... }: { - imports = [ ]; + imports = [ ./options.nix ]; # Try really hard to get QT to respect my GTK theme. - my.env = { - GTK_DATA_PREFIX = [ "${config.system.path}" ]; - QT_QPA_PLATFORMTHEME = "gtk2"; - }; - qt5 = { - style = "gtk2"; - platformTheme = "gtk2"; - }; + my.env.GTK_DATA_PREFIX = [ "${config.system.path}" ]; + my.env.QT_QPA_PLATFORMTHEME = "gtk2"; + qt5 = { style = "gtk2"; platformTheme = "gtk2"; }; services.xserver.displayManager.sessionCommands = '' export GTK2_RC_FILES="$XDG_CONFIG_HOME/gtk-2.0/gtkrc" source "$XDG_CONFIG_HOME"/xsession/*.sh diff --git a/options/theme.nix b/modules/themes/options.nix similarity index 81% rename from options/theme.nix rename to modules/themes/options.nix index 36228f9a..64a7c43a 100644 --- a/options/theme.nix +++ b/modules/themes/options.nix @@ -1,19 +1,17 @@ -{ config, options, lib, pkgs, ... }: +# modules/themes/options.nix +{ options, config, lib, pkgs, ... }: with lib; { options.theme = { wallpaper = mkOption { type = with types; nullOr (either str path); - default = null; - description = "The wallpaper to use"; }; # TODO Colors? }; config = { - # Set up wallpaper and blur/darken it for lock/login screen my.home.home.file.".background-image".source = config.theme.wallpaper; services.xserver.displayManager.lightdm.background = let blurredWallpaper = diff --git a/options.nix b/options.nix new file mode 100644 index 00000000..8413a75e --- /dev/null +++ b/options.nix @@ -0,0 +1,90 @@ +{ config, options, lib, ... }: + +with lib; +let mkOptionStr = value: mkOption + { type = types.str; + default = value; }; +in +{ + imports = [ ]; + + + ## Personal settings + options.my.username = mkOptionStr "hlissner"; + options.my.email = mkOptionStr "henrik@lissner.net"; + + + ## Convenience aliases + options.my.home = mkOption + { type = options.home-manager.users.type.functor.wrapped; }; + config.home-manager.users.${config.my.username} = mkAliasDefinitions options.my.home; + + options.my.user = mkOption { type = types.submodule; }; + config.users.users.${config.my.username} = mkAliasDefinitions options.my.user; + + options.my.packages = mkOption + { type = types.listOf types.package; + description = "The set of packages to appear in the user environment."; }; + config.my.user.packages = config.my.packages; + + + ## Shell/Environment + options.my.env = mkOption { + type = with types; attrsOf (either (either str path) (listOf (either str path))); + apply = mapAttrs + (n: v: if isList v + then concatMapStringsSep ":" (x: toString x) v + else (toString v)); + }; + options.my.init = mkOption { + type = types.lines; + description = '' + An init script that runs after the environment has been rebuilt or + booted. Anything done here should be idempotent and inexpensive. + ''; + }; + config.environment.extraInit = + let exportLines = mapAttrsToList (n: v: "export ${n}=\"${v}\"") config.my.env; + in '' + ${concatStringsSep "\n" exportLines} + ${config.my.init} + ''; + + options.my.alias = mkOption + { type = with types; nullOr (attrsOf (nullOr (either str path))); }; + options.my.zsh = { + rc = mkOption { + type = types.lines; + default = ""; + description = '' + Zsh lines to be written to $XDG_CONFIG_HOME/zsh/extra.zshrc and + sourced by $XDG_CONFIG_HOME/zsh/.zshrc + ''; + }; + env = mkOption { + type = types.lines; + default = ""; + description = '' + Zsh lines to be written to $XDG_CONFIG_HOME/zsh/extra.zshenv and + sourced by $XDG_CONFIG_HOME/zsh/.zshenv + ''; + }; + }; + + # I avoid programs.zsh.*Init variables because they initialize too soon. My + # zsh config is particular about load order. + config.my.home.xdg.configFile."zsh/extra.zshrc".text = + let aliasLines = mapAttrsToList (n: v: "alias ${n}=\"${v}\"") config.my.alias; + in '' + # This file is autogenerated, do not edit it! + ${concatStringsSep "\n" aliasLines} + ${config.my.zsh.rc} + ''; + config.my.home.xdg.configFile."zsh/extra.zshenv".text = '' + # This file is autogenerated, do not edit it! + ${config.my.zsh.env}; + ''; + + ## PATH should always start with its old value + config.my.env.PATH = [ "$PATH" ]; +} diff --git a/options/my.nix b/options/my.nix deleted file mode 100644 index 80c06d3e..00000000 --- a/options/my.nix +++ /dev/null @@ -1,108 +0,0 @@ -{ config, options, lib, utils, pkgs, ... }: - -with lib; -{ - imports = [ ]; - - options.my = { - username = mkOption { - type = types.str; - default = "hlissner"; - }; - - email = mkOption { - type = types.str; - default = "henrik@lissner.net"; - }; - - home = mkOption { - type = options.home-manager.users.type.functor.wrapped; - default = {}; - description = "A convenience alias for home-manager.users.{my.username}."; - }; - - user = mkOption { - type = types.submodule; - default = {}; - description = "A convenience alias for users.users.{my.username}."; - }; - - env = mkOption { - type = with types; attrsOf (either (either str path) (listOf (either str path))); - default = {}; - description = '' - An map of environment variables that are set later than - environment.variables or environment.sessionVariables. This is insurance - that XDG variables (and other essentials) are initialized by the time - these are set. - ''; - apply = mapAttrs - (n: v: if isList v - then concatMapStringsSep ":" (x: toString x) v - else (toString v)); - }; - - alias = mkOption { - type = with types; nullOr (attrsOf (nullOr (either str path))); - default = {}; - description = "Shell-independent aliases for interactive shells."; - }; - - packages = mkOption { - type = types.listOf types.package; - default = []; - description = "The set of packages to appear in the user environment."; - }; - - init = mkOption { - type = types.lines; - default = ""; - description = '' - An init script that runs after the environment has been rebuilt or - booted. Anything done here should be idempotent and inexpensive. - ''; - }; - - zsh = { - rc = mkOption { - type = types.lines; - default = ""; - description = '' - Zsh lines to be written to $XDG_CONFIG_HOME/zsh/extra.zshrc and - sourced by $XDG_CONFIG_HOME/zsh/.zshrc - ''; - }; - env = mkOption { - type = types.lines; - default = ""; - description = '' - Zsh lines to be written to $XDG_CONFIG_HOME/zsh/extra.zshenv and - sourced by $XDG_CONFIG_HOME/zsh/.zshenv - ''; - }; - }; - }; - - config = { - users.users.${config.my.username} = mkAliasDefinitions options.my.user; - home-manager.users.${config.my.username} = mkAliasDefinitions options.my.home; - - my.user.packages = config.my.packages; - my.env.PATH = [ "$PATH" ]; - - environment.extraInit = - let exportLines = mapAttrsToList (n: v: "export ${n}=\"${v}\"") config.my.env; - in '' - ${concatStringsSep "\n" exportLines} - ${config.my.init} - ''; - - my.home.xdg.configFile."zsh/extra.zshrc".text = - let aliasLines = mapAttrsToList (n: v: "alias ${n}=\"${v}\"") config.my.alias; - in '' - ${concatStringsSep "\n" aliasLines} - ${config.my.zsh.rc} - ''; - my.home.xdg.configFile."zsh/extra.zshenv".text = config.my.zsh.env; - }; -} diff --git a/overlays.nix b/overlays.nix new file mode 100644 index 00000000..314dd2cd --- /dev/null +++ b/overlays.nix @@ -0,0 +1,24 @@ +[ + (self: super: with super; { + my = { + linode-cli = (callPackage ./packages/linode-cli.nix {}); + ripcord = (callPackage ./packages/ripcord.nix {}); + zunit = (callPackage ./packages/zunit.nix {}); + cached-nix-shell = + (callPackage + (builtins.fetchTarball + https://github.com/xzfc/cached-nix-shell/archive/master.tar.gz) {}); + }; + + nur = import (builtins.fetchTarball "https://github.com/nix-community/NUR/archive/master.tar.gz") { + inherit super; + }; + + # Occasionally, "stable" packages are broken or incomplete, so access to the + # bleeding edge is necessary, as a last resort. + unstable = import { inherit config; }; + }) + + # emacsGit + (import (builtins.fetchTarball https://github.com/nix-community/emacs-overlay/archive/master.tar.gz)) +]