### Flake Inputs and Imports Setup Source: https://github.com/doc-steve/dendritic-design-with-flake-parts/wiki/Basics This example shows the necessary setup for Flake Parts and other Nix tool libraries, including defining flake inputs and importing modules. It specifies supported systems for the flake. ```nix flake-file.inputs = { flake-parts.url = "github:hercules-ci/flake-parts"; flake-file.url = "github:vic/flake-file"; import-tree.url = "github:vic/import-tree"; }; imports = [ inputs.flake-parts.flakeModules.modules inputs.flake-file.flakeModules.default ]; systems = [ "aarch64-darwin" "aarch64-linux" "x86_64-darwin" "x86_64-linux" ]; ``` -------------------------------- ### Project Structure Overview Source: https://github.com/doc-steve/dendritic-design-with-flake-parts/wiki/Comprehensive_Example This GraphQL-like structure outlines the organization of a comprehensive Nix configuration example, detailing feature directories and their system contexts (NixOS, Darwin, Home-Manager). ```graphql ├── flake.nix └── modules ├── factory │ ├── 'user [ND]' │ └── 'mount-cifs-nixos [N]' ├── hosts │ ├── 'homeserver [N]' │ │ ├── services │ │ │ └── syncthing │ │ └── users │ ├── 'linux-desktop [N]' │ │ └── users │ └── 'macbook [D]' │ └── users ├── nix │ ├── 'flake-parts []' │ └── tools │ ├── 'determinate [D]' │ ├── 'home-manager [ND]' │ ├── 'homebrew [D]' │ ├── 'impermanence [N]' │ ├── 'pkgs-by-name [G]' │ └── 'secrets [NDnd]' ├── programs │ ├── 'browser [nd]' │ ├── 'cli-tools [ND]' │ ├── 'gnome [N]' │ ├── 'office [nd]' │ └── 'shell [nd]' ├── services │ ├── 'iperf [N]' │ ├── 'printing [N]' │ ├── 'ssh [ND]' │ └── 'syncthing [N]' ├── system │ ├── settings │ │ ├── 'bluetooth [N]' │ │ ├── 'firmware [N]' │ │ ├── network │ │ │ ├── 'subnet-A [networkInterfaces]' │ │ │ └── 'subnet-B [networkInterfaces]' │ │ ├── 'systemConstants [NDnd]' │ │ └── 'systemd-boot [N]' │ └── 'system types' │ ├── '1 - system-default [NDnd]' │ │ ├── darwin │ │ ├── homeManager │ │ └── nixos │ ├── '2 - system-essential [NDnd]' │ ├── '3 - system-basic [NDnd]' │ ├── '4 - system-cli [NDnd]' │ └── '5 - system-desktop [NDnd]' └── users ├── 'alice [D]' ├── 'bob [NDn]' ├── 'eve [N]' └── 'mallory [N]' ``` -------------------------------- ### Search for Dendritic Implementations on GitHub Source: https://github.com/doc-steve/dendritic-design-with-flake-parts/wiki/Acknowledgement_and_additional_information Use this console command to search GitHub for Nix implementations related to flake modules and specific options, which can provide inspiration for Dendritic setups. ```console lang:nix flake.modules SOME-OPTION ``` -------------------------------- ### Conditional Aspect Example for Home Manager Source: https://github.com/doc-steve/dendritic-design-with-flake-parts/wiki/Dendritic_Aspects Use lib.mkIf to conditionally include packages based on the operating system. This is useful for home-manager modules that need to support both NixOS and Nix-Darwin environments. ```nix flake.modules.homeManager.office = { pkgs, lib, ... }: lib.mkMerge [ { home.packages = with pkgs; [ notesnook ]; # settings for all systems } (lib.mkIf (pkgs.stdenv.isLinux) { home.packages = with pkgs; [ libreoffice-qt6 ]; # NixOS settings }) (lib.mkIf (pkgs.stdenv.isDarwin) { home.packages = with pkgs; [ libreoffice-bin ]; # Nix-Darwin settings }) ]; ``` -------------------------------- ### Feature Module with Aspect Definition and Usage Source: https://github.com/doc-steve/dendritic-design-with-flake-parts/wiki/Basics This example demonstrates a feature module that defines a NixOS aspect and then uses it within the flake's configuration. It illustrates how to define aspects and structure them hierarchically using imports. ```nix { # <- this is the feature module # 'flake.modules' module definition flake.modules.nixos.aspect1 = { # defining the hierarchical module structure imports = with inputs.self.modules.nixos; [ aspect2 aspect3 ]; }; # using the previously defined 'aspect1' module for a system configuration (flake-part boilerplate) flake.nixosConfigurations = ... # nixpkgs.lib.nixosSystem using inputs.self.modules.nixos.aspect1; } ``` -------------------------------- ### Multi Context Aspect Example for GNOME Feature Source: https://github.com/doc-steve/dendritic-design-with-flake-parts/wiki/Dendritic_Aspects Defines a feature (GNOME) that is primarily for NixOS but also includes configuration for Home-Manager. The auxiliary module for Home-Manager is included via sharedModules in the main NixOS module. ```nix {inputs, ...}: { flake.modules.nixos.gnome = { home-manager.sharedModules = [ inputs.self.modules.homeManager.gnome ]; # configuration of gnome on system level }; flake.modules.homeManager.gnome = { # auxiliary module # configuration of gnome with the options of home-manager }; } ``` -------------------------------- ### Inheritance Aspect Example for System Desktop Feature Source: https://github.com/doc-steve/dendritic-design-with-flake-parts/wiki/Dendritic_Aspects Extends the 'system-cli' aspect for 'system-desktop' feature in NixOS and Darwin contexts. It imports the parent aspect and adds specific extensions like mail, browser, KDE, and printing for NixOS, and mail and browser for Darwin. ```nix {inputs, ...}: { flake.modules.nixos.system-desktop = { imports = with inputs.self.modules.nixos; [ system-cli # parent aspect # extensions and modifications to the parent mail browser kde printing ]; }; flake.modules.darwin.system-desktop = { imports = with inputs.self.modules.darwin; [ system-cli # parent aspect # extensions and modifications to the parent mail browser ]; }; } ``` -------------------------------- ### Assigning Multiple DRY Aspects to a Network Interface Source: https://github.com/doc-steve/dendritic-design-with-flake-parts/wiki/Dendritic_Aspects This example demonstrates how to assign multiple DRY aspects ('subnet-A', 'subnet-B') along with additional configurations to a network interface ('enp86s0') using lib.mkMerge. Ensure lib.mkMerge is used for merging DRY aspects. ```nix networking.interfaces."enp86s0" = with self.modules.networkInterface; lib.mkMerge [ subnet-A subnet-B { ipv4.addresses = [ { address = "10.0.0.1"; prefixLength = 16; } ]; ipv6.addresses = [ { address = "2001:1470:fffd:2098::e006"; prefixLength = 64; } ]; } ]; ``` -------------------------------- ### NixOS Host Configuration with Multiple Features Source: https://github.com/doc-steve/dendritic-design-with-flake-parts/wiki/Dendritic_Aspects This snippet demonstrates how to define a NixOS host configuration, 'linux-desktop', by importing various system modules including user features like 'bob' and 'alice'. It shows how to aggregate features into a complete system. ```nix flake.modules.nixos."linux-desktop" = { imports = with inputs.self.modules.nixos; [ system-cli # this module sets everything for a cli-only standard system syncthing # we want the feature syncthing bob # system user + home-manager included (multi context) alice ]; # addition configuration of all features and additional settings }; ``` -------------------------------- ### NixOS and Darwin Configuration for 'bob' Feature Source: https://github.com/doc-steve/dendritic-design-with-flake-parts/wiki/Dendritic_Aspects This snippet shows how to configure a user feature 'bob' for both NixOS and Darwin systems, including Home-Manager integration and system-level imports. It highlights the application of Simple and Multi Context Aspect patterns. ```nix {inputs, ...}: { # (A) flake.modules.nixos.bob = { # (B) home-manager.users.bob = { imports = [ inputs.self.modules.homeManager.bob ]; }; # (A) imports = with inputs.self.modules.nixos; [ desktopEnvironment # other NixOS features we will want on system level ]; # other NixOS user settings for bob }; # (A) flake.modules.darwin.bob = { # (B) home-manager.users.bob = { imports = [ inputs.self.modules.homeManager.bob ]; }; # (A) imports = with inputs.self.modules.darwin; [ desktopEnvironment # other Nix-Darwin features we will want on system level ]; # other Darwin user settings for bob }; # (B) # (D) -> nothing to do, the internal (private) auxiliary module created for (B) will just be used as a public module flake.modules.homeManager.bob = { # (C) imports = with inputs.self.modules.homeManager; [ adminTools videoEditing ]; # other home-manager user settings }; } ``` -------------------------------- ### NixOS Configuration Helper Function Source: https://github.com/doc-steve/dendritic-design-with-flake-parts/wiki/Basics This helper function simplifies the creation of NixOS configurations by abstracting common module imports and setting the host platform. It's designed to be used with aspect modules. ```nix mkNixos = system: name: { ${name} = inputs.nixpkgs.lib.nixosSystem { modules = [ inputs.self.modules.nixos.${name} { nixpkgs.hostPlatform = lib.mkDefault system; } ]; }; }; ``` -------------------------------- ### Instantiate User Factory Aspect for a Feature Source: https://github.com/doc-steve/dendritic-design-with-flake-parts/wiki/Dendritic_Aspects Shows how to use the 'user' factory aspect function to create an instance for a 'bob' user and then apply additional customizations for NixOS and Darwin. ```nix { flake.modules = lib.mkMerge [ (self.factory.user "bob" true) { nixos.bob = { # additional customization }; darwin.bob = { # additional customization }; } ]; } ``` -------------------------------- ### Include Constants Aspect in System Defaults Source: https://github.com/doc-steve/dendritic-design-with-flake-parts/wiki/Dendritic_Aspects Demonstrates how to import the system constants aspect into different system default configurations (NixOS, macOS, Home Manager). This ensures constants are available across these platforms. ```nix { ... }: { imports = [ inputs.self.modules.generic.systemConstants ]; } ``` -------------------------------- ### Import Anonymous Mount CIFS Factory Aspect Source: https://github.com/doc-steve/dendritic-design-with-flake-parts/wiki/Dendritic_Aspects Demonstrates how to use the anonymous 'mount-cifs-nixos' factory aspect within the imports of a NixOS host configuration, providing all necessary parameters. ```nix flake.modules.nixos.linux-desktop = { lib, config, ... }: { imports = with inputs.self.modules.nixos; with inputs.self.factory; [ (mount-cifs-nixos { host = "home-server.lan"; resource = "home"; destination = "/home/users/bob/homeserver"; credentialspath = "${config.age.secrets."homeserver-cred".path}"; UID = "bob"; GID = "users"; }) # ... ]; # ... } ``` -------------------------------- ### Importing All Feature Modules Recursively Source: https://github.com/doc-steve/dendritic-design-with-flake-parts/wiki/Basics This snippet demonstrates how to import all `.nix` files from a 'modules' folder recursively using `flake-parts` and `vic/import-tree`. Ensure all files in the folder are feature modules. ```nix outputs = inputs: inputs.flake-parts.lib.mkFlake { inherit inputs; } (inputs.import-tree ./modules); ``` -------------------------------- ### NixOS Flake Output Configuration Source: https://github.com/doc-steve/dendritic-design-with-flake-parts/wiki/Dendritic_Aspects This snippet shows the boilerplate code required to define the NixOS configurations within a flake output, using a helper function `mkNixos` to set up the system. ```nix flake.nixosConfigurations = inputs.self.lib.mkNixos "x86_64-linux" "linux-desktop"; ``` -------------------------------- ### Utilize Constants in NixOS Homeserver Configuration Source: https://github.com/doc-steve/dendritic-design-with-flake-parts/wiki/Dendritic_Aspects Shows how to access and use the 'adminEmail' constant defined in the constants aspect within a NixOS homeserver service configuration. ```nix { config, ... }: { services.zfs.zed.settings = { ZED_EMAIL_ADDR = [ config.systemConstants.adminEmail ]; }; } ``` -------------------------------- ### Simple Aspect: Basic Packages for NixOS, Darwin, and Home-Manager Source: https://github.com/doc-steve/dendritic-design-with-flake-parts/wiki/Dendritic_Aspects Defines a 'simple aspect' for basic package management across different operating systems. Each context (NixOS, Darwin, Home-Manager) has its own module definition. ```nix { flake.modules.nixos.basicPackages = { pkgs }: { environment.systemPackages = with pkgs; [ # list of NixOS system packages ]; # necessary configurations }; flake.modules.darwin.basicPackages = { pkgs }: { environment.systemPackages = with pkgs; [ # list of Darwin system packages ]; # necessary configurations }; flake.modules.homeManager.basicPackages = { pkgs }: { programs = { # configuration of various programs }; }; } ``` -------------------------------- ### Define Factory Aspect Library Source: https://github.com/doc-steve/dendritic-design-with-flake-parts/wiki/Dendritic_Aspects This snippet defines the base structure for the flake factory aspect library, setting up an attribute set to hold factory functions. ```nix { options.flake.factory = lib.mkOption { type = lib.types.attrsOf lib.types.unspecified; default = { }; }; } ``` -------------------------------- ### Create User Factory Aspect Function Source: https://github.com/doc-steve/dendritic-design-with-flake-parts/wiki/Dendritic_Aspects Defines a factory aspect function named 'user' that generates module configurations for creating new users on both Darwin and NixOS systems, with an option to set primary user or extra groups based on an isAdmin flag. ```nix { config.flake.factory.user = username: isAdmin: { darwin."${username}" = { users.users."${username}" = { name = "${username}"; }; system.primaryUser = lib.mkIf isAdmin "${username}"; }; nixos."${username}" = { users.users."${username}" = { name = "${username}"; }; extraGroups = lib.optionals isAdmin [ "wheel" ]; }; }; } ``` -------------------------------- ### Define Reusable Module in flake.modules Source: https://github.com/doc-steve/dendritic-design-with-flake-parts/wiki/Basics This snippet shows the basic structure for defining a reusable module within the `flake.modules` attribute. It includes placeholders for the module class, aspect name, and imports. ```nix flake.modules.. = { imports = [ ]; # # module code defining this `aspect` # } ``` -------------------------------- ### Collector Aspect: Host-Specific Syncthing Device Configuration Source: https://github.com/doc-steve/dendritic-design-with-flake-parts/wiki/Dendritic_Aspects Adds host-specific Syncthing device configuration to the collector aspect. This demonstrates how to merge peer IDs for different hosts into the Syncthing configuration. ```nix { # <- feature "homeserver" flake.modules.nixos.syncthing = { services.syncthing.settings.devices = { homeserver = { id = "VNV2XTI-6VY6KR2-OCASMST-Z35JUEG-VNV2XTI-KJWBOKQ-6VYUKR2-Z35JUEG"; }; }; }; } ``` -------------------------------- ### Collector Aspect: Base Syncthing Feature Configuration Source: https://github.com/doc-steve/dendritic-design-with-flake-parts/wiki/Dendritic_Aspects Defines the base configuration for the Syncthing service within a feature. This is the unconditional part of the collector aspect. ```nix { # <- feature "syncthing" flake.modules.nixos.syncthing = { services.syncthing = { enable = true; }; }; } ``` -------------------------------- ### Define Anonymous Mount CIFS Factory Aspect Source: https://github.com/doc-steve/dendritic-design-with-flake-parts/wiki/Dendritic_Aspects Defines a factory aspect function for mounting CIFS shares on NixOS, which returns an anonymous module. This function takes parameters for host, resource, destination, credentialspath, UID, and GID. ```nix { config.flake.factory.mount-cifs-nixos = { host, resource, destination, credentialspath, UID, GID, }: { config, lib, ... }: { fileSystems."${destination}" = { # creating the mount }; }; } ``` -------------------------------- ### Define a DRY Aspect for Network Interface Settings Source: https://github.com/doc-steve/dendritic-design-with-flake-parts/wiki/Dendritic_Aspects This snippet defines a reusable DRY aspect for network interface settings, specifically for 'subnet-A', including IPv6 and IPv4 routing information. This class can be utilized for attribute assignments in other aspects. ```nix flake.modules.networkInterface.subnet-A = { ipv6.routes = [ { address = "2001:1470:fffd:2098::"; prefixLength = 64; via = "fdfd:b3f0::1"; } ]; ipv4.routes = [ { address = "192.168.2.0"; prefixLength = 24; via = "192.168.1.1"; } ]; }; ``` -------------------------------- ### Define System Constants Aspect Source: https://github.com/doc-steve/dendritic-design-with-flake-parts/wiki/Dendritic_Aspects Defines a generic constants aspect that sets system-wide constants. This aspect can be included in various configuration contexts to make these constants available. ```nix { lib, ... }: { options.systemConstants = lib.mkOption { type = lib.types.attrsOf lib.types.unspecified; default = { }; }; config.systemConstants = { adminEmail = "admin@test.org"; }; } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.