From 71e36690a3aadd56adb8ca27b6d074177ce56b57 Mon Sep 17 00:00:00 2001 From: janis Date: Tue, 18 Nov 2025 16:54:18 +0100 Subject: [PATCH] split home and user up to allow for modular configuration --- flake.nix | 39 +++++++++++++++--- home/common.nix | 60 ++++++++++++++++++++++++++++ home/default.nix | 92 ++----------------------------------------- home/desktop-apps.nix | 27 +++++++++++++ home/sway.nix | 9 +++-- home/wsl.nix | 11 ++++++ home/xdg.nix | 14 +++++++ system/core.nix | 70 ++++++++++++++++++++++++++++++++ system/default.nix | 71 +-------------------------------- user/common.nix | 27 +++++++++++++ user/default.nix | 39 +++--------------- user/greetd.nix | 11 ++++++ user/wsl.nix | 13 ++++++ 13 files changed, 282 insertions(+), 201 deletions(-) create mode 100644 home/common.nix create mode 100644 home/desktop-apps.nix create mode 100644 home/wsl.nix create mode 100644 home/xdg.nix create mode 100644 system/core.nix create mode 100644 user/common.nix create mode 100644 user/greetd.nix create mode 100644 user/wsl.nix diff --git a/flake.nix b/flake.nix index edea97e..f292c0a 100644 --- a/flake.nix +++ b/flake.nix @@ -2,6 +2,7 @@ inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05"; nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable"; + nixos-wsl.url = "github:nix-community/NixOS-WSL/main"; home-manager = { url = "github:nix-community/home-manager"; inputs.nixpkgs.follows = "nixpkgs"; @@ -19,7 +20,7 @@ duralumin.url = "git+https://git.nirgendwo.xyz/janis/duralumin.git"; }; - outputs = inputs @ { self, disko, nixpkgs, nixpkgs-unstable, home-manager, duralumin, emacs-overlay, ... }: + outputs = inputs @ { self, disko, nixpkgs, nixos-wsl, nixpkgs-unstable, home-manager, duralumin, emacs-overlay, ... }: let system = "x86_64-linux"; overlay-unstable = final: prev: { @@ -30,12 +31,12 @@ }; in rec { - mkSystem = {host, ...}: nixpkgs.lib.nixosSystem { + mkSystem = {host, extra-modules ? [], ...}: nixpkgs.lib.nixosSystem { inherit system; modules = [ - ./configuration.nix - ./options.nix + ./programs + ./options.nix ./pkgs host home-manager.nixosModules.home-manager @@ -48,7 +49,7 @@ inherit inputs; }; } - ]; + ] ++ extra-modules; specialArgs = { inherit inputs home-manager; @@ -74,9 +75,37 @@ }; laptop = mkSystem { host = ./hosts/laptop; + extra-modules = [ + ./user + ./system + ]; }; + desktop = mkSystem { host = ./hosts/desktop; + extra-modules = [ + ./user + ./system + ]; + }; + + wsl = mkSystem { + host = ./hosts/wsl.nix; + extra-modules = [ + nixos-wsl.nixosModules.default + ./user/wsl.nix + { + wsl.enable = true; + + # wsl wants a subset of the system configuration, sans power, wireless, boot + imports = [ + ./system/core.nix + ./system/networking.nix + ./system/fonts.nix + ./system/virtualisation.nix + ]; + } + ]; }; }; }; diff --git a/home/common.nix b/home/common.nix new file mode 100644 index 0000000..3f0203d --- /dev/null +++ b/home/common.nix @@ -0,0 +1,60 @@ +{pkgs, ...}: +let + user = import ../data/user.nix {}; +in { + + # Manage NixOS configurations + programs.nh = { + enable = true; + }; + + # Direnv for project-specific environment variables + programs.direnv = { + enable = true; + nix-direnv.enable = true; + enableZshIntegration = true; + }; + + # Font configuration + fonts.fontconfig.enable = true; + + home = { + stateVersion = "25.05"; + homeDirectory = "/home/${user.username}"; + username = user.username; + + shell.enableZshIntegration = true; + + sessionVariables = { + SSH_AUTH_SOCK = "/run/user/1000/ssh-agent"; + EDITOR = "nvim"; + VISUAL = "nvim"; + GTK_THEME = "Breeze-Dark"; + NIXOS_OZONE_WL = "1"; + }; + + packages = with pkgs; [ + # Add your global packages here + duralumin + duralumin-keygen + ranger + neovim + bottom + git + wget + curl + tree + htop + ripgrep + killall + xdg-utils + file + gh + + # for running wayland apps over ssh + waypipe + + screenshot + ]; + }; +} diff --git a/home/default.nix b/home/default.nix index 6dd2109..7b8f664 100644 --- a/home/default.nix +++ b/home/default.nix @@ -1,9 +1,8 @@ -{pkgs, ...}: -let - user = import ../data/user.nix {}; -in { +{...}: { imports = [ ./alacritty.nix + ./common.nix + ./desktop-apps.nix ./development ./emacs.nix ./firefox.nix @@ -20,89 +19,4 @@ in { ./waybar.nix ./zsh.nix ]; - - programs.nh = { - enable = true; - # flake = "/etc/nixos/config#laptop" - }; - - programs.direnv = { - enable = true; - nix-direnv.enable = true; - enableZshIntegration = true; - }; - - xdg = { - systemDirs.data = ["${pkgs.nordvpn}/share"]; - portal = { - enable = true; - extraPortals = with pkgs; [ - xdg-desktop-portal - xdg-desktop-portal-wlr - xdg-desktop-portal-gtk - xdg-desktop-portal-xapp - ]; - }; - }; - - fonts.fontconfig.enable = true; - home = { - stateVersion = "25.05"; - homeDirectory = "/home/${user.username}"; - username = user.username; - - shell.enableZshIntegration = true; - - sessionVariables = { - SSH_AUTH_SOCK = "/run/user/1000/ssh-agent"; - EDITOR = "nvim"; - VISUAL = "nvim"; - GTK_THEME = "Breeze-Dark"; - NIXOS_OZONE_WL = "1"; - }; - - packages = with pkgs; [ - # Add your global packages here - mpv - sxiv - feh - duralumin - duralumin-keygen - ranger - neovim - bottom - git - wget - curl - htop - tree - htop - pavucontrol - ripgrep - killall - x11_ssh_askpass - xdg-utils - vanilla-dmz - (discord.override {withVencord = true;}) - spotify - pkgs.unstable.zed-editor-fhs - file - bitwarden-desktop - bitwarden-cli - prismlauncher - virt-manager - - gh - - # for running wayland apps over ssh - waypipe - - foliate - - # file manager - nemo-with-extensions - - screenshot - ]; - }; } diff --git a/home/desktop-apps.nix b/home/desktop-apps.nix new file mode 100644 index 0000000..d4a01b7 --- /dev/null +++ b/home/desktop-apps.nix @@ -0,0 +1,27 @@ +{pkgs, ...}: { + packages = with pkgs; [ + # Video/Image Viewers + mpv + feh + sxiv + + vanilla-dmz + whitesur-cursors + + x11_ssh_askpass + pavucontrol + (discord.override {withVencord = true;}) + spotify + pkgs.unstable.zed-editor-fhs + bitwarden-desktop + bitwarden-cli + + # Minecraft Launcher + prismlauncher + virt-manager + foliate + + # GUI File Manager + nemo-with-extensions + ]; +} diff --git a/home/sway.nix b/home/sway.nix index 0982f62..1c7441b 100644 --- a/home/sway.nix +++ b/home/sway.nix @@ -15,11 +15,12 @@ in { wmctrl alsa-utils wireplumber - alacritty - waybar - sway - whitesur-cursors rofi-wayland + + alacritty + + vanilla-dmz + whitesur-cursors ]; wayland = { diff --git a/home/wsl.nix b/home/wsl.nix new file mode 100644 index 0000000..98c2018 --- /dev/null +++ b/home/wsl.nix @@ -0,0 +1,11 @@ +{...}: { + imports = [ + ./common.nix + ./development + ./emacs.nix + ./git-ssh.nix + ./syncthing.nix + ./theme.nix + ./zsh.nix + ]; +} diff --git a/home/xdg.nix b/home/xdg.nix new file mode 100644 index 0000000..39284a2 --- /dev/null +++ b/home/xdg.nix @@ -0,0 +1,14 @@ +{pkgs, ...}: { + xdg = { + systemDirs.data = ["${pkgs.nordvpn}/share"]; + portal = { + enable = true; + extraPortals = with pkgs; [ + xdg-desktop-portal + xdg-desktop-portal-wlr + xdg-desktop-portal-gtk + xdg-desktop-portal-xapp + ]; + }; + }; +} diff --git a/system/core.nix b/system/core.nix new file mode 100644 index 0000000..576f51f --- /dev/null +++ b/system/core.nix @@ -0,0 +1,70 @@ +{pkgs, ...}: { + environment.systemPackages = with pkgs; [ + # Basic utilities + zsh + wget + curl + git + vim + + htop + + linux-firmware + linuxHeaders + ]; + + nix.settings.experimental-features = [ + "nix-command" + "flakes" + ]; + + system = { + stateVersion = "25.05"; + activationScripts = { + rfkill-unblock = { + text = '' + rfkill unblock all + ''; + deps = []; + }; + }; + }; + + time.hardwareClockInLocalTime = true; + + security = { + polkit.enable = true; + rtkit.enable = true; + sudo.wheelNeedsPassword = false; # Allow sudo without password + }; + + time.timeZone = "Europe/Amsterdam"; + i18n.defaultLocale = "en_GB.UTF-8"; + + console = { + font = "Lat2-Terminus16"; + keyMap = "uk"; + }; + + services = { + dbus.implementation = "broker"; + + pipewire = { + enable = true; + pulse.enable = true; + alsa.enable = true; + alsa.support32Bit = true; + }; + + openssh = { + enable = true; + settings = { + PasswordAuthentication = true; # Enable password authentication. + ./user + PermitRootLogin = "yes"; # Allow root login (not recommended for production). + }; + }; + + libinput.enable = true; + }; +} diff --git a/system/default.nix b/system/default.nix index bd38170..42699d1 100644 --- a/system/default.nix +++ b/system/default.nix @@ -1,6 +1,7 @@ -{pkgs, ...}: { +{...}: { imports = [ ./boot.nix + ./core.nix ./fonts.nix ./hardware.nix ./networking.nix @@ -9,72 +10,4 @@ ./virtualisation.nix ./wireless.nix ]; - - environment.systemPackages = with pkgs; [ - # Basic utilities - zsh - wget - curl - git - vim - - htop - - linux-firmware - linuxHeaders - ]; - - nix.settings.experimental-features = [ - "nix-command" - "flakes" - ]; - - system = { - stateVersion = "25.05"; - activationScripts = { - rfkill-unblock = { - text = '' - rfkill unblock all - ''; - deps = []; - }; - }; - }; - - time.hardwareClockInLocalTime = true; - - security = { - polkit.enable = true; - rtkit.enable = true; - sudo.wheelNeedsPassword = false; # Allow sudo without password - }; - - time.timeZone = "Europe/Amsterdam"; - i18n.defaultLocale = "en_GB.UTF-8"; - - console = { - font = "Lat2-Terminus16"; - keyMap = "uk"; - }; - - services = { - dbus.implementation = "broker"; - - pipewire = { - enable = true; - pulse.enable = true; - alsa.enable = true; - alsa.support32Bit = true; - }; - - openssh = { - enable = true; - settings = { - PasswordAuthentication = true; # Enable password authentication. - PermitRootLogin = "yes"; # Allow root login (not recommended for production). - }; - }; - - libinput.enable = true; - }; } diff --git a/user/common.nix b/user/common.nix new file mode 100644 index 0000000..21249b3 --- /dev/null +++ b/user/common.nix @@ -0,0 +1,27 @@ +{config, pkgs, ...}: +let + user = import ../data/user.nix {}; +in { + imports = [ + ../options.nix + ]; + + users.users.${user.username} = { + shell = pkgs.zsh; + group = "users"; + home = "/home/${user.username}"; + createHome = true; + isNormalUser = true; + extraGroups = [ "wheel" "input" "nordvpn" "networkmanager" "libvirtd" ]; + }; + + programs.zsh.enable = true; + programs.dconf.enable = true; + programs.ssh = { + startAgent = true; + }; + + home-manager.extraSpecialArgs = { + super-config = config; + }; +} diff --git a/user/default.nix b/user/default.nix index ed85da2..d00f3f1 100644 --- a/user/default.nix +++ b/user/default.nix @@ -1,45 +1,16 @@ -{config, pkgs, ...}: +{...}: let user = import ../data/user.nix {}; in { imports = [ - ../options.nix + ../options.nix + ./common.nix + ./greetd.nix ]; - users.users.${user.username} = { - shell = pkgs.zsh; - group = "users"; - home = "/home/${user.username}"; - createHome = true; - isNormalUser = true; - extraGroups = [ "wheel" "input" "nordvpn" "networkmanager" "libvirtd" ]; - }; - - programs.zsh.enable = true; - programs.dconf.enable = true; - programs.ssh = { - startAgent = true; - }; - - services = { - udisks2.enable = true; - # xserver.enable = true; - # xserver.displayManager.sddm.enable = true; - greetd = { - enable = true; - settings = { - default_session = { - command = "${pkgs.greetd.tuigreet}/bin/tuigreet --time --cmd 'dbus-run-session sway'"; - user = "greeter"; - }; - }; - }; - }; + services.udisks2.enable = true; home-manager.users.${user.username} = { ... }: { imports = [ ../home ]; }; - home-manager.extraSpecialArgs = { - super-config = config; - }; } diff --git a/user/greetd.nix b/user/greetd.nix new file mode 100644 index 0000000..69f4bb4 --- /dev/null +++ b/user/greetd.nix @@ -0,0 +1,11 @@ +{pkgs, ...}: { + services.greetd = { + enable = true; + settings = { + default_session = { + command = "${pkgs.greetd.tuigreet}/bin/tuigreet --time --cmd 'dbus-run-session sway'"; + user = "greeter"; + }; + }; + }; +} diff --git a/user/wsl.nix b/user/wsl.nix new file mode 100644 index 0000000..e26e72d --- /dev/null +++ b/user/wsl.nix @@ -0,0 +1,13 @@ +{...}: +let + user = import ../data/user.nix {}; +in { + imports = [ + ../options.nix + ./common.nix + ]; + + home-manager.users.${user.username} = { ... }: { + imports = [ ../home/wsl.nix ]; + }; +}