Skip to content

Commit

Permalink
✨ (users): Support multi-user on my nixos module
Browse files Browse the repository at this point in the history
Also added screenshots in the documentation.
  • Loading branch information
theobori committed Nov 16, 2024
1 parent cae6b1f commit 2874645
Show file tree
Hide file tree
Showing 26 changed files with 218 additions and 132 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ works:
This structured approach to Nix configuration makes it easier to manage and
customize your Nix environment while maintaining flexibility and modularity.

## Screenshots

My NixOS KDE Plasma 6 environment looks like this.

![sddm](./docs/docs/images/sddm.png)
![home](./docs/docs/images/home.png)
![launcher](./docs/docs/images/launcher.png)
![neofetch](./docs/docs/images/neofetch.png)

## Resources

Other configurations from where I learned and copied:
Expand Down
Binary file added docs/docs/images/home.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/docs/images/launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/docs/images/neofetch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/docs/images/sddm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions docs/docs/screenshots.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Screenshots

My NixOS KDE Plasma 6 environment looks like this.

![sddm](./images/sddm.png)
![home](./images/home.png)
![launcher](./images/launcher.png)
![neofetch](./images/neofetch.png)
1 change: 1 addition & 0 deletions docs/docs/tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ Here are a non-exhaustive list of tasks.
- [x] Use [nixcord](https://github.com/KaylorBen/nixcord) to entirely manage Discord with Nix declarations
- [x] Add a working GNOME desktop environment
- [x] Fix `gpg-agent` not finding a pinetry binary
- [x] Support multi-user on my user nixos module
- [ ] Better email accounts management
1 change: 1 addition & 0 deletions docs/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ nav:
- Features: features.md
- Customization: customization.md
- Resources: resources.md
- Screenshots: screenshots.md
- Tasks: tasks.md

plugins:
Expand Down
1 change: 0 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@
stylix.nixosModules.stylix
home-manager.nixosModules.home-manager
disko.nixosModules.disko
sops-nix.nixosModules.sops
];
};
};
Expand Down
20 changes: 20 additions & 0 deletions homes/x86_64-linux/nagi@vm/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{ lib, namespace, ... }:
let
inherit (lib.${namespace}) enabled;
in
{
theobori-nix = {
roles = {
desktop = enabled;
};

user = {
enable = true;
name = "nagi";
};

desktops.addons.plasma6 = enabled;
};

home.stateVersion = "24.11";
}
1 change: 0 additions & 1 deletion homes/x86_64-linux/theobori@laptop/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ in
cli.programs = {
ssh.useSops = true;
gpg.useSops = true;
age.useSops = true;
};

services = {
Expand Down
14 changes: 1 addition & 13 deletions modules/home/cli/programs/age/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,18 @@
config,
lib,
namespace,
host,
...
}:
let
inherit (lib) mkIf;
inherit (lib.${namespace}) mkBoolOpt;
inherit (config.${namespace}) user;

cfg = config.${namespace}.cli.programs.age;
in
{
options.${namespace}.cli.programs.age = {
enable = mkBoolOpt false "Whether or not to enable age.";
useSops = mkBoolOpt false "Whether or not to use SOPS.";
};

config = mkIf cfg.enable {
home.packages = with pkgs; [ age ];

sops.secrets = mkIf (config."${namespace}".services.sops.enable && cfg.useSops) {
age_keys = {
sopsFile = lib.snowfall.fs.get-file "secrets/${host}/${user.name}/secrets.yaml";
path = "${config.home.homeDirectory}/sops/age/keys.txt";
};
};
};
config = mkIf cfg.enable { home.packages = with pkgs; [ age ]; };
}
13 changes: 5 additions & 8 deletions modules/home/cli/programs/eza/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
pkgs,
config,
lib,
namespace,
Expand All @@ -8,16 +9,12 @@ let
inherit (lib) mkIf;
inherit (lib.${namespace}) mkBoolOpt;

cfg = config.${namespace}.cli.programs.eza;
cfg = config.${namespace}.cli.programs.screen;
in
{
options.${namespace}.cli.programs.eza = {
enable = mkBoolOpt false "Whether or not to enable eza.";
options.${namespace}.cli.programs.screen = {
enable = mkBoolOpt false "Whether or not to enable screen.";
};

config = mkIf cfg.enable {
programs.eza = {
enable = true;
};
};
config = mkIf cfg.enable { home.packages = with pkgs; [ screen ]; };
}
1 change: 1 addition & 0 deletions modules/home/cli/programs/git/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ in
core = {
editor = "emacs";
pager = "delta";
filemode = "false";
};

color = {
Expand Down
23 changes: 23 additions & 0 deletions modules/home/cli/programs/screen/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
config,
lib,
namespace,
...
}:
let
inherit (lib) mkIf;
inherit (lib.${namespace}) mkBoolOpt;

cfg = config.${namespace}.cli.programs.eza;
in
{
options.${namespace}.cli.programs.eza = {
enable = mkBoolOpt false "Whether or not to enable eza.";
};

config = mkIf cfg.enable {
programs.eza = {
enable = true;
};
};
}
2 changes: 1 addition & 1 deletion modules/home/messages/discord/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ in
programs.nixcord = {
enable = true;
discord = disabled;
vesktop.enable = true;
vesktop = enabled;

inherit (cfg) config quickCss;
};
Expand Down
1 change: 1 addition & 0 deletions modules/home/roles/development/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ in
modern-unix = enabled;
network-tools = enabled;
nix-index = enabled;
screen = enabled;
ssh = enabled;
starship = enabled;
yazi = enabled;
Expand Down
10 changes: 5 additions & 5 deletions modules/nixos/cli/programs/nh/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@
...
}:
let
inherit (lib) mkIf;
inherit (lib.${namespace}) mkBoolOpt;
inherit (lib) mkIf types;
inherit (lib.${namespace}) mkOpt mkBoolOpt;

cfg = config.${namespace}.cli.programs.nh;
userName = config.${namespace}.user.name;
in
{
options.${namespace}.cli.programs.nh = {
options.${namespace}.cli.programs.nh = with types; {
enable = mkBoolOpt false "Whether or not to enable nh.";
flake = mkOpt str "/etc/nixos/${namespace}" "NixOS flake configuration path";
};

config = mkIf cfg.enable {
programs.nh = {
enable = true;
clean.enable = true;
clean.extraArgs = "--keep-since 4d --keep 3";
flake = "/home/${userName}/${namespace}";
inherit (cfg) flake;
};
};
}
2 changes: 1 addition & 1 deletion modules/nixos/security/doas/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ in
enable = true;
extraRules = [
{
users = [ config.${namespace}.user.name ];
users = builtins.attrNames config.${namespace}.user.users;
noPass = false;
keepEnv = true;
}
Expand Down
30 changes: 0 additions & 30 deletions modules/nixos/security/sops/default.nix

This file was deleted.

63 changes: 37 additions & 26 deletions modules/nixos/user/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,55 @@
...
}:
let
inherit (lib) types;
inherit (lib) types mapAttrs;
inherit (lib.${namespace}) mkOpt enabled;

cfg = config.${namespace}.user;

userModule = types.submodule {
options = with types; {
extraGroups = mkOpt (listOf str) [ ] "Groups for the user to be assigned.";
extraOptions = mkOpt attrs { } "Extra options passed to <option>users.users.<name></option>.";
initialPassword = mkOpt str "1" "The initial password to use when the user is first created.";
shell = mkOpt package pkgs.fish "Default shell package";
};
};
in
{
options.${namespace}.user = with types; {
extraGroups = mkOpt (listOf str) [ ] "Groups for the user to be assigned.";
extraOptions = mkOpt attrs { } "Extra options passed to <option>users.users.<name></option>.";
initialPassword = mkOpt str "1" "The initial password to use when the user is first created.";
name = mkOpt str "theobori" "The name to use for the user account.";
users = mkOpt (attrsOf userModule) { } "Attributes set representing every user on the system.";
};

config = {
programs.fish = enabled;

users.users.${cfg.name} = {
isNormalUser = true;
inherit (cfg) name initialPassword;
home = "/home/${cfg.name}";
group = "users";
shell = pkgs.fish;
users.users = mapAttrs (
name: user:
{
inherit name;
inherit (user) initialPassword shell;

isNormalUser = true;
home = "/home/${name}";
group = "users";

extraGroups = [
"wheel"
"audio"
"sound"
"video"
"networkmanager"
"input"
"tty"
"kvm"
"libvirtd"
"nix"
"power"
"docker"
] ++ cfg.extraGroups;
} // cfg.extraOptions;
extraGroups = [
"wheel"
"audio"
"sound"
"video"
"networkmanager"
"input"
"tty"
"kvm"
"libvirtd"
"nix"
"power"
"docker"
] ++ user.extraGroups;
}
// user.extraOptions
) cfg.users;

home-manager = {
useGlobalPkgs = true;
Expand Down
9 changes: 6 additions & 3 deletions systems/x86_64-install-iso/minimal/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ in
boot.loader.systemd-boot = enabled;
boot.loader.efi.canTouchEfiVariables = true;

boot.supportedFilesystems = [ "ntfs" ];

networking.wireless.enable = lib.mkForce false;
networking.networkmanager = enabled;

Expand All @@ -29,9 +31,10 @@ in
locale = enabled;
};

user = {
name = "nixos";
initialPassword = "1";
user.users = {
nixos = {
initialPassword = "1";
};
};
};

Expand Down
Loading

0 comments on commit 2874645

Please sign in to comment.