feat: home-manager support
This commit is contained in:
parent
9e4d359699
commit
f85f831b33
8 changed files with 432 additions and 56 deletions
|
|
@ -1,31 +0,0 @@
|
|||
{ 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));
|
||||
}
|
||||
71
modules/darwin/user/default.nix
Normal file
71
modules/darwin/user/default.nix
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
{ pkgs, lib, options, config, ... }:
|
||||
|
||||
let
|
||||
inherit (lib) types mkOption mkDefault foldl optionalAttrs;
|
||||
|
||||
cfg = config.snowfallorg;
|
||||
|
||||
user-names = builtins.attrNames cfg.user;
|
||||
|
||||
create-system-users = system-users: name:
|
||||
let
|
||||
user = cfg.user.${name};
|
||||
in
|
||||
system-users // (optionalAttrs user.create {
|
||||
${name} = {
|
||||
home = mkDefault user.home.path;
|
||||
isHidden = mkDefault false;
|
||||
};
|
||||
});
|
||||
|
||||
create-resolved-home = resolved-homes: name:
|
||||
let
|
||||
user = cfg.user.${name};
|
||||
in
|
||||
resolved-homes // {
|
||||
${name} = user.home.config;
|
||||
};
|
||||
in
|
||||
{
|
||||
options.snowfallorg = {
|
||||
user = mkOption {
|
||||
description = "User configuration.";
|
||||
default = { };
|
||||
type = types.attrsOf (types.submodule ({ name, ... }: {
|
||||
options = {
|
||||
create = mkOption {
|
||||
description = "Whether to create the user automatically.";
|
||||
type = types.bool;
|
||||
default = true;
|
||||
};
|
||||
|
||||
home = {
|
||||
path = mkOption {
|
||||
type = types.str;
|
||||
default = "/Users/${name}";
|
||||
};
|
||||
|
||||
config = mkOption {
|
||||
type = types.attrs;
|
||||
default = { };
|
||||
};
|
||||
};
|
||||
};
|
||||
}));
|
||||
};
|
||||
|
||||
resolved-homes = mkOption {
|
||||
type = types.attrs;
|
||||
default = { };
|
||||
internal = true;
|
||||
};
|
||||
};
|
||||
|
||||
config = {
|
||||
users.users = (foldl (create-system-users) { } (user-names));
|
||||
|
||||
snowfallorg = {
|
||||
resolved-homes = (foldl (create-resolved-home) { } (user-names));
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
@ -1,23 +1,50 @@
|
|||
{ lib, options, ... }:
|
||||
inputs@{ pkgs, lib, options, config, ... }:
|
||||
|
||||
let
|
||||
inherit (lib) types mkOption mkIf;
|
||||
inherit (lib) types mkOption mkIf mkDefault;
|
||||
|
||||
cfg = options.snowfallorg;
|
||||
cfg = config.snowfallorg;
|
||||
|
||||
# @NOTE(jakehamilton): The module system chokes if it finds `osConfig` named in the module arguments
|
||||
# when being used in standalone home-manager. To remedy this, we have to refer to the arguments set directly.
|
||||
os-user-home = inputs.osConfig.users.users.${cfg.name}.home or null;
|
||||
|
||||
default-home-directory =
|
||||
if (os-user-home != null) then
|
||||
os-user-home
|
||||
else if pkgs.stdenv.isDarwin then
|
||||
"/Users/${cfg.user.name}"
|
||||
else
|
||||
"/home/${cfg.user.name}";
|
||||
in
|
||||
# (builtins.trace (cfg.user.name or "no name"))
|
||||
{
|
||||
options.snowfallorg = {
|
||||
user = {
|
||||
enable = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
description = "Whether to configure the user.";
|
||||
};
|
||||
|
||||
name = mkOption {
|
||||
type = types.str;
|
||||
description = "The user's name.";
|
||||
};
|
||||
|
||||
home = {
|
||||
directory = mkOption {
|
||||
type = types.str;
|
||||
description = "The user's home directory.";
|
||||
default = default-home-directory;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
# config = mkIf ((cfg.user.name or null) != null) {
|
||||
# @TODO(jakehamilton): Get user home directory from osConfig if
|
||||
# it exists.
|
||||
# };
|
||||
config = mkIf cfg.user.enable {
|
||||
home = {
|
||||
username = mkIf (cfg.user.name or null != null) (mkDefault cfg.user.name);
|
||||
homeDirectory = mkIf (cfg.user.name or null != null) (mkDefault cfg.user.home.directory);
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
84
modules/nixos/user/default.nix
Normal file
84
modules/nixos/user/default.nix
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
{ pkgs, lib, options, config, ... }:
|
||||
|
||||
let
|
||||
inherit (lib) types mkOption mkDefault foldl optionalAttrs optional;
|
||||
|
||||
cfg = config.snowfallorg;
|
||||
|
||||
user-names = builtins.attrNames cfg.user;
|
||||
|
||||
create-system-users = system-users: name:
|
||||
let
|
||||
user = cfg.user.${name};
|
||||
in
|
||||
system-users // (optionalAttrs user.create {
|
||||
${name} = {
|
||||
isNormalUser = mkDefault true;
|
||||
|
||||
name = mkDefault cfg.name;
|
||||
|
||||
home = mkDefault user.home.path;
|
||||
group = mkDefault "users";
|
||||
|
||||
extraGroups = (builtins.trace user.admin) optional user.admin "wheel";
|
||||
};
|
||||
});
|
||||
|
||||
create-resolved-home = resolved-homes: name:
|
||||
let
|
||||
user = cfg.user.${name};
|
||||
in
|
||||
resolved-homes // {
|
||||
${name} = user.home.config;
|
||||
};
|
||||
in
|
||||
(builtins.trace "hello")
|
||||
{
|
||||
options.snowfallorg = {
|
||||
user = mkOption {
|
||||
description = "User configuration.";
|
||||
default = { };
|
||||
type = types.attrsOf (types.submodule ({ name, ... }: {
|
||||
options = {
|
||||
create = mkOption {
|
||||
description = "Whether to create the user automatically.";
|
||||
type = types.bool;
|
||||
default = true;
|
||||
};
|
||||
|
||||
admin = mkOption {
|
||||
description = "Whether the user should be added to the wheel group.";
|
||||
type = types.bool;
|
||||
default = true;
|
||||
};
|
||||
|
||||
home = {
|
||||
path = mkOption {
|
||||
type = types.str;
|
||||
default = "/home/${name}";
|
||||
};
|
||||
|
||||
config = mkOption {
|
||||
type = types.attrs;
|
||||
default = { };
|
||||
};
|
||||
};
|
||||
};
|
||||
}));
|
||||
};
|
||||
|
||||
resolved-homes = mkOption {
|
||||
type = types.attrs;
|
||||
default = { };
|
||||
internal = true;
|
||||
};
|
||||
};
|
||||
|
||||
config = {
|
||||
users.users = (foldl (create-system-users) { } (user-names));
|
||||
|
||||
snowfallorg = {
|
||||
resolved-homes = (foldl (create-resolved-home) { } (user-names));
|
||||
};
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue