From a85a5c59423bbff1d3d4263a0f972eecf00a5428 Mon Sep 17 00:00:00 2001 From: cosmeak Date: Sun, 25 Jan 2026 15:11:26 +0100 Subject: [PATCH] feat: reorganize files --- README.md | 24 +++++- modules/{system => features}/audio.nix | 2 +- .../{factories => features}/auto-login.nix | 2 +- .../garbage-collector.nix | 4 +- modules/features/gnome-desktop.nix | 18 +++++ modules/{system/boot => features}/grub.nix | 2 +- .../kde-desktop.nix} | 6 +- .../nvidia.nix => features/nvidia-gpu.nix} | 2 +- .../boot => features}/systemd-boot.nix | 2 +- modules/{nix => features}/unfree.nix | 4 +- modules/hosts/andhrimnir/configuration.nix | 16 ++-- modules/hosts/loki/configuration.nix | 18 +++-- modules/hosts/njord/configuration.nix | 4 +- modules/hosts/sunna/configuration.nix | 8 +- modules/{factories => lib}/host.nix | 6 +- modules/lib/user.nix | 37 +++++++++ modules/services/desktops/gnome.nix | 16 ---- modules/tools/_hjem.nix | 24 ++++++ modules/tools/flake-parts.nix | 17 ++++ modules/users/cosmeak.nix | 80 +++++++++---------- 20 files changed, 196 insertions(+), 96 deletions(-) rename modules/{system => features}/audio.nix (85%) rename modules/{factories => features}/auto-login.nix (66%) rename modules/{system => features}/garbage-collector.nix (73%) create mode 100644 modules/features/gnome-desktop.nix rename modules/{system/boot => features}/grub.nix (80%) rename modules/{services/desktops/kdePlasma.nix => features/kde-desktop.nix} (57%) rename modules/{system/graphics/nvidia.nix => features/nvidia-gpu.nix} (85%) rename modules/{system/boot => features}/systemd-boot.nix (76%) rename modules/{nix => features}/unfree.nix (81%) rename modules/{factories => lib}/host.nix (94%) create mode 100644 modules/lib/user.nix delete mode 100644 modules/services/desktops/gnome.nix create mode 100644 modules/tools/_hjem.nix create mode 100644 modules/tools/flake-parts.nix diff --git a/README.md b/README.md index 338992f..3e2b6ea 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,29 @@ This repository want this to be multi-user and multi-host so there is some worka ## Folder structure -> TODO: write the new documentation with the dentritic pattern usage +This repository use a `dentritic pattern` to make everything work with ease. With this pattern, every file is a modules (modules, configurations, ...), so everything needs to be inside the modules folders and imported as it. + +The only things not treated as it are the custom packages inside the packages folder. + +> [!NOTE] +> This is my current idea of what will look the folders, it can change in the future. + +``` +. +├── modules/ +│ ├── features/ # Feature definitions +│ ├── hjem/ # Hjem modules (not using flake-parts modules) +│ ├── hosts/ # machines configurations +│ ├── lib/ # Custom library (mostly factories) +│ ├── packages/ # Custom packages derivations (per-system) +│ ├── tools/ # Basic tools configurations (flake-parts, hjem, impermanence, ...) +│ ├── users/ # Users configurations +│ └── default.nix # Modules entrypoint with auto-import +├── secrets/ # Secrets files used by agenix +│ └── secrets.nix # Secrets entrypoint +├── flake.nix # Configuration entrypoint +└── justfile # Command helper +``` ## Commands diff --git a/modules/system/audio.nix b/modules/features/audio.nix similarity index 85% rename from modules/system/audio.nix rename to modules/features/audio.nix index 029808c..435c2a7 100644 --- a/modules/system/audio.nix +++ b/modules/features/audio.nix @@ -1,6 +1,6 @@ { lib, ... }: { - flake.modules.nixos.system-audio = { ... }: { + flake.modules.nixos.audio = { ... }: { services.pulseaudio.enable = lib.mkForce false; security.rtkit.enable = true; services.pipewire = { diff --git a/modules/factories/auto-login.nix b/modules/features/auto-login.nix similarity index 66% rename from modules/factories/auto-login.nix rename to modules/features/auto-login.nix index ce1ace9..265abf8 100644 --- a/modules/factories/auto-login.nix +++ b/modules/features/auto-login.nix @@ -1,5 +1,5 @@ { - config.flake.factories.autoLogin = username: { ... }: { + config.flake.factory.autoLogin = username: { ... }: { services.displayManager.autoLogin.enable = true; services.displayManager.autoLogin.user = username; }; diff --git a/modules/system/garbage-collector.nix b/modules/features/garbage-collector.nix similarity index 73% rename from modules/system/garbage-collector.nix rename to modules/features/garbage-collector.nix index 0337278..d7c46e7 100644 --- a/modules/system/garbage-collector.nix +++ b/modules/features/garbage-collector.nix @@ -1,5 +1,5 @@ { - flake.modules.nixos.system-garbageCollector = { ... }: { + flake.modules.nixos.garbageCollector = { ... }: { nix.settings.auto-optimise-store = true; nix.gc = { automatic = true; @@ -8,7 +8,7 @@ }; }; - flake.modules.darwin.system-garbageCollector = { ... }: { + flake.modules.darwin.garbageCollector = { ... }: { nix.gc = { automatic = true; interval = [{ Weekday = 7; }]; diff --git a/modules/features/gnome-desktop.nix b/modules/features/gnome-desktop.nix new file mode 100644 index 0000000..4ba4b68 --- /dev/null +++ b/modules/features/gnome-desktop.nix @@ -0,0 +1,18 @@ +{ + # Minimal gnome desktop + flake.modules.nixos.gnome-desktop = { inputs, pkgs, ... }: { + imports = with inputs.self.modules.nixos; [ + audio + ]; + + services.displayManager.gdm.enable = true; + services.displayManager.autoLogin.enable = true; + services.displayManager.autoLogin.user = "cosmeak"; + services.desktopManager.gnome.enable = true; + services.gnome.games.enable = false; + services.gnome.core-developer-tools.enable = false; + services.gnome.core-apps.enable = false; + environment.gnome.excludePackages = with pkgs; [ gnome-tour gnome-user-docs ]; + environment.systemPackages = with pkgs; [ nautilus ]; + }; +} diff --git a/modules/system/boot/grub.nix b/modules/features/grub.nix similarity index 80% rename from modules/system/boot/grub.nix rename to modules/features/grub.nix index 62c16cb..c56e5d5 100644 --- a/modules/system/boot/grub.nix +++ b/modules/features/grub.nix @@ -1,5 +1,5 @@ { - flake.modules.nixos.system-boot-grub = { ... }: { + flake.modules.nixos.grub = { ... }: { boot.loader.grub.enable = true; boot.loader.grub.device = "nodev"; boot.loader.grub.useOSProber = true; diff --git a/modules/services/desktops/kdePlasma.nix b/modules/features/kde-desktop.nix similarity index 57% rename from modules/services/desktops/kdePlasma.nix rename to modules/features/kde-desktop.nix index f179f34..0a4d48a 100644 --- a/modules/services/desktops/kdePlasma.nix +++ b/modules/features/kde-desktop.nix @@ -1,5 +1,9 @@ { - flake.modules.nixos.services-desktops-kdePlasma = { ... }: { + flake.modules.nixos.kde-desktop = { inputs, ... }: { + imports = with inputs.self.modules.nixos; [ + audio + ]; + services.displayManager.sddm.enable = true; services.displayManager.sddm.wayland.enable = true; services.desktopManager.plasma6.enable = true; diff --git a/modules/system/graphics/nvidia.nix b/modules/features/nvidia-gpu.nix similarity index 85% rename from modules/system/graphics/nvidia.nix rename to modules/features/nvidia-gpu.nix index c72eb4c..e484b7e 100644 --- a/modules/system/graphics/nvidia.nix +++ b/modules/features/nvidia-gpu.nix @@ -1,7 +1,7 @@ { allowedUnfreePackages = [ "nvidia-x11" "nvidia-settings" ]; - flake.modules.nixos.system-graphics-nvidia = { config, ... }: { + flake.modules.nixos.nvidia-gpu = { config, ... }: { hardware.nvidia = { package = config.boot.kernelPackages.nvidiaPackages.latest; modesetting.enable = true; diff --git a/modules/system/boot/systemd-boot.nix b/modules/features/systemd-boot.nix similarity index 76% rename from modules/system/boot/systemd-boot.nix rename to modules/features/systemd-boot.nix index f8c204e..56a7350 100644 --- a/modules/system/boot/systemd-boot.nix +++ b/modules/features/systemd-boot.nix @@ -1,6 +1,6 @@ { # EFI Bootloader - flake.modules.nixos.system-boot-systemd = { ... }: { + flake.modules.nixos.systemd-boot = { ... }: { boot.loader.systemd-boot.enable = true; boot.loader.efi.canTouchEfiVariables = true; boot.loader.systemd-boot.configurationLimit = 10; diff --git a/modules/nix/unfree.nix b/modules/features/unfree.nix similarity index 81% rename from modules/nix/unfree.nix rename to modules/features/unfree.nix index 8e1bde1..fe27cf1 100644 --- a/modules/nix/unfree.nix +++ b/modules/features/unfree.nix @@ -8,12 +8,12 @@ }; config = let packages = config.allowedUnfreePackages; in { - flake.nixosModules.unfree-packages = { lib, ... }: { + flake.modules.nixos.unfree-packages = { lib, ... }: { nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) packages; }; - flake.darwinModules.unfree-packages = { lib, ... }: { + flake.modules.darwin.unfree-packages = { lib, ... }: { nixpkgs.config.allowUnfreePredicate = pkg: builtins.elem (lib.getName pkg) packages; }; diff --git a/modules/hosts/andhrimnir/configuration.nix b/modules/hosts/andhrimnir/configuration.nix index c3efb27..27f0756 100644 --- a/modules/hosts/andhrimnir/configuration.nix +++ b/modules/hosts/andhrimnir/configuration.nix @@ -3,16 +3,14 @@ let configuration = { pkgs, ... }: { imports = with inputs.self.modules.nixos; - with inputs.self.factories; + with inputs.self.factory; [ - system-boot-grub - system-garbageCollector - system-audio - system-graphics-nvidia - services-desktops-kdePlasma - neoxa - (autoLogin "neoxa") - ]; + grub + nvidia-gpu + kde-desktop + neoxa + (autoLogin "neoxa") + ]; networking.networkmanager.enable = true; diff --git a/modules/hosts/loki/configuration.nix b/modules/hosts/loki/configuration.nix index 8a9cf32..f08a0bd 100644 --- a/modules/hosts/loki/configuration.nix +++ b/modules/hosts/loki/configuration.nix @@ -3,13 +3,12 @@ let configuration = { pkgs, ... }: { imports = with inputs.self.modules.nixos; - with inputs.self.factories; + with inputs.self.factory; [ - system-boot-systemd - system-garbageCollector - system-audio - system-graphics-nvidia - services-desktops-gnome + systemd-boot + audio + nvidia-gpu + gnome-desktop cosmeak (autoLogin "cosmeak") ]; @@ -28,6 +27,13 @@ let enable = true; gamescopeSession.enable = true; }; + + networking.firewall = { + enable = true; + # Open ports for minecraft LAN + allowedUDPPorts = [ 25565 ]; + allowedTCPPorts = [ 25565 ]; + }; }; in { diff --git a/modules/hosts/njord/configuration.nix b/modules/hosts/njord/configuration.nix index b045461..f9a9375 100644 --- a/modules/hosts/njord/configuration.nix +++ b/modules/hosts/njord/configuration.nix @@ -1,8 +1,7 @@ { inputs, ... }: let - configuration = { pkgs, ... }: { + configuration = { ... }: { imports = with inputs.self.modules.darwin; [ - system-garbageCollector cosmeak ]; @@ -107,7 +106,6 @@ let "figma" # Collaborative design application "gpg-suite-no-mail" # Signing tool for commits "logi-options+" # - "modrinth" # Minecraft launcher "zed" # Code editor ]; }; diff --git a/modules/hosts/sunna/configuration.nix b/modules/hosts/sunna/configuration.nix index 793b7aa..280bbad 100644 --- a/modules/hosts/sunna/configuration.nix +++ b/modules/hosts/sunna/configuration.nix @@ -2,11 +2,9 @@ let configuration = { ... }: { imports = with inputs.self.modules.nixos; [ - system-boot-systemd - system-garbageCollector - system-audio - system-graphics-nvidia - services-desktops-kdePlasma + systemd-boot + nvidia-gpu + kde-desktop ]; networking.networkmanager.enable = true; diff --git a/modules/factories/host.nix b/modules/lib/host.nix similarity index 94% rename from modules/factories/host.nix rename to modules/lib/host.nix index eb14845..e48a2cb 100644 --- a/modules/factories/host.nix +++ b/modules/lib/host.nix @@ -6,7 +6,8 @@ let modules = modules ++ [ hardwareConfig - inputs.self.nixosModules.unfree-packages + inputs.self.modules.nixos.unfree-packages + inputs.self.modules.nixos.garbageCollector ({ ... }: { networking.hostName = hostname; nix.settings.experimental-features = [ "nix-command" "flakes" ]; @@ -26,7 +27,8 @@ let inputs.darwin.lib.darwinSystem { inherit system; modules = [ - inputs.self.darwinModules.unfree-packages + inputs.self.modules.darwin.unfree-packages + inputs.self.modules.darwin.garbageCollector ({ ... }: { nix.enable = true; networking.hostName = hostname; diff --git a/modules/lib/user.nix b/modules/lib/user.nix new file mode 100644 index 0000000..544e237 --- /dev/null +++ b/modules/lib/user.nix @@ -0,0 +1,37 @@ +{ self, ... }: { + config.flake.factory.user = { username, isAdmin }: { + nixos.${username} = { lib, pkgs, ... }: + let home = "/home/${username}"; in { + # imports = [ self.modules.nixos.hjem ]; + + users.users.${username} = { + isNormalUser = true; + home = home; + extraGroups = lib.optionals isAdmin [ "wheel" ]; + }; + + # hjem.users.${username} = { + # enable = true; + # directory = home; + # user = username; + # }; + }; + + darwin.${username} = { lib, pkgs, ... }: + let home = "/Users/${username}"; in { + # imports = [ self.modules.darwin.hjem ]; + + users.users.${username} = { + home = home; + }; + + system.primaryUser = lib.mkIf isAdmin "${username}"; + + # hjem.users.${username} = { + # enable = true; + # directory = home; + # user = username; + # }; + }; + }; +} diff --git a/modules/services/desktops/gnome.nix b/modules/services/desktops/gnome.nix deleted file mode 100644 index ec5cc64..0000000 --- a/modules/services/desktops/gnome.nix +++ /dev/null @@ -1,16 +0,0 @@ -{ - flake.modules.nixos.services-desktops-gnome = { pkgs, ... }: { - services.displayManager.gdm.enable = true; - services.displayManager.autoLogin.enable = true; - services.displayManager.autoLogin.user = "cosmeak"; - services.desktopManager.gnome.enable = true; - services.gnome.games.enable = false; - services.gnome.core-developer-tools.enable = false; - environment.gnome.excludePackages = with pkgs; [ - gnome-tour - gnome-user-docs - gnome-text-editor - gnome-console - ]; - }; -} diff --git a/modules/tools/_hjem.nix b/modules/tools/_hjem.nix new file mode 100644 index 0000000..ed290dc --- /dev/null +++ b/modules/tools/_hjem.nix @@ -0,0 +1,24 @@ +{ inputs, lib, ... }: +let + configuration = { + # hjem.extraModules = [ inputs.self.modules.hjem ]; + hjem.clobberByDefault = true; + }; +in +{ + flake.modules.nixos.hjem = { + imports = [ inputs.hjem.nixosModules.default configuration ]; + }; + + flake.modules.darwin.hjem = { + imports = [ inputs.hjem.darwinModules.default configuration ]; + }; + + options.flake.hjemModules = lib.mkOption { + type = lib.types.lazyAttrsOf lib.types.module; + default = { }; + description = '' + Collection of modules defined in classic nix to extend hjem in the end. + ''; + }; +} diff --git a/modules/tools/flake-parts.nix b/modules/tools/flake-parts.nix new file mode 100644 index 0000000..a72bcfd --- /dev/null +++ b/modules/tools/flake-parts.nix @@ -0,0 +1,17 @@ +{ lib, ... }: { + # currently, there's no nix-darwin module for flake-parts, + # so we have to manually add flake.darwinConfigurations + options.flake.darwinConfigurations = lib.mkOption { + type = lib.types.lazyAttrsOf lib.types.raw; + default = { }; + description = '' + Instantiated Darwin configurations. Used by `darwin-rebuild`. + ''; + }; + + # factory: storage for factory aspect functions + options.flake.factory = lib.mkOption { + type = lib.types.attrsOf lib.types.unspecified; + default = { }; + }; +} diff --git a/modules/users/cosmeak.nix b/modules/users/cosmeak.nix index 0489cee..d57e1a2 100644 --- a/modules/users/cosmeak.nix +++ b/modules/users/cosmeak.nix @@ -1,4 +1,4 @@ -{ ... }: +{ lib, self, ... }: let username = "cosmeak"; @@ -18,49 +18,41 @@ let ]; in { - allowedUnfreePackages = [ "1password" "cursor" "modrinth-app" "modrinth-app-unwrapped" "obsidian" "raycast" "spotify" ]; + allowedUnfreePackages = [ "1password" "cursor" "obsidian" "raycast" "spotify" ]; - flake.modules.nixos.${username} = { pkgs, ... }: { - users.users.${username} = { - isNormalUser = true; - extraGroups = [ "networkmanager" "wheel" ]; - packages = with pkgs; [ - ghostty # Terminal emulator - heroic # Game Launcher (Epic Games, GOG) - (modrinth-app.overrideAttrs (oldAttrs: { - buildCommand = - '' - gappsWrapperArgs+=( - --set GDK_BACKEND x11 - --set WEBKIT_DISABLE_DMABUF_RENDERER 1 - ) - '' - + oldAttrs.buildCommand; - })) - obs-studio # Recording App - prismlauncher # Minecraft launcher - vesktop # Discord client - (zed-editor.fhsWithPackages (pkg: [ zlib ])) # Code editor - ] ++ (sharedPackages pkgs); - }; - }; + flake.modules = lib.mkMerge [ + (self.factory.user { + username = username; + isAdmin = true; + }) + { + nixos.${username} = { pkgs, ... }: { + users.users.${username} = { + packages = with pkgs; [ + ghostty # Terminal emulator + heroic # Game Launcher (Epic Games, GOG) + obs-studio # Recording App + prismlauncher # Minecraft launcher + vesktop # Discord client + (zed-editor.fhsWithPackages (pkg: [ zlib ])) # Code editor + ] ++ (sharedPackages pkgs); + }; + }; - flake.modules.darwin.${username} = { pkgs, ... }: { - users.users.${username} = { - home = "Users/${username}/"; - }; - - environment.systemPackages = with pkgs; [ - alt-tab-macos # alt tab like windows on macos - bruno # IDE for testing apis - chirp # Radio programming tool - dbeaver-bin # Database client - ghostty-bin # Terminal emulator - jujutsu # VCS - stats # System monitoring displayed in macos top bar - podman # container tool -> replacement of docker - podman-compose # compose provider for podman - raycast # replacement for spotlight - ]++ (sharedPackages pkgs); - }; + darwin.${username} = { pkgs, ... }: { + environment.systemPackages = with pkgs; [ + alt-tab-macos # alt tab like windows on macos + bruno # IDE for testing apis + chirp # Radio programming tool + dbeaver-bin # Database client + ghostty-bin # Terminal emulator + jujutsu # VCS + stats # System monitoring displayed in macos top bar + podman # container tool -> replacement of docker + podman-compose # compose provider for podman + raycast # replacement for spotlight + ]++ (sharedPackages pkgs); + }; + } + ]; } -- 2.51.2