diff --git a/flake.nix b/flake.nix index 2513686..c624e9f 100644 --- a/flake.nix +++ b/flake.nix @@ -10,10 +10,30 @@ outputs = { self, nixpkgs, flake-utils, sops-nix }: ( let inherit (nixpkgs) lib; + + defaultMachine = { + system = "x86_64-linux"; + + config = { pkgs, ... }: { + dualBoot = false; + timeZone = null; + keyMap = "us"; + keyboardLayout = "us"; + localeSettings = { }; + users = { }; + }; + }; + + machines = { + nixos.config = { ... }: { + }; + }; + + systems = builtins.mapAttrs (name: value: defaultMachine // value) machines; tryFiles = files: default: lib.lists.foldr (a: b: - if builtins.pathExists a + if (a != null) && (builtins.pathExists a) then a else b) default @@ -54,22 +74,8 @@ } ) // { nixosConfigurations = - let - default = { pkgs, ... }: { - dualBoot = false; - timeZone = null; - keyMap = "us"; - keyboardLayout = "us"; - localeSettings = { }; - users = { }; - }; - systems = { - nixos.config = { ... }: { - }; - }; - in builtins.mapAttrs ( - name: { system ? "x86_64-linux", config }: nixpkgs.lib.nixosSystem { + name: { system, config }: nixpkgs.lib.nixosSystem { inherit system; modules = [ @@ -78,7 +84,7 @@ config._module.args = { hostname = name; - machineConfig = (default args) // + machineConfig = (defaultMachine.config args) // (config args) // { inherit name; }; @@ -88,7 +94,56 @@ ./lib/configuration.nix (tryFiles [ ./lib/machines/${name}.nix ] ./lib/hardware/base.nix) ]; - }) - systems; - }); + }) + systems; + + homeConfigurations = + let + lib = nixpkgs.lib; + in + lib.attrsets.concatMapAttrs ( + hostname: machineDeclaration: + let + machine = machineDeclaration // defaultMachine // { + config = { ... }@args: ( + (defaultMachine.config args) // + (machineDeclaration.config args)); + }; + + pkgs = import nixpkgs { + inherit (machine) system; + }; + in + lib.attrsets.concatMapAttrs ( + username: user: { + "${username}@${hostname}" = { + modules = + let + userConfigPath = ( + tryFiles [ + ./lib/users/${username}/${hostname}.nix + ./lib/users/${username}/common.nix + ./lib/users/${username}.nix + ] + null); + in [ + ( + { pkgs, ... }: { + config._module.args = { + userConfig = { + inherit + hostname + username + ; + } // user; + }; + }) + sops-nix.homeManagerModules.sops + ./lib/home.nix + ] ++ (lib.optional (userConfigPath != null) userConfigPath); + }; + }) + (machine.config { inherit pkgs; }).users) + machines; + }); } diff --git a/lib/home.nix b/lib/home.nix new file mode 100644 index 0000000..4b2c5c4 --- /dev/null +++ b/lib/home.nix @@ -0,0 +1,2 @@ +{ ... }: { +}