/nixos-config

My nixos configurations

Primary LanguageNix

Nixos Configuration

Welcome to my nixos configuration!. This is a configuration for a single laptop setup.

Flake

So I use flake to manage my configs.

{
  description = "A7R7's NixOS Flake";
  nixConfig = {
    <<nixConfig>>
  };
  inputs = {
    <<inputs>>
  };
  outputs =
    <<outputs>>
}

nixConfig

experimental-features = [ "nix-command" "flakes" ];
# nix community's cache server
extra-substituters = [
  "https://nix-community.cachix.org"
  "https://nixpkgs-wayland.cachix.org"
  "https://anyrun.cachix.org"
  "https://cuda-maintainers.cachix.org"
  "https://hyprland.cachix.org"
];
extra-trusted-public-keys = [
  "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs="
  "nixpkgs-wayland.cachix.org-1:3lwxaILxMRkVhehr5StQprHdEo4IrE8sRho9R9HOLYA="
  "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="
  "anyrun.cachix.org-1:pqBobmOjI7nKlsUMV25u9QHa9btJK65/C8vnO3p346s="
  "cuda-maintainers.cachix.org-1:0dq3bujKpuEPMCX6U4WylrUDZ9JyUG0VpVZa7CNfq5E="
  "hyprland.cachix.org-1:a7pgxzMz7+chwVL3/pzj6jIBMioiJM7ypFP8PwtkuGc="
];

Inputs

## nixpkgs
nixpkgs-2305.url = "github:nixos/nixpkgs/nixos-23.05";
nixpkgs-2311.url = "github:nixos/nixpkgs/nixos-23.11";
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
nixpkgs-wayland.url = "github:nix-community/nixpkgs-wayland";
home-manager = {
  url = "github:nix-community/home-manager";
  inputs.nixpkgs.follows = "nixpkgs";
};

utils.url = "github:gytis-ivaskevicius/flake-utils-plus";
nur.url = "github:nix-community/NUR";
mynur.url = "github:A7R7/nur-packages";
# mynur.url = "git+file:./?dir=./nurpkgs";
# mynur.url = "./nurpkgs";
# hyprland wm
hyprland.url = "github:hyprwm/Hyprland";
pyprland.url = "github:A7R7/pyprland";
ags.url = "github:Aylur/ags";
musnix.url = "github:musnix/musnix";
pip2nix.url = "github:nix-community/pip2nix";
emacs.url = "github:nix-community/emacs-overlay";
anyrun.url = "github:Kirottu/anyrun";
anyrun.inputs.nixpkgs.follows = "nixpkgs";
nbfc.url = "github:nbfc-linux/nbfc-linux";
nbfc.inputs.nixpkgs.follows = "nixpkgs";

Outputs

inputs@{
  self,
  nixpkgs,
  home-manager,
  ... }:
let
  username = "aaron";
  system = "x86_64-linux";
  pkgs = import nixpkgs {
    inherit system;
    config = {
      allowUnfree = true;
      cudaSupport = true;
      cudaVersion = "12";
    };
    overlays = with inputs; [
      nur.overlay
      mynur.overlay
      emacs.overlay
      (final: prev: { v2311 = import inputs.nixpkgs-2311 {
          inherit system;
          config.allowUnfree = true;
      };})
    ];
  };
in
  {
  nixosConfigurations = {
    Omen16 = nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      specialArgs = { inherit inputs username system pkgs; };
      modules = [ ./host/configuration.nix ./host/omen16.nix];
    };
  };
	homeConfigurations = {
    aaron = home-manager.lib.homeManagerConfiguration {
      inherit pkgs;
      extraSpecialArgs = { inherit inputs username pkgs; };
      modules = [ ./home/home.nix ];
    };
  };
};

Host

{ config, pkgs, lib, inputs, username, system, ... }:
{
  imports =
    [
      /etc/nixos/hardware-configuration.nix
      inputs.musnix.nixosModules.musnix
    ];
  <<host-config>>
}

