Nix Flakes configuration for MacOS, NixOS and WSL

feat: reorganize files

+202 -102
+23 -1
README.md
··· 70 70 71 71 ## Folder structure 72 72 73 - > TODO: write the new documentation with the dentritic pattern usage 73 + 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. 74 + 75 + The only things not treated as it are the custom packages inside the packages folder. 76 + 77 + > [!NOTE] 78 + > This is my current idea of what will look the folders, it can change in the future. 79 + 80 + ``` 81 + . 82 + ├── modules/ 83 + │ ├── features/ # Feature definitions 84 + │ ├── hjem/ # Hjem modules (not using flake-parts modules) 85 + │ ├── hosts/ # machines configurations 86 + │ ├── lib/ # Custom library (mostly factories) 87 + │ ├── packages/ # Custom packages derivations (per-system) 88 + │ ├── tools/ # Basic tools configurations (flake-parts, hjem, impermanence, ...) 89 + │ ├── users/ # Users configurations 90 + │ └── default.nix # Modules entrypoint with auto-import 91 + ├── secrets/ # Secrets files used by agenix 92 + │ └── secrets.nix # Secrets entrypoint 93 + ├── flake.nix # Configuration entrypoint 94 + └── justfile # Command helper 95 + ``` 74 96 75 97 ## Commands 76 98
+1 -1
modules/factories/auto-login.nix modules/features/auto-login.nix
··· 1 1 { 2 - config.flake.factories.autoLogin = username: { ... }: { 2 + config.flake.factory.autoLogin = username: { ... }: { 3 3 services.displayManager.autoLogin.enable = true; 4 4 services.displayManager.autoLogin.user = username; 5 5 };
+4 -2
modules/factories/host.nix modules/lib/host.nix
··· 6 6 modules = 7 7 modules ++ [ 8 8 hardwareConfig 9 - inputs.self.nixosModules.unfree-packages 9 + inputs.self.modules.nixos.unfree-packages 10 + inputs.self.modules.nixos.garbageCollector 10 11 ({ ... }: { 11 12 networking.hostName = hostname; 12 13 nix.settings.experimental-features = [ "nix-command" "flakes" ]; ··· 26 27 inputs.darwin.lib.darwinSystem { 27 28 inherit system; 28 29 modules = [ 29 - inputs.self.darwinModules.unfree-packages 30 + inputs.self.modules.darwin.unfree-packages 31 + inputs.self.modules.darwin.garbageCollector 30 32 ({ ... }: { 31 33 nix.enable = true; 32 34 networking.hostName = hostname;
+18
modules/features/gnome-desktop.nix
··· 1 + { 2 + # Minimal gnome desktop 3 + flake.modules.nixos.gnome-desktop = { inputs, pkgs, ... }: { 4 + imports = with inputs.self.modules.nixos; [ 5 + audio 6 + ]; 7 + 8 + services.displayManager.gdm.enable = true; 9 + services.displayManager.autoLogin.enable = true; 10 + services.displayManager.autoLogin.user = "cosmeak"; 11 + services.desktopManager.gnome.enable = true; 12 + services.gnome.games.enable = false; 13 + services.gnome.core-developer-tools.enable = false; 14 + services.gnome.core-apps.enable = false; 15 + environment.gnome.excludePackages = with pkgs; [ gnome-tour gnome-user-docs ]; 16 + environment.systemPackages = with pkgs; [ nautilus ]; 17 + }; 18 + }
+11
modules/features/kde-desktop.nix
··· 1 + { 2 + flake.modules.nixos.kde-desktop = { inputs, ... }: { 3 + imports = with inputs.self.modules.nixos; [ 4 + audio 5 + ]; 6 + 7 + services.displayManager.sddm.enable = true; 8 + services.displayManager.sddm.wayland.enable = true; 9 + services.desktopManager.plasma6.enable = true; 10 + }; 11 + }
+7 -9
modules/hosts/andhrimnir/configuration.nix
··· 3 3 configuration = { pkgs, ... }: { 4 4 imports = 5 5 with inputs.self.modules.nixos; 6 - with inputs.self.factories; 6 + with inputs.self.factory; 7 7 [ 8 - system-boot-grub 9 - system-garbageCollector 10 - system-audio 11 - system-graphics-nvidia 12 - services-desktops-kdePlasma 13 - neoxa 14 - (autoLogin "neoxa") 15 - ]; 8 + grub 9 + nvidia-gpu 10 + kde-desktop 11 + neoxa 12 + (autoLogin "neoxa") 13 + ]; 16 14 17 15 networking.networkmanager.enable = true; 18 16
+12 -6
modules/hosts/loki/configuration.nix
··· 3 3 configuration = { pkgs, ... }: { 4 4 imports = 5 5 with inputs.self.modules.nixos; 6 - with inputs.self.factories; 6 + with inputs.self.factory; 7 7 [ 8 - system-boot-systemd 9 - system-garbageCollector 10 - system-audio 11 - system-graphics-nvidia 12 - services-desktops-gnome 8 + systemd-boot 9 + audio 10 + nvidia-gpu 11 + gnome-desktop 13 12 cosmeak 14 13 (autoLogin "cosmeak") 15 14 ]; ··· 27 26 programs.steam = { 28 27 enable = true; 29 28 gamescopeSession.enable = true; 29 + }; 30 + 31 + networking.firewall = { 32 + enable = true; 33 + # Open ports for minecraft LAN 34 + allowedUDPPorts = [ 25565 ]; 35 + allowedTCPPorts = [ 25565 ]; 30 36 }; 31 37 }; 32 38 in
+1 -3
modules/hosts/njord/configuration.nix
··· 1 1 { inputs, ... }: 2 2 let 3 - configuration = { pkgs, ... }: { 3 + configuration = { ... }: { 4 4 imports = with inputs.self.modules.darwin; [ 5 - system-garbageCollector 6 5 cosmeak 7 6 ]; 8 7 ··· 107 106 "figma" # Collaborative design application 108 107 "gpg-suite-no-mail" # Signing tool for commits 109 108 "logi-options+" # 110 - "modrinth" # Minecraft launcher 111 109 "zed" # Code editor 112 110 ]; 113 111 };
+3 -5
modules/hosts/sunna/configuration.nix
··· 2 2 let 3 3 configuration = { ... }: { 4 4 imports = with inputs.self.modules.nixos; [ 5 - system-boot-systemd 6 - system-garbageCollector 7 - system-audio 8 - system-graphics-nvidia 9 - services-desktops-kdePlasma 5 + systemd-boot 6 + nvidia-gpu 7 + kde-desktop 10 8 ]; 11 9 12 10 networking.networkmanager.enable = true;
+37
modules/lib/user.nix
··· 1 + { self, ... }: { 2 + config.flake.factory.user = { username, isAdmin }: { 3 + nixos.${username} = { lib, pkgs, ... }: 4 + let home = "/home/${username}"; in { 5 + # imports = [ self.modules.nixos.hjem ]; 6 + 7 + users.users.${username} = { 8 + isNormalUser = true; 9 + home = home; 10 + extraGroups = lib.optionals isAdmin [ "wheel" ]; 11 + }; 12 + 13 + # hjem.users.${username} = { 14 + # enable = true; 15 + # directory = home; 16 + # user = username; 17 + # }; 18 + }; 19 + 20 + darwin.${username} = { lib, pkgs, ... }: 21 + let home = "/Users/${username}"; in { 22 + # imports = [ self.modules.darwin.hjem ]; 23 + 24 + users.users.${username} = { 25 + home = home; 26 + }; 27 + 28 + system.primaryUser = lib.mkIf isAdmin "${username}"; 29 + 30 + # hjem.users.${username} = { 31 + # enable = true; 32 + # directory = home; 33 + # user = username; 34 + # }; 35 + }; 36 + }; 37 + }
+2 -2
modules/nix/unfree.nix modules/features/unfree.nix
··· 8 8 }; 9 9 10 10 config = let packages = config.allowedUnfreePackages; in { 11 - flake.nixosModules.unfree-packages = { lib, ... }: { 11 + flake.modules.nixos.unfree-packages = { lib, ... }: { 12 12 nixpkgs.config.allowUnfreePredicate = pkg: 13 13 builtins.elem (lib.getName pkg) packages; 14 14 }; 15 15 16 - flake.darwinModules.unfree-packages = { lib, ... }: { 16 + flake.modules.darwin.unfree-packages = { lib, ... }: { 17 17 nixpkgs.config.allowUnfreePredicate = pkg: 18 18 builtins.elem (lib.getName pkg) packages; 19 19 };
-16
modules/services/desktops/gnome.nix
··· 1 - { 2 - flake.modules.nixos.services-desktops-gnome = { pkgs, ... }: { 3 - services.displayManager.gdm.enable = true; 4 - services.displayManager.autoLogin.enable = true; 5 - services.displayManager.autoLogin.user = "cosmeak"; 6 - services.desktopManager.gnome.enable = true; 7 - services.gnome.games.enable = false; 8 - services.gnome.core-developer-tools.enable = false; 9 - environment.gnome.excludePackages = with pkgs; [ 10 - gnome-tour 11 - gnome-user-docs 12 - gnome-text-editor 13 - gnome-console 14 - ]; 15 - }; 16 - }
-7
modules/services/desktops/kdePlasma.nix
··· 1 - { 2 - flake.modules.nixos.services-desktops-kdePlasma = { ... }: { 3 - services.displayManager.sddm.enable = true; 4 - services.displayManager.sddm.wayland.enable = true; 5 - services.desktopManager.plasma6.enable = true; 6 - }; 7 - }
+1 -1
modules/system/audio.nix modules/features/audio.nix
··· 1 1 { lib, ... }: 2 2 { 3 - flake.modules.nixos.system-audio = { ... }: { 3 + flake.modules.nixos.audio = { ... }: { 4 4 services.pulseaudio.enable = lib.mkForce false; 5 5 security.rtkit.enable = true; 6 6 services.pipewire = {
+1 -1
modules/system/boot/grub.nix modules/features/grub.nix
··· 1 1 { 2 - flake.modules.nixos.system-boot-grub = { ... }: { 2 + flake.modules.nixos.grub = { ... }: { 3 3 boot.loader.grub.enable = true; 4 4 boot.loader.grub.device = "nodev"; 5 5 boot.loader.grub.useOSProber = true;
+1 -1
modules/system/boot/systemd-boot.nix modules/features/systemd-boot.nix
··· 1 1 { 2 2 # EFI Bootloader 3 - flake.modules.nixos.system-boot-systemd = { ... }: { 3 + flake.modules.nixos.systemd-boot = { ... }: { 4 4 boot.loader.systemd-boot.enable = true; 5 5 boot.loader.efi.canTouchEfiVariables = true; 6 6 boot.loader.systemd-boot.configurationLimit = 10;
+2 -2
modules/system/garbage-collector.nix modules/features/garbage-collector.nix
··· 1 1 { 2 - flake.modules.nixos.system-garbageCollector = { ... }: { 2 + flake.modules.nixos.garbageCollector = { ... }: { 3 3 nix.settings.auto-optimise-store = true; 4 4 nix.gc = { 5 5 automatic = true; ··· 8 8 }; 9 9 }; 10 10 11 - flake.modules.darwin.system-garbageCollector = { ... }: { 11 + flake.modules.darwin.garbageCollector = { ... }: { 12 12 nix.gc = { 13 13 automatic = true; 14 14 interval = [{ Weekday = 7; }];
+1 -1
modules/system/graphics/nvidia.nix modules/features/nvidia-gpu.nix
··· 1 1 { 2 2 allowedUnfreePackages = [ "nvidia-x11" "nvidia-settings" ]; 3 3 4 - flake.modules.nixos.system-graphics-nvidia = { config, ... }: { 4 + flake.modules.nixos.nvidia-gpu = { config, ... }: { 5 5 hardware.nvidia = { 6 6 package = config.boot.kernelPackages.nvidiaPackages.latest; 7 7 modesetting.enable = true;
+24
modules/tools/_hjem.nix
··· 1 + { inputs, lib, ... }: 2 + let 3 + configuration = { 4 + # hjem.extraModules = [ inputs.self.modules.hjem ]; 5 + hjem.clobberByDefault = true; 6 + }; 7 + in 8 + { 9 + flake.modules.nixos.hjem = { 10 + imports = [ inputs.hjem.nixosModules.default configuration ]; 11 + }; 12 + 13 + flake.modules.darwin.hjem = { 14 + imports = [ inputs.hjem.darwinModules.default configuration ]; 15 + }; 16 + 17 + options.flake.hjemModules = lib.mkOption { 18 + type = lib.types.lazyAttrsOf lib.types.module; 19 + default = { }; 20 + description = '' 21 + Collection of modules defined in classic nix to extend hjem in the end. 22 + ''; 23 + }; 24 + }
+17
modules/tools/flake-parts.nix
··· 1 + { lib, ... }: { 2 + # currently, there's no nix-darwin module for flake-parts, 3 + # so we have to manually add flake.darwinConfigurations 4 + options.flake.darwinConfigurations = lib.mkOption { 5 + type = lib.types.lazyAttrsOf lib.types.raw; 6 + default = { }; 7 + description = '' 8 + Instantiated Darwin configurations. Used by `darwin-rebuild`. 9 + ''; 10 + }; 11 + 12 + # factory: storage for factory aspect functions 13 + options.flake.factory = lib.mkOption { 14 + type = lib.types.attrsOf lib.types.unspecified; 15 + default = { }; 16 + }; 17 + }
+36 -44
modules/users/cosmeak.nix
··· 1 - { ... }: 1 + { lib, self, ... }: 2 2 let 3 3 username = "cosmeak"; 4 4 ··· 18 18 ]; 19 19 in 20 20 { 21 - allowedUnfreePackages = [ "1password" "cursor" "modrinth-app" "modrinth-app-unwrapped" "obsidian" "raycast" "spotify" ]; 22 - 23 - flake.modules.nixos.${username} = { pkgs, ... }: { 24 - users.users.${username} = { 25 - isNormalUser = true; 26 - extraGroups = [ "networkmanager" "wheel" ]; 27 - packages = with pkgs; [ 28 - ghostty # Terminal emulator 29 - heroic # Game Launcher (Epic Games, GOG) 30 - (modrinth-app.overrideAttrs (oldAttrs: { 31 - buildCommand = 32 - '' 33 - gappsWrapperArgs+=( 34 - --set GDK_BACKEND x11 35 - --set WEBKIT_DISABLE_DMABUF_RENDERER 1 36 - ) 37 - '' 38 - + oldAttrs.buildCommand; 39 - })) 40 - obs-studio # Recording App 41 - prismlauncher # Minecraft launcher 42 - vesktop # Discord client 43 - (zed-editor.fhsWithPackages (pkg: [ zlib ])) # Code editor 44 - ] ++ (sharedPackages pkgs); 45 - }; 46 - }; 21 + allowedUnfreePackages = [ "1password" "cursor" "obsidian" "raycast" "spotify" ]; 47 22 48 - flake.modules.darwin.${username} = { pkgs, ... }: { 49 - users.users.${username} = { 50 - home = "Users/${username}/"; 51 - }; 23 + flake.modules = lib.mkMerge [ 24 + (self.factory.user { 25 + username = username; 26 + isAdmin = true; 27 + }) 28 + { 29 + nixos.${username} = { pkgs, ... }: { 30 + users.users.${username} = { 31 + packages = with pkgs; [ 32 + ghostty # Terminal emulator 33 + heroic # Game Launcher (Epic Games, GOG) 34 + obs-studio # Recording App 35 + prismlauncher # Minecraft launcher 36 + vesktop # Discord client 37 + (zed-editor.fhsWithPackages (pkg: [ zlib ])) # Code editor 38 + ] ++ (sharedPackages pkgs); 39 + }; 40 + }; 52 41 53 - environment.systemPackages = with pkgs; [ 54 - alt-tab-macos # alt tab like windows on macos 55 - bruno # IDE for testing apis 56 - chirp # Radio programming tool 57 - dbeaver-bin # Database client 58 - ghostty-bin # Terminal emulator 59 - jujutsu # VCS 60 - stats # System monitoring displayed in macos top bar 61 - podman # container tool -> replacement of docker 62 - podman-compose # compose provider for podman 63 - raycast # replacement for spotlight 64 - ]++ (sharedPackages pkgs); 65 - }; 42 + darwin.${username} = { pkgs, ... }: { 43 + environment.systemPackages = with pkgs; [ 44 + alt-tab-macos # alt tab like windows on macos 45 + bruno # IDE for testing apis 46 + chirp # Radio programming tool 47 + dbeaver-bin # Database client 48 + ghostty-bin # Terminal emulator 49 + jujutsu # VCS 50 + stats # System monitoring displayed in macos top bar 51 + podman # container tool -> replacement of docker 52 + podman-compose # compose provider for podman 53 + raycast # replacement for spotlight 54 + ]++ (sharedPackages pkgs); 55 + }; 56 + } 57 + ]; 66 58 }