From 9e4d35969942c0d64b7554c783076da72217c5ef Mon Sep 17 00:00:00 2001 From: Jake Hamilton Date: Sat, 27 May 2023 12:24:20 -0700 Subject: [PATCH] wip: home-manager support --- lib/home/default.nix | 20 +++++++++++++------- lib/system/default.nix | 5 ++++- modules/darwin/home/default.nix | 31 +++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 8 deletions(-) create mode 100644 modules/darwin/home/default.nix diff --git a/lib/home/default.nix b/lib/home/default.nix index d4e0ad3..3f64fe1 100644 --- a/lib/home/default.nix +++ b/lib/home/default.nix @@ -1,7 +1,7 @@ { core-inputs, user-inputs, snowfall-lib }: let - inherit (core-inputs.nixpkgs.lib) assertMsg foldl head tail concatMap optionalAttrs mkIf filterAttrs mapAttrs' mkMerge mapAttrsToList optionals mkDefault; + inherit (core-inputs.nixpkgs.lib) assertMsg foldl head tail concatMap optionalAttrs mkIf filterAttrs mapAttrs' mkMerge mapAttrsToList optionals mkDefault mkAliasDefinitions; user-homes-root = snowfall-lib.fs.get-snowfall-file "homes"; user-modules-root = snowfall-lib.fs.get-snowfall-file "modules"; @@ -57,7 +57,10 @@ in output = "homeConfigurations"; - modules = [ path ] ++ modules; + modules = [ + path + ../../modules/home/user/default.nix + ] ++ modules; specialArgs = { inherit name; @@ -80,6 +83,9 @@ in (module-args: import ./nix-registry-module.nix (module-args // { inherit user-inputs core-inputs; })) + ({ + snowfallorg.user.name = mkDefault user-metadata.user; + }) ]; extraSpecialArgs = specialArgs // args.specialArgs; @@ -180,7 +186,7 @@ in # @NOTE(jakehamilton): We *must* specify named attributes here in order # for home-manager to provide them. - wrapped-user-module = home-args@{ pkgs, lib, ... }: + wrapped-user-module = home-args@{ pkgs, lib, osConfig ? {}, ... }: let user-module-result = import user-module home-args; user-imports = @@ -193,6 +199,7 @@ in user-module-result.config else builtins.removeAttrs user-module-result [ "imports" "options" "_file" ]; + user = created-user.specialArgs.user; in { _file = builtins.toString user-module; @@ -201,8 +208,9 @@ in config = mkMerge [ user-config ({ - snowfallorg.user.name = mkDefault created-user.specialArgs.user; + snowfallorg.user.name = mkDefault user; }) + (osConfig.snowfallorg.home.resolvedHomes.${user} or {}) ]; }; in @@ -212,9 +220,7 @@ in config = mkIf host-matches { home-manager = { users.${user-name} = wrapped-user-module; - sharedModules = other-modules ++ [ - ../../modules/home/user/default.nix - ]; + sharedModules = other-modules; }; }; } diff --git a/lib/system/default.nix b/lib/system/default.nix index 9df24f9..296bf3e 100644 --- a/lib/system/default.nix +++ b/lib/system/default.nix @@ -100,10 +100,13 @@ in darwin-system-builder = args: assert assertMsg (user-inputs ? darwin) "In order to create virtual systems, you must include `darwin` as a flake input."; user-inputs.darwin.lib.darwinSystem - ((builtins.removeAttrs args [ "system" ]) // { + ((builtins.removeAttrs args [ "system" "modules" ]) // { specialArgs = args.specialArgs // { format = "darwin"; }; + modules = args.modules ++ [ + ../../modules/darwin/home/default.nix + ]; }); linux-system-builder = args: core-inputs.nixpkgs.lib.nixosSystem diff --git a/modules/darwin/home/default.nix b/modules/darwin/home/default.nix new file mode 100644 index 0000000..7466dd8 --- /dev/null +++ b/modules/darwin/home/default.nix @@ -0,0 +1,31 @@ +{ lib, options, ... }: + +let + inherit (lib) types mkOption mkIf mkMerge mkAliasDefinitions; + + cfg = options.snowfallorg; +in +{ + options.snowfallorg = { + home = mkOption { + description = "Configuration for home-manager."; + type = types.attrsOf (types.submodule ({ name, ... }: { + options.config = { + type = types.attrs; + default = { }; + }; + })); + }; + + resolvedHomes = mkOption { + type = types.attrs; + default = { }; + }; + }; + + config = mkMerge (builtins.map + (name: { + snowfallorg.resolvedHomes.${name} = mkAliasDefinitions options.snowfallorg.home.${name}.config; + }) + (builtins.attrNames cfg.home)); +}