Nix

system.stateVersion = "23.11";
nixpkgs.config.allowUnfree = true;
nix = {
  # This will add each flake input as a registry
  # To make nix3 commands consistent with your flake
  registry = lib.mapAttrs (_: value: { flake = value; }) inputs;

  # This will additionally add your inputs to the system's legacy channels
  # Making legacy nix commands consistent as well, awesome!
  nixPath = lib.mapAttrsToList (key: value: "${key}=${value.to.path}") config.nix.registry;

  settings = {
    experimental-features = "nix-command flakes";
    auto-optimise-store = true;
    trusted-users = [ "${username}" ];
  };
};

Boot

/etc/nixos/hardware-configuration.nix

boot = {
  loader = {
    # systemd-boot.enable = true;
    grub = {
      enable = true;
      theme = pkgs.mynur.xenlism-grub-4k-nixos;
      splashMode = "normal";
      efiSupport = true;
      useOSProber = true;
    };
    efi.canTouchEfiVariables = true;
    efi.efiSysMountPoint = "/boot";
    timeout = 10;
  };
};

Network & hostname

networking = {
  networkmanager.enable = true;
};

Sound

musnix.enable = true;
sound.enable = false; # sound.enable is only meant for ALSA-based configurations
hardware.pulseaudio.enable = false;
hardware.bluetooth.enable = true;
security.rtkit.enable = true;
services. pipewire = {
  enable = true;
  alsa.enable = true;
  alsa.support32Bit = true;
  pulse.enable = true;
  jack.enable = true;
};

Locale

time.timeZone = "Asia/Shanghai";
i18n = {
  defaultLocale = "en_US.UTF-8";
  supportedLocales = [
    "en_US.UTF-8/UTF-8"
    "zh_CN.UTF-8/UTF-8"
  ];
};
console = {
  font = "Lat2-Terminus16";
  useXkbConfig = true; # use xkbOptions in tty.
};

User

# Define a user account. Don't forget to set a password with ‘passwd’.
users.users.${username} = {
  isNormalUser = true;
  extraGroups = [ "wheel" "networkmanager" "libvirtd" "adbusers" "audio"];
  # shell = pkgs.elvish;
};

Pkgs

environment.systemPackages = with pkgs; [
  vim neovim
  wget
  curl
  git
  stow
  man
  efibootmgr
  gnumake
  killall
  home-manager
  dash elvish fish nushell tcsh xonsh zsh
  sddm-chili-theme
  hicolor-icon-theme
  # inputs.nbfc.defaultPackage.${system}
];

Shells

Shells. Yeah I’d like to try different shells.

environment.shells = with pkgs; [
  dash elvish fish nushell tcsh xonsh zsh
];

This adds ~~/.local/bin~ to PATH.

environment.localBinInPath = true;

Virtualisation

virtualisation = {
  podman.enable = true;
  libvirtd.enable = true;
  waydroid.enable = true;
  virtualbox.host.enable = true;
  # virtualbox.host.enableExtensionPack = true;
  virtualbox.guest.enable = true;
  virtualbox.guest.x11 = true;
  vmware.host.enable = true;
  vmware.guest.enable = true;
};
users.extraGroups.vboxusers.members = [ "user-with-access-to-virtualbox" ];

Programs

Shell

programs.bash = {
  interactiveShellInit = ''
    if [[ $(${pkgs.procps}/bin/ps --no-header --pid=$PPID --format=comm) != "fish" && -z ''${BASH_EXECUTION_STRING} ]]
    then
      shopt -q login_shell && LOGIN_OPTION='--login' || LOGIN_OPTION=""
      exec ${pkgs.fish}/bin/fish $LOGIN_OPTION
    fi
  ''; # launches fish unless the parent process is already fish
};

Window managers

