feat: systems/set-user
Small "helper" for handling users
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
{
|
||||
imports = [
|
||||
../../modules/nixos/config/host.nix
|
||||
../../modules/nixos/systems/set-user.nix
|
||||
# Include the results of the hardware scan.
|
||||
./hardware-configuration.nix
|
||||
];
|
||||
@@ -26,27 +27,17 @@
|
||||
|
||||
programs.zsh.enable = true;
|
||||
# Define a user account. Don't forget to set a password with ‘passwd’.
|
||||
users.users."guz" = {
|
||||
isNormalUser = true;
|
||||
description = "Guz";
|
||||
extraGroups = [ "networkmanager" "wheel" ];
|
||||
packages = with pkgs; [
|
||||
firefox
|
||||
# thunderbird
|
||||
];
|
||||
shell = pkgs.zsh;
|
||||
};
|
||||
|
||||
home-manager = {
|
||||
extraSpecialArgs = { inherit inputs; };
|
||||
users = {
|
||||
"guz" = import ./home.nix;
|
||||
};
|
||||
};
|
||||
set-user.users = [
|
||||
{
|
||||
username = "guz";
|
||||
shell = pkgs.zsh;
|
||||
home = import ./home.nix;
|
||||
}
|
||||
];
|
||||
|
||||
services.flatpak.enable = true;
|
||||
|
||||
environment.pathsToLink = [ "/share/zsh" ];
|
||||
environment.pathsToLink = [ " /share/zsh " ];
|
||||
|
||||
# Some programs need SUID wrappers, can be configured further or are
|
||||
# started in user sessions.
|
||||
@@ -69,3 +60,4 @@
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -2,31 +2,11 @@
|
||||
|
||||
{
|
||||
imports = [
|
||||
# inputs.flatpaks.homeManagerModules.default
|
||||
inputs.nix-flatpak.homeManagerModules.nix-flatpak
|
||||
../../modules/home-manager/theme.nix
|
||||
../../modules/home-manager/config/terminal.nix
|
||||
];
|
||||
|
||||
# theme.accent = "f38ba8";
|
||||
# Home Manager needs a bit of information about you and the paths it should
|
||||
# manage.
|
||||
home.username = "guz";
|
||||
home.homeDirectory = "/home/guz";
|
||||
|
||||
|
||||
# This value determines the Home Manager release that your configuration is
|
||||
# compatible with. This helps avoid breakage when a new Home Manager release
|
||||
# introduces backwards incompatible changes.
|
||||
#
|
||||
# You should not change this value, even if you update Home Manager. If you do
|
||||
# want to update the value, then make sure to first check the Home Manager
|
||||
# release notes.
|
||||
home.stateVersion = "23.11"; # Please read the comment before changing.
|
||||
|
||||
# The home.packages option allows you to install Nix packages into your
|
||||
# environment.
|
||||
|
||||
|
||||
programs.bash = {
|
||||
enable = true;
|
||||
@@ -46,6 +26,7 @@
|
||||
];
|
||||
home.packages = with pkgs; [
|
||||
obsidian
|
||||
firefox
|
||||
# # It is sometimes useful to fine-tune packages, for example, by applying
|
||||
# # overrides. You can do that directly here, just don't forget the
|
||||
# # parentheses. Maybe you want to install Nerd Fonts with a limited number of
|
||||
@@ -94,7 +75,4 @@
|
||||
home.sessionVariables = {
|
||||
# EDITOR = "emacs";
|
||||
};
|
||||
|
||||
# Let Home Manager install and manage itself.
|
||||
programs.home-manager.enable = true;
|
||||
}
|
||||
|
||||
74
modules/nixos/systems/set-user.nix
Normal file
74
modules/nixos/systems/set-user.nix
Normal file
@@ -0,0 +1,74 @@
|
||||
{ config, pkgs, inputs, lib, ... }:
|
||||
|
||||
let
|
||||
cfg = config.set-user;
|
||||
in
|
||||
{
|
||||
options.set-user = {
|
||||
users = lib.mkOption {
|
||||
default = [ ];
|
||||
# TODO: Fix types
|
||||
/* type = lib.types.listOf {
|
||||
username = lib.types.str;
|
||||
description = lib.types.str;
|
||||
normalUser = lib.types.bool;
|
||||
shell = lib.types.package;
|
||||
packages = lib.types.pkgs;
|
||||
extraGroups = lib.types.listOf lib.types.str;
|
||||
home = lib.types.anything;
|
||||
flatpak = lib.types.bool;
|
||||
}; */
|
||||
};
|
||||
};
|
||||
config =
|
||||
let
|
||||
home-default = user: {
|
||||
imports = [
|
||||
(
|
||||
if user?flatpak && !user.flatpak
|
||||
then null
|
||||
else inputs.nix-flatpak.homeManagerModules.nix-flatpak
|
||||
)
|
||||
];
|
||||
programs.home-manager.enable = true;
|
||||
home.username = user.username;
|
||||
home.homeDirectory = "/home/${user.username}";
|
||||
home.stateVersion = "23.11"; # Do not change
|
||||
};
|
||||
in
|
||||
{
|
||||
users.users = (builtins.listToAttrs
|
||||
(map
|
||||
(u: {
|
||||
name = u.username;
|
||||
value = {
|
||||
description =
|
||||
if u?description then u.description else u.username;
|
||||
isNormalUser =
|
||||
if u?normalUser then u.normalUser else true;
|
||||
shell =
|
||||
if u?shell then u.shell else pkgs.bash;
|
||||
packages =
|
||||
if u?packages then u.packages else [ ];
|
||||
extraGroups =
|
||||
if u?extraGroups then u.extraGroups else [ "networkmanager" "wheel" ];
|
||||
};
|
||||
})
|
||||
cfg.users
|
||||
)
|
||||
);
|
||||
home-manager.extraSpecialArgs = { inherit inputs; };
|
||||
home-manager.users = (builtins.listToAttrs
|
||||
(map
|
||||
(u: {
|
||||
name = u.username;
|
||||
value =
|
||||
if u?home then lib.mkMerge [ (home-default u) u.home ]
|
||||
else (home-default u);
|
||||
})
|
||||
cfg.users
|
||||
)
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user