wip: better home-manager integration

This commit is contained in:
Jake Hamilton 2023-04-10 16:50:47 -07:00
parent 17ef1c563d
commit 4d6fdba390
No known key found for this signature in database
GPG key ID: 9762169A1B35EA68
6 changed files with 57 additions and 112 deletions

View file

@ -38,5 +38,9 @@
in in
{ {
inherit mkLib mkFlake; inherit mkLib mkFlake;
homeModules = {
user = ./user/default.nix;
};
}; };
} }

View file

@ -1,7 +1,7 @@
{ core-inputs, user-inputs, snowfall-lib }: { core-inputs, user-inputs, snowfall-lib }:
let let
inherit (core-inputs.nixpkgs.lib) assertMsg foldl head tail concatMap optionalAttrs mkIf filterAttrs mapAttrs' mkMerge mapAttrsToList; inherit (core-inputs.nixpkgs.lib) assertMsg foldl head tail concatMap optionalAttrs mkIf filterAttrs mapAttrs' mkMerge mapAttrsToList optionals mkDefault;
user-homes-root = snowfall-lib.fs.get-snowfall-file "homes"; user-homes-root = snowfall-lib.fs.get-snowfall-file "homes";
user-modules-root = snowfall-lib.fs.get-snowfall-file "modules"; user-modules-root = snowfall-lib.fs.get-snowfall-file "modules";
@ -157,7 +157,6 @@ in
inherit system target format virtual systems host; inherit system target format virtual systems host;
lib = home-lib; lib = home-lib;
# pkgs = user-inputs.self.pkgs.${system}.nixpkgs;
inputs = snowfall-lib.flake.without-src user-inputs; inputs = snowfall-lib.flake.without-src user-inputs;
}; };
@ -179,30 +178,43 @@ in
let let
host-matches = created-user.specialArgs.host == host; host-matches = created-user.specialArgs.host == host;
wrapped-user-module = home-args: # @NOTE(jakehamilton): We *must* specify named attributes here in order
# for home-manager to provide them.
wrapped-user-module = home-args@{ pkgs, lib, ... }:
let let
modified-args = args // { user-module-result = import user-module home-args;
inherit (created-user.specialArgs) user; user-imports =
}; if user-module-result ? imports then
user-module-result = (import user-module (home-args // modified-args)) // { user-module-result.imports
_file = user-module; else
}; [ ];
user-config =
if user-module-result ? config then
user-module-result.config
else
builtins.removeAttrs user-module-result [ "imports" "options" "_file" ];
in in
user-module-result; {
_file = builtins.toString user-module;
imports = user-imports;
config = mkMerge [
user-config
({
snowfallorg.user.name = mkDefault created-user.specialArgs.user;
})
];
};
in in
{ {
_file = "virtual:snowfallorg/home/user/${name}"; _file = "virtual:snowfallorg/home/user/${name}";
imports =
if snowfall-lib.system.is-darwin created-user.system then
[ ../../modules/darwin/home/default.nix ]
else
[ ../../modules/nixos/home/default.nix ];
config = mkIf host-matches { config = mkIf host-matches {
home-manager = { home-manager = {
users.${user-name} = wrapped-user-module args; users.${user-name} = wrapped-user-module;
sharedModules = other-modules; sharedModules = other-modules ++ [
../../modules/home/user/default.nix
];
}; };
}; };
} }

View file

@ -1,33 +0,0 @@
{ lib, config, ... }:
let
inherit (lib) types mkOption mkMerge mapAttrsToList;
home-submodule = { name, ... }: {
options = {
proxy = mkOption {
type = types.attrs;
default = { };
description = "Configuration to be proxied to the home-manager configuration for `home-manager.users.<name>`.";
};
};
};
cfg = config.snowfallorg;
in
{
options.snowfallorg = {
home = mkOption {
type = types.attrsOf (types.submodule home-submodule);
default = { };
description = "Options for configuring home environments.";
};
};
config = mkMerge
(mapAttrsToList
(name: value: {
home-manager.users.${name} = value.proxy;
})
(cfg.home));
}

View file

@ -1,28 +0,0 @@
{ lib, osConfig ? { }, ... }:
let
inherit (lib) types mkOption;
home-submodule = { name, ... }: {
options = {
proxy = mkOption {
type = types.attrs;
default = { };
description = "Configuration to be proxied to the home-manager configuration for `home-manager.users.<name>`.";
};
};
};
in
{
options.snowfallorg = {
home = mkOption {
type = types.attrsOf (types.submodule home-submodule);
default = { };
description = "Options for configuring home environments.";
};
};
config = {
# snowfallorg.home = osConfig.snowfallorg.home or { };
};
}

View file

@ -0,0 +1,23 @@
{ lib, options, ... }:
let
inherit (lib) types mkOption mkIf;
cfg = options.snowfallorg;
in
# (builtins.trace (cfg.user.name or "no name"))
{
options.snowfallorg = {
user = {
name = mkOption {
type = types.str;
description = "The user's name.";
};
};
};
# config = mkIf ((cfg.user.name or null) != null) {
# @TODO(jakehamilton): Get user home directory from osConfig if
# it exists.
# };
}

View file

@ -1,33 +0,0 @@
{ lib, config, ... }:
let
inherit (lib) types mkOption mkMerge mapAttrsToList;
home-submodule = { name, ... }: {
options = {
proxy = mkOption {
type = types.attrs;
default = { };
description = "Configuration to be proxied to the home-manager configuration for `home-manager.users.<name>`.";
};
};
};
cfg = config.snowfallorg;
in
{
options.snowfallorg = {
home = mkOption {
type = types.attrsOf (types.submodule home-submodule);
default = { };
description = "Options for configuring home environments.";
};
};
config = mkMerge
(mapAttrsToList
(name: value: {
home-manager.users.${name} = value.proxy;
})
(cfg.home));
}