programs.hyprland = {
  enable = true;
  xwayland.enable = true;
  package = inputs.hyprland.packages.${pkgs.system}.hyprland;
  # enableNvidiaPatches = false; # deprecated
};
programs.wayfire = {
  enable = true;
  package = pkgs.mynur.wayfire;
  plugins = (with pkgs.wayfirePlugins; [
    wcm
    wf-shell
    wayfire-plugins-extra
  ]) ++  [
    pkgs.mynur.swayfire
  ];
};
environment.sessionVariables.WAYFIRE_CONFIG_FILE = "$HOME/.config/wayfire/wayfire.ini";

Misc

programs.steam = {
  enable = true;
  remotePlay.openFirewall = true; # Open ports in the firewall for Steam Remote Play
  dedicatedServer.openFirewall = true; # Open ports in the firewall for Source Dedicated Server
};
xdg.portal = {
  enable = true;
  wlr.enable = true;
  # extraPortals = [ pkgs.xdg-desktop-portal-gtk ];
};
programs.adb.enable = true;
programs.dconf.enable = true;

Fonts

fonts.packages = with pkgs; [
  noto-fonts
  noto-fonts-cjk
  symbola
  roboto roboto-serif
  sarasa-gothic
];
fonts.fontconfig = {
  enable = true;
  includeUserConf = true;
  allowBitmaps = false;
  hinting.enable = false;
};

Services

Xserver

services.xserver.enable = true;
services.xserver.excludePackages = [ pkgs.xterm ];
services.xserver.xkb.layout = "us";
services.xserver.xkb.options = "caps:escape";
# services.xserver.displayManager.gdm.enable = true;
services.xserver.displayManager.sddm = {
  enable = true;
  theme = "chili";
};
# displayManager.lightdm.enable = true;
# displayManager.lightdm.greeters.slick.enable = true;
# desktopManager.gnome.enable = true;

GNOME

services.gnome = {
  evolution-data-server.enable = true;
  glib-networking.enable = true;
  gnome-keyring.enable = true;
  gnome-online-accounts.enable = true;
  at-spi2-core.enable = true; # avoid the warning "The name org.a11y.Bus was not provided by any .service files"
};

DAE

services.dae = {
  enable = true;
  configFile = "/home/${username}/.config/dae/config.dae";
};

Syncthing

Syncthing is a continuouts file synchronization program using UPnP, which synchronize files WITHOUT centralized services.

services.syncthing = {
  enable = true;
  openDefaultPorts = true; # 22000/TCP and 22000/UDP
  dataDir = "/home/${username}";
  configDir = "/home/${username}/.config/syncthing";
  user = "${username}";
  group = "users";
  # guiAdd.0:8384"; # To be able to access the web GUI
};

Blueman

services.blueman.enable = true;

Print

services.printing.enable = true;
services.printing.drivers = [ pkgs.hplipWithPlugin ];
services.avahi = {
  enable = true;
  nssmdns4 = true;
  openFirewall = true;
};

Ollama

services.ollama.enable = true;

Misc

services.flatpak.enable = true;
services.openssh.enable = true;
# userspace virtual filesystem
services.gvfs.enable = true;
# an automatic device mounting daemon
services.devmon.enable = true;
# allows applications to query and manipulate storage devices.
services.udisks2.enable = true;
# a DBus service for accessing the list of user accounts and information attached to those accounts.
# services.accounts-daemon.enable = true;
services.ratbagd.enable = true; # configuring gamming mouse

Power management

# a DBus service that provides power management support to applications.
services.upower.enable = true;
services.tlp = {
  enable = true;
  settings = {
    CPU_SCALING_GOVERNOR_ON_AC = "performance";
    CPU_SCALING_GOVERNOR_ON_BAT = "powersave";

    CPU_ENERGY_PERF_POLICY_ON_BAT = "power";
    CPU_ENERGY_PERF_POLICY_ON_AC = "performance";

    CPU_MIN_PERF_ON_AC = 0;
    CPU_MAX_PERF_ON_AC = 100;
    CPU_MIN_PERF_ON_BAT = 0;
    CPU_MAX_PERF_ON_BAT = 20;

    #Optional helps save long term battery health
    START_CHARGE_THRESH_BAT0 = 40; # 40 and bellow it starts to charge
    STOP_CHARGE_THRESH_BAT0 = 80; # 80 and above it stops charging
  };
};

