| 1 | # This function creates a NixOS system based on our VM setup for a |
| 2 | # particular architecture. |
| 3 | { |
| 4 | overlays, |
| 5 | inputs, |
| 6 | mkNeovim, |
| 7 | }: |
| 8 | name: |
| 9 | { |
| 10 | user, # ./users/{name} |
| 11 | host, # ./users/{name}/{host} |
| 12 | system, # arch-os |
| 13 | extraModules ? [ ], |
| 14 | }: |
| 15 | let |
| 16 | darwin = inputs.nixpkgs.lib.strings.hasSuffix "-darwin" system; |
| 17 | getInputModule = a: b: inputs.${a}.${if darwin then "darwinModules" else "nixosModules"}.${b}; |
| 18 | |
| 19 | # NixOS vs nix-darwin functions |
| 20 | systemFunc = if darwin then inputs.darwin.lib.darwinSystem else inputs.nixpkgs.lib.nixosSystem; |
| 21 | |
| 22 | userDir = ../users + "/${user}"; |
| 23 | userConfig = import (userDir + "/user.nix"); |
| 24 | hostDir = userDir + "/${host}"; |
| 25 | |
| 26 | hostConfigPath = hostDir + "/configuration.nix"; |
| 27 | userConfigPath = userDir + "/configuration.nix"; |
| 28 | hostHomePath = hostDir + "/home.nix"; |
| 29 | userHomePath = userDir + "/home.nix"; |
| 30 | |
| 31 | pathOrNull = a: if builtins.pathExists a then a else null; |
| 32 | |
| 33 | # Arguments passed to all module files |
| 34 | args = { |
| 35 | inherit inputs; |
| 36 | currentSystem = system; |
| 37 | # Details about the host machine |
| 38 | host = { |
| 39 | inherit darwin name; |
| 40 | linux = !darwin; |
| 41 | }; |
| 42 | user = |
| 43 | ( |
| 44 | { |
| 45 | # This acts as formal documentation for what is allowed in user.nix |
| 46 | username, # unix username |
| 47 | name, # your display name |
| 48 | email, # for identity in programs such as git |
| 49 | dotfilesDir, # location to `../.` |
| 50 | timeZone ? "America/Los_Angeles", |
| 51 | # Stylix/Theming |
| 52 | theme ? null, # theme name for stylix |
| 53 | sexuality ? null, # pride flag for hyfetch |
| 54 | font ? null, # font to use |
| 55 | term, # preferred $TERM |
| 56 | editor, # preferred $EDITOR |
| 57 | browser ? null, # preferred $BROWSER |
| 58 | }@user: |
| 59 | user |
| 60 | ) |
| 61 | userConfig; |
| 62 | }; |
| 63 | systemSettings = rec { |
| 64 | inherit darwin; |
| 65 | homeDir = "/${if darwin then "Users" else "home"}/${userConfig.username}"; |
| 66 | }; |
| 67 | |
| 68 | mainHomeImports = builtins.filter (f: f != null) [ |
| 69 | (pathOrNull userHomePath) |
| 70 | (pathOrNull hostHomePath) |
| 71 | ( |
| 72 | { pkgs, ... }: |
| 73 | { |
| 74 | home.packages = [ (mkNeovim user pkgs) ]; |
| 75 | } |
| 76 | ) |
| 77 | inputs.nvf.homeManagerModules.default |
| 78 | inputs.android-nixpkgs.hmModule |
| 79 | inputs.vicinae.homeManagerModules.default |
| 80 | ]; |
| 81 | in |
| 82 | systemFunc { |
| 83 | inherit system; |
| 84 | |
| 85 | modules = |
| 86 | builtins.filter (f: f != null) [ |
| 87 | # Apply our overlays. Overlays are keyed by system type so we have |
| 88 | # to go through and apply our system type. We do this first so |
| 89 | # the overlays are available globally. |
| 90 | { nixpkgs.overlays = overlays; } |
| 91 | |
| 92 | # Modules shared between nix-darwin and NixOS |
| 93 | ../modules/shared |
| 94 | # Modules for the specific OS |
| 95 | (if darwin then ../modules/macos else ../modules/nixos) |
| 96 | |
| 97 | # The user-wide configuration.nix |
| 98 | (pathOrNull userConfigPath) |
| 99 | # The host-wide configuration.nix |
| 100 | (pathOrNull hostConfigPath) |
| 101 | |
| 102 | # Set up nix-index and enable comma for easy one-shot command use |
| 103 | # https://github.com/nix-community/comma |
| 104 | (getInputModule "nix-index-database" "nix-index") |
| 105 | { programs.nix-index-database.comma.enable = true; } |
| 106 | |
| 107 | # Home manager |
| 108 | (getInputModule "home-manager" "home-manager") |
| 109 | { |
| 110 | home-manager = { |
| 111 | useGlobalPkgs = true; |
| 112 | useUserPackages = true; |
| 113 | backupFileExtension = "hm-backup"; |
| 114 | # Arguments passed to all module files |
| 115 | extraSpecialArgs = args // { |
| 116 | inherit mainHomeImports; |
| 117 | }; |
| 118 | # can't find how to make this an array without the param |
| 119 | users.${userConfig.username} = ../modules/home; |
| 120 | }; |
| 121 | users.users.${userConfig.username}.home = systemSettings.homeDir; |
| 122 | } |
| 123 | |
| 124 | # Arguments passed to all module files |
| 125 | { config._module.args = args; } |
| 126 | ] |
| 127 | # Add extra modules specified from config |
| 128 | ++ extraModules; |
| 129 | } |