Security

Polkit is used for controlling system-wide privileges. It provides an organized way for non-privileged processes to communicate with privileged ones, especially for those GUI applications.

security.polkit.enable = true;
# start polkit on login by creating a systemd user service

Home

Becareful that packages installed by nix profile install can conflict with packages defined here! Therefore, it is recommended to clear nix profile list before home-manager switch.

Config

{ config, pkgs, inputs, ... }:
let
  username = "aaron";
  homeDirectory = "/home/aaron";
in
{
  imports = [
    ./packages.nix
  ];
  <<hm-config>>
}

Home

home = {
  username = username;
  homeDirectory = homeDirectory;
  stateVersion = "23.11";
  sessionVariables = {
    QT_XCB_GL_INTEGRATION = "none"; # kde-connect
    NIXPKGS_ALLOW_UNFREE = "1";
    LD_LIBRARY_PATH="${pkgs.linuxPackages.nvidia_x11}/lib:$LD_LIBRARY_PATH";
    # SHELL = "${pkgs.zsh}/bin/elvish";
  };
  sessionPath = [
    "$HOME/.local/bin"
  ];
};
programs.home-manager.enable = true;

nixpkgs = {
  config = {
    allowUnfree = true;
    # Workaround for https://github.com/nix-community/home-manager/issues/2942
    allowUnfreePredicate = (_: true);
    cudaSupport = true;
    cudaVersion = "12";
    permittedInsecurePackages = [
      "electron-11.5.0"
    ];
  };
};

Input method

i18n.inputMethod = {
  enabled = "fcitx5";
  fcitx5 = {
    addons = with pkgs; [
      fcitx5-gtk
      fcitx5-rime
      fcitx5-lua
      fcitx5-chinese-addons
      librime
    ];
  };
};

Font

fonts.fontconfig.enable = true;
home.packages = with pkgs; [
   nerdfonts
   noto-fonts-monochrome-emoji
   noto-fonts-emoji
   noto-fonts-extra
   source-han-mono
   source-han-sans
   source-han-serif
   source-han-serif-vf-ttf

   commit-mono
   monaspace
   # mynur.symbols-nerd-font
   # mynur.ibm-plex-nerd-font
   ibm-plex

   corefonts
   vistafonts
   mynur.sarasa-gothic-nerd-font
   fontforge-gtk

   lxgw-wenkai
   lxgw-neoxihei
];

GTK

gtk.enable = true;
# gtk.theme = {
#   name = "Fluent";
#   package = pkgs.fluent-gtk-theme.override {
#     tweaks = [ "blur" ];
#   };
# };
gtk.iconTheme = {
  name = "kora";
  package = pkgs.kora-icon-theme;
};
# gtk.cursorTheme = {
#   package = pkgs.whitesur-cursors;
#   name = "whitesur-cursors";
#   size = 32;
# };
home.pointerCursor = {
  package = pkgs.whitesur-cursors;
  name = "WhiteSur-cursors";
  size = 32;
  x11.enable = true;
  gtk.enable = true;
};
xresources.properties = {
  "Xcursor.size" = 32;
  "Xft.dpi" = 172;
};
gtk.gtk3.bookmarks = [
  "file://${homeDirectory}/Documents"
  "file://${homeDirectory}/Music"
  "file://${homeDirectory}/Pictures"
  "file://${homeDirectory}/Videos"
  "file://${homeDirectory}/Downloads"
  "file://${homeDirectory}/Desktop"
  "file://${homeDirectory}/Projects"
  "file://${homeDirectory}/.config Config"
  "file://${homeDirectory}/.local/share Local"
];

Programs

Bash is the default login shell. A login shell should be POSIX compliant, or it can cause errors.

programs.bash = {
  enable = true; # this is needed for home.sessionVariables to work
};
programs.vscode = {
  enable = true;
  package = pkgs.vscode.fhs;
};
programs.emacs = {
  enable = true;
  package = pkgs.emacs-unstable-pgtk;
};
programs.obs-studio = {
  enable = true;
  plugins = with pkgs.obs-studio-plugins; [
    wlrobs
    # obs-backgroundremoval
    obs-pipewire-audio-capture
  ];
};
programs.direnv = {
  enable = true;
  enableBashIntegration = true; # see note on other shells below
      nix-direnv.enable = true;
};

Services

services.syncthing = {
  enable = true;
  tray = {enable = true;};
};
services.emacs.enable = true;
services.blueman-applet.enable = true;

Packages

{ inputs, pkgs, ... }:
{
  home.packages = (with pkgs; [
    <<hm-packages>>
  ]);
}

Development

Text-editor

helix
lapce  # a rust powered editor
libreoffice
wpsoffice
neovide
marktext
# nur.repos.lschuermann.vivado-2020_1

Languages

These tools can be seen as runtimes, for non serious usage and quick testing. To seriously do development on nixos I have to write derivations.

gcc ccache cmake clang-tools bear
(python311.withPackages(ps: with ps; [
  # pytorch-bin torchvision-bin
  #(torchvision.override {torch = pytorch-bin; })
  # required by lsp-bridge, holo-layer, and blink search
  epc orjson sexpdata six paramiko rapidfuzz
  pynput inflect pyqt6 pyqt6-sip
  python-pam requests
  numpy pandas toolz
  scipy cython
  # pyperclip
  pillow
  # imageio imageio-ffmpeg
  # grad-cam
  # opencv4
  # onnxruntime
  jupyter ipython matplotlib
  # pip pipdeptree
  # mynur.pix2tex
  # mynur.pix2text
  nvidia-ml-py
]))

poetry
# octave
nodejs
gjs
go
bun
sassc
typescript
meson
ninja
# eslint
maven
pkg-config
rnix-lsp # WIP Language Server for Nix
texliveFull
plantuml # draw plots

Lang-servers

pyright
javascript-typescript-langserver
rust-analyzer
mynur.jdtls
vscode-langservers-extracted

Database

sqlite
dbeaver

Nix

These are tools for packaging using nix.

niv
nix-universal-prefetch
inputs.pip2nix.defaultPackage.${system}
nix-your-shell
any-nix-shell
nix-output-monitor
nix-du
nixfmt
nixpkgs-fmt
manix # fast nix doc searcher

Others

doxygen
doxygen_gui
mynur.logisim-ita
uncrustify
patchelf

Runtime

gtk-engine-murrine
gnome-themes-extra
mynur.tdlib # for building telegrame clients

Cmdline

Emulator

kitty
alacritty
wezterm
blackbox-terminal
cool-retro-term

Tools

gitstatus # 10x faster than git status
gitoxide  # rust git client
gitui     # magit like git client
cloc      # compute lines
carapace  # completion backend
starship  # custom prompt
lf
thefuck   #
bat       # rust cat
eza       # rust ls

ranger
nnn       # cmdline file explorer
joshuto   # rust ranger
yazi      # faster rust ranger

file      # tell file type
oterm     # cmdline ollama client
fd
ripgrep
fzf
socat
jq
yq-go
acpi
inotify-tools
ffmpeg
libnotify
zoxide
autoconf
tree
ghostscript
_7zz
lazygit
hugo
pandoc
gh
zinit
just

Toys

# ueberzugpp # allow showing child window in terminal
pipes-rs
tty-clock
cava
cmatrix
fastfetch
uniscribe # describe unicodes
unipicker # pick unicodes
nerdfix # find nerd font icons
dwt1-shell-color-scripts # some colorful outputs

Multimedia

Audio-production

# daw
ardour
# synthesizer-plugin
zyn-fusion
surge
geonkick
distrho
# sampler
avldrums-lv2
drumkv1
drumgizmo
# effect processor
calf
lsp-plugins

# Qt-based Graph/Patchbay for PipeWire
qpwgraph

Music Player

tauon
lollypop
cider      # Apple Music
spotify

Image

feh
# gimp-with-plugins
inkscape
imagemagick    # editing and manipulating digital images

Videos

# kdenlive
vlc
mpv

PDF

zathura

Network

Browser

firefox
floorp
chromium
(vivaldi.override {
  proprietaryCodecs = true;
  enableWidevine = true;
#   commandLineArgs = "--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations --enable-wayland-ime";
})
# vivaldi
(mynur.thorium-browser.override {
  commandLineArgs = "--enable-features=WaylandWindowDecorations --gtk-version=4";
})

Message

qq
discord
telegram-desktop
element-desktop
thunderbird
weechat # IRC
nur.repos.linyinfeng.wemeet
# nur.repos.xddxdd.dingtalk

VPN

mynur.clash-verge-rev

others

# nur.repos.xddxdd.baidunetdisk

Downloader

tidal-dl
youtube-dl

Gaming

prismlauncher
glfw-wayland-minecraft
zulu21
steam-tui
steamcmd
steam
gamescope

Desktop

Essentials

kanshi         # manage monitor position on wayland
wlsunset       # screen color temperature mnger
swayidle       # idle mnger
# swaylock       # lock mnger
wlogout        # logout mnger
swaynotificationcenter # not only show notifications but also have a drawer
rofi-wayland-unwrapped # app launcher
inputs.anyrun.packages.${system}.anyrun-with-all-plugins # app launcher

eww            # bar
waybar         # bar

pavucontrol    # sound control
brightnessctl  # brightness control
grim           # wl raw screenshot
grimblast      # wrapper around grim
slurp          # reigon selection (outputs reigon coordinates)
swappy         # Wayland native snapshot editing tool
wf-recorder    # screen recording tool

hyprpaper      # hyprland wallpaper utility
swww           # dynamic wallpaper
swayimg        # wallpaper utility from sway
mpvpaper       # use mpv as wallpaper

wl-clipboard-rs # wayland clipboard
wev            # wayland event viewer
# gnome stuffs
gnome.nautilus # gnome's file manager
gnome.gnome-tweaks # gnome's file manager
gnome.gnome-characters
gnome.gnome-font-viewer # view system fonts
gnome-themes-extra
gtk-engine-murrine
cinnamon.nemo  # cinnamon's file manager
doublecmd
peazip         # achiever
nsxiv          # the best image viewer

gnome.adwaita-icon-theme

# hyprkeys       # keybind retrieval utility
# hyprnome       # gnome like workspace switch

# hyprshade      # screen color filters
# wl-gammactl    # set contrast, brightness and gamma on wl

v2311.hyprpicker     # wlroots color picker
wayshot        # screenshots tool


# bar and shell in gjs
inputs.ags.packages.${system}.default

# hyprland plugin set in python
inputs.pyprland.packages.${system}.default

System-tools

gparted        # disk partition manager
gnome.gnome-disk-utility # view disk info
fsearch        # search files in disk
lshw
solaar         # connect with logitech devices
iotop
btop
logiops        # Unofficial userspace driver for HID++ Logitech devices
powertop       # Analyze power consumption on Intel-based laptops
mission-center
filelight      # inspecting disk usage statistics
xorg.xhost          # launch gui with sudo in cmdline
networkmanagerapplet # network manager, gtk frontend
wlr-randr      # wlroots screen manager
pciutils       # portable access to PCI bus configuration registers
piper          # GTK frontend for ratbagd mouse config daemon
lm_sensors     # reading hardware sensors

Build

sudo nixos-rebuild switch --flake . --impure
home-manager switch --flake .
nix flake update
sudo nix profile wipe-history --profile /nix/var/nix/profiles/system  --older-than 7d
sudo nix store gc --debug