nix magic plus restructuring
(the magic is os/util/user.nix)
This commit is contained in:
parent
8d7d459b84
commit
61f78061a3
23 changed files with 372 additions and 127 deletions
30
flake.lock
30
flake.lock
|
@ -121,11 +121,11 @@
|
|||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1719582740,
|
||||
"narHash": "sha256-s4WsLu2L8EzF5Hg2TkelFLVhKGL108AySnlw8voPe5U=",
|
||||
"lastModified": 1719864345,
|
||||
"narHash": "sha256-e4Pw+30vFAxuvkSTaTypd9zYemB/QlWcH186dsGT+Ms=",
|
||||
"owner": "nix-community",
|
||||
"repo": "disko",
|
||||
"rev": "115311bc395f24c1b553338fec4b3aa28cbf5ae2",
|
||||
"rev": "544a80a69d6e2da04e4df7ec8210a858de8c7533",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -190,11 +190,11 @@
|
|||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1719588253,
|
||||
"narHash": "sha256-A03i8xiVgP14DCmV5P7VUv37eodCjY4e1iai0b2EuuM=",
|
||||
"lastModified": 1719827439,
|
||||
"narHash": "sha256-tneHOIv1lEavZ0vQ+rgz67LPNCgOZVByYki3OkSshFU=",
|
||||
"owner": "nix-community",
|
||||
"repo": "home-manager",
|
||||
"rev": "7e68e55d2e16d3a1e92a679430728c35a30fd24e",
|
||||
"rev": "59ce796b2563e19821361abbe2067c3bb4143a7d",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -264,11 +264,11 @@
|
|||
"xdph": "xdph"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1719613382,
|
||||
"narHash": "sha256-DAWdnk0cCFbOZrdo9Ku0kbrlpv7pjnF+DQBnLiyuSSQ=",
|
||||
"lastModified": 1719949580,
|
||||
"narHash": "sha256-Ht6ZUjQ6HO9vllB0CxeGgLYUzZCw9Q/2Aaq21Og+3hM=",
|
||||
"owner": "hyprwm",
|
||||
"repo": "Hyprland",
|
||||
"rev": "9c5dd59d4b1927b7d88e8e3c2e260eb01d95794b",
|
||||
"rev": "8bb75a223db3ea9471d05d74fbed3328334a9f78",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -436,11 +436,11 @@
|
|||
},
|
||||
"nixpkgs-unstable": {
|
||||
"locked": {
|
||||
"lastModified": 1719254875,
|
||||
"narHash": "sha256-ECni+IkwXjusHsm9Sexdtq8weAq/yUyt1TWIemXt3Ko=",
|
||||
"lastModified": 1719848872,
|
||||
"narHash": "sha256-H3+EC5cYuq+gQW8y0lSrrDZfH71LB4DAf+TDFyvwCNA=",
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "2893f56de08021cffd9b6b6dfc70fd9ccd51eb60",
|
||||
"rev": "00d80d13810dbfea8ab4ed1009b09100cca86ba8",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -452,11 +452,11 @@
|
|||
},
|
||||
"nixpkgs_2": {
|
||||
"locked": {
|
||||
"lastModified": 1719426051,
|
||||
"narHash": "sha256-yJL9VYQhaRM7xs0M867ZFxwaONB9T2Q4LnGo1WovuR4=",
|
||||
"lastModified": 1719838683,
|
||||
"narHash": "sha256-Zw9rQjHz1ilNIimEXFeVa1ERNRBF8DoXDhLAZq5B4pE=",
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "89c49874fb15f4124bf71ca5f42a04f2ee5825fd",
|
||||
"rev": "d032c1a6dfad4eedec7e35e91986becc699d7d69",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
|
22
flake.nix
22
flake.nix
|
@ -81,26 +81,18 @@
|
|||
inputs.disko.nixosModules.default
|
||||
(import ./disko.nix {device = "/dev/nvme1n1";})
|
||||
{networking.hostName = "waves";}
|
||||
./os
|
||||
./os/configuration.nix
|
||||
./waves-hardware.nix
|
||||
./user/users.nix
|
||||
inputs.impermanence.nixosModules.impermanence
|
||||
inputs.stylix.nixosModules.stylix
|
||||
inputs.home-manager.nixosModules.home-manager
|
||||
{
|
||||
home-manager.useGlobalPkgs = true;
|
||||
home-manager.useUserPackages = true;
|
||||
}
|
||||
./os/users.nix
|
||||
./os/styling.nix
|
||||
];
|
||||
};
|
||||
|
||||
homeConfigurations.deva = home-manager.lib.homeManagerConfiguration {
|
||||
pkgs = nixpkgs.legacyPackages.x86_64-linux;
|
||||
extraSpecialArgs = {inherit inputs outputs;};
|
||||
modules = [
|
||||
./home.nix
|
||||
./user/desktop
|
||||
./user/dev
|
||||
./user/shell/zsh.nix
|
||||
./user/services.nix
|
||||
./user/apps
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
47
home.nix
47
home.nix
|
@ -1,47 +0,0 @@
|
|||
{
|
||||
config,
|
||||
pkgs,
|
||||
inputs,
|
||||
outputs,
|
||||
...
|
||||
}: {
|
||||
home = {
|
||||
username = "deva";
|
||||
homeDirectory = "/home/deva";
|
||||
extraOutputsToInstall = ["doc" "devdoc"];
|
||||
packages = [
|
||||
inputs.nh.packages.x86_64-linux.default
|
||||
];
|
||||
sessionVariables = {
|
||||
NIX_AUTO_RUN = "1";
|
||||
FLAKE = "${config.home.homeDirectory}/nix";
|
||||
};
|
||||
};
|
||||
|
||||
nix.package = pkgs.nixVersions.latest;
|
||||
nixpkgs = {
|
||||
overlays = [
|
||||
outputs.overlays.additions
|
||||
outputs.overlays.modifications
|
||||
outputs.overlays.unstable-packages
|
||||
];
|
||||
config = {
|
||||
allowUnfree = true;
|
||||
};
|
||||
};
|
||||
nix.extraOptions = ''
|
||||
experimental-features = nix-command flakes
|
||||
'';
|
||||
|
||||
manual = {
|
||||
html.enable = true;
|
||||
json.enable = false;
|
||||
manpages.enable = false;
|
||||
};
|
||||
|
||||
programs.home-manager.enable = true;
|
||||
programs.git.enable = true;
|
||||
systemd.user.startServices = "sd-switch";
|
||||
|
||||
home.stateVersion = "24.05";
|
||||
}
|
|
@ -6,7 +6,7 @@
|
|||
inputs,
|
||||
...
|
||||
}: {
|
||||
nixpkgs.config.allowUnfree = true;
|
||||
nixpkgs.config = {allowUnfree = true;};
|
||||
nixpkgs.overlays = [
|
||||
outputs.overlays.additions
|
||||
outputs.overlays.modifications
|
||||
|
@ -28,6 +28,7 @@
|
|||
flake-registry = "";
|
||||
# Workaround for https://github.com/NixOS/nix/issues/9574
|
||||
nix-path = config.nix.nixPath;
|
||||
# allowUnfree = true;
|
||||
};
|
||||
# Opinionated: disable channels
|
||||
channel.enable = false;
|
||||
|
@ -88,7 +89,7 @@
|
|||
programs = {
|
||||
less.enable = true;
|
||||
|
||||
# default zsh config
|
||||
# default zsh config if not configured using home-manager
|
||||
zsh = {
|
||||
enable = true;
|
||||
enableCompletion = true;
|
||||
|
@ -110,10 +111,6 @@
|
|||
services.libinput.enable = true;
|
||||
services.printing.enable = true;
|
||||
|
||||
services.xserver.displayManager.gdm.enable = true;
|
||||
services.xserver.desktopManager.gnome.enable = true;
|
||||
services.xserver.enable = true;
|
||||
|
||||
# https://nixos.wiki/wiki/FAQ/When_do_I_update_stateVersion
|
||||
system.stateVersion = "24.05";
|
||||
|
|
@ -3,10 +3,6 @@
|
|||
config,
|
||||
...
|
||||
}: {
|
||||
imports = [
|
||||
./gnome.nix
|
||||
];
|
||||
|
||||
home.packages = [
|
||||
pkgs.noto-fonts
|
||||
pkgs.noto-fonts-emoji
|
Before Width: | Height: | Size: 3.1 MiB After Width: | Height: | Size: 3.1 MiB |
Before Width: | Height: | Size: 2.1 MiB After Width: | Height: | Size: 2.1 MiB |
5
os/gnome_support.nix
Normal file
5
os/gnome_support.nix
Normal file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
services.xserver.displayManager.gdm.enable = true;
|
||||
services.xserver.desktopManager.gnome.enable = true;
|
||||
services.xserver.enable = true;
|
||||
}
|
34
os/users.nix
Normal file
34
os/users.nix
Normal file
|
@ -0,0 +1,34 @@
|
|||
{pkgs, ...}: {
|
||||
imports = [./util/user.nix ./gnome_support.nix];
|
||||
|
||||
user.deva = {
|
||||
shell = "zsh";
|
||||
description = "Deva Waves";
|
||||
initialPassword = "12345";
|
||||
sudoer = true;
|
||||
developer = true;
|
||||
extraGroups = ["networkmanager" "audio" "docker" "input" "libvirtd" "plugdev" "video" "adbusers"];
|
||||
normalUser = true;
|
||||
desktopEnvironment = "gnome";
|
||||
obs = true;
|
||||
authorizedKeys = [
|
||||
(builtins.readFile ./id_dev.pub)
|
||||
];
|
||||
packages = with pkgs; [
|
||||
nom
|
||||
pinta
|
||||
vesktop
|
||||
signal-desktop
|
||||
blockbench
|
||||
blender
|
||||
prismlauncher
|
||||
];
|
||||
};
|
||||
user.root = {
|
||||
shell = "zsh";
|
||||
extraGroups = [];
|
||||
authorizedKeys = [
|
||||
(builtins.readFile ./id_dev.pub)
|
||||
];
|
||||
};
|
||||
}
|
308
os/util/user.nix
Normal file
308
os/util/user.nix
Normal file
|
@ -0,0 +1,308 @@
|
|||
{
|
||||
pkgs,
|
||||
lib,
|
||||
outputs,
|
||||
inputs,
|
||||
config,
|
||||
...
|
||||
}: let
|
||||
userOpts = {
|
||||
name,
|
||||
config,
|
||||
...
|
||||
}: {
|
||||
options = with lib; {
|
||||
allowUnfree = mkOption {
|
||||
type = with types; bool;
|
||||
default = true;
|
||||
description = "Whether or not to allow unfree packages for this user.";
|
||||
};
|
||||
username = mkOption {
|
||||
type = with types; nullOr str;
|
||||
default = null;
|
||||
description = "The username of the user, if undefined it uses the name of the attribute set.";
|
||||
};
|
||||
homeDirectory = mkOption {
|
||||
type = with types; nullOr str;
|
||||
default = null;
|
||||
description = "The home directory of the user.";
|
||||
};
|
||||
description = mkOption {
|
||||
type = with types; nullOr str;
|
||||
default = null;
|
||||
description = "The user's description. It is usually their full name.";
|
||||
};
|
||||
uid = mkOption {
|
||||
type = with types; nullOr int;
|
||||
default = null;
|
||||
description = "The user id of the user.";
|
||||
};
|
||||
initialPassword = mkOption {
|
||||
type = with types; nullOr str;
|
||||
default = null;
|
||||
description = "The initial password of the user.";
|
||||
};
|
||||
hashedPassword = mkOption {
|
||||
type = with types; nullOr str;
|
||||
default = null;
|
||||
description = "The hashed password of the user.";
|
||||
};
|
||||
initialHashedPassword = mkOption {
|
||||
type = with types; nullOr str;
|
||||
default = null;
|
||||
description = "The initial hashed password of the user.";
|
||||
};
|
||||
normalUser = mkOption {
|
||||
type = with types; bool;
|
||||
default = false;
|
||||
description = "Whether the user is a system user.";
|
||||
};
|
||||
desktopEnvironment = mkOption {
|
||||
type = with types; nullOr (enum ["gnome" "hyprland" "bspwm"]);
|
||||
default = null;
|
||||
description = "The desktop environment of the user.";
|
||||
};
|
||||
developer = mkOption {
|
||||
type = with types; bool;
|
||||
default = false;
|
||||
description = "Whether or not the user is a developer.";
|
||||
};
|
||||
sudoer = mkOption {
|
||||
type = with types; bool;
|
||||
default = false;
|
||||
description = "Whether or not the user has access to sudo.";
|
||||
};
|
||||
obs = mkOption {
|
||||
type = with types; bool;
|
||||
default = false;
|
||||
description = "Whether or not the user requires OBS.";
|
||||
};
|
||||
authorizedKeys = mkOption {
|
||||
type = with types; listOf str;
|
||||
default = [];
|
||||
description = "List of Authorized SSH Keys for the user.";
|
||||
};
|
||||
extraGroups = mkOption {
|
||||
type = with types; listOf str;
|
||||
default = [];
|
||||
description = "Extra groups to put the user in.";
|
||||
};
|
||||
packages = mkOption {
|
||||
type = with types; listOf package;
|
||||
default = [];
|
||||
description = "The user's packages.";
|
||||
};
|
||||
shell = mkOption {
|
||||
type = with types; enum ["bash" "zsh"];
|
||||
default = "zsh";
|
||||
description = "The user's shell.";
|
||||
};
|
||||
};
|
||||
config = with lib;
|
||||
mkMerge [
|
||||
{
|
||||
shell = mkDefault "zsh";
|
||||
}
|
||||
];
|
||||
};
|
||||
in {
|
||||
options = with lib; {
|
||||
user = mkOption {
|
||||
type = with types; attrsOf (submodule userOpts);
|
||||
default = {};
|
||||
example = {
|
||||
deva = {
|
||||
shell = "zsh";
|
||||
sudoer = true;
|
||||
developer = true;
|
||||
desktopEnvironment = "gnome";
|
||||
obs = true;
|
||||
name = "Deva Waves";
|
||||
};
|
||||
root = {
|
||||
shell = "zsh";
|
||||
authorizedKeys = [];
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
config = let
|
||||
mkIfNoValue = lib.mkOverride 1500;
|
||||
in {
|
||||
users.users = lib.mkIf (config.user != null) (lib.attrsets.mapAttrs (name: userConfig: {
|
||||
uid = (
|
||||
if userConfig.uid != null
|
||||
then userConfig.uid
|
||||
else mkIfNoValue null
|
||||
);
|
||||
initialPassword = (
|
||||
if userConfig.initialPassword != null
|
||||
then userConfig.initialPassword
|
||||
else mkIfNoValue null
|
||||
);
|
||||
hashedPassword = (
|
||||
if userConfig.hashedPassword != null
|
||||
then userConfig.hashedPassword
|
||||
else mkIfNoValue null
|
||||
);
|
||||
initialHashedPassword = (
|
||||
if userConfig.initialHashedPassword != null
|
||||
then userConfig.initialHashedPassword
|
||||
else mkIfNoValue null
|
||||
);
|
||||
description = (
|
||||
if userConfig.description != null
|
||||
then userConfig.description
|
||||
else mkIfNoValue "${name}"
|
||||
);
|
||||
shell = pkgs.${userConfig.shell};
|
||||
openssh.authorizedKeys.keys = userConfig.authorizedKeys or [];
|
||||
isNormalUser =
|
||||
if userConfig.normalUser
|
||||
then true
|
||||
else mkIfNoValue false;
|
||||
name =
|
||||
if userConfig.username != null
|
||||
then userConfig.username
|
||||
else mkIfNoValue name;
|
||||
extraGroups =
|
||||
(
|
||||
if userConfig.extraGroups != null
|
||||
then userConfig.extraGroups
|
||||
else mkIfNoValue []
|
||||
)
|
||||
++ (
|
||||
if userConfig.sudoer
|
||||
then ["wheel"]
|
||||
else []
|
||||
);
|
||||
})
|
||||
config.user);
|
||||
|
||||
home-manager.users = lib.mkIf (config.user != null) (lib.attrsets.mapAttrs (name: userConfig: {
|
||||
imports =
|
||||
[]
|
||||
++ (
|
||||
if name != "root"
|
||||
then [
|
||||
../services.nix
|
||||
]
|
||||
else []
|
||||
)
|
||||
++ (
|
||||
if userConfig.developer
|
||||
then [
|
||||
../dev
|
||||
]
|
||||
else []
|
||||
)
|
||||
++ (
|
||||
if userConfig.shell == "zsh"
|
||||
then [
|
||||
../shell/zsh.nix
|
||||
]
|
||||
else []
|
||||
)
|
||||
++ (
|
||||
if userConfig.shell == "bash"
|
||||
then [
|
||||
../shell/bash.nix
|
||||
]
|
||||
else []
|
||||
)
|
||||
++ (
|
||||
if userConfig.obs
|
||||
then [
|
||||
{
|
||||
programs.obs-studio = {
|
||||
enable = true;
|
||||
plugins = with pkgs.obs-studio-plugins; [
|
||||
wlrobs
|
||||
];
|
||||
};
|
||||
}
|
||||
]
|
||||
else []
|
||||
)
|
||||
++ (
|
||||
if userConfig.desktopEnvironment == "gnome"
|
||||
then [
|
||||
../desktop/gnome.nix
|
||||
]
|
||||
else []
|
||||
)
|
||||
++ (
|
||||
if userConfig.desktopEnvironment == "hyprland"
|
||||
then [
|
||||
../desktop/hyprland.nix
|
||||
]
|
||||
else []
|
||||
)
|
||||
++ (
|
||||
if userConfig.desktopEnvironment == "bspwm"
|
||||
then [
|
||||
../desktop/bspwm.nix
|
||||
]
|
||||
else []
|
||||
);
|
||||
|
||||
home = {
|
||||
username =
|
||||
if userConfig.username != null
|
||||
then userConfig.username
|
||||
else mkIfNoValue name;
|
||||
homeDirectory =
|
||||
if userConfig.homeDirectory != null
|
||||
then userConfig.homeDirectory
|
||||
else
|
||||
mkIfNoValue "/home/${(
|
||||
if userConfig.username != null
|
||||
then userConfig.username
|
||||
else name
|
||||
)}";
|
||||
extraOutputsToInstall = ["doc" "devdoc"];
|
||||
packages =
|
||||
[
|
||||
inputs.nh.packages.x86_64-linux.default
|
||||
]
|
||||
++ userConfig.packages or [];
|
||||
sessionVariables = {
|
||||
NIX_AUTO_RUN = "1";
|
||||
FLAKE = "${config.home-manager.users.${name}.home.homeDirectory}/nix";
|
||||
};
|
||||
stateVersion = "24.05";
|
||||
};
|
||||
|
||||
nixpkgs =
|
||||
if config.home-manager.useGlobalPkgs != true
|
||||
then {
|
||||
overlays = [
|
||||
outputs.overlays.additions
|
||||
outputs.overlays.modifications
|
||||
outputs.overlays.unstable-packages
|
||||
];
|
||||
config = {
|
||||
allowUnfree =
|
||||
if userConfig.allowUnfree != true
|
||||
then false
|
||||
else mkIfNoValue true;
|
||||
};
|
||||
}
|
||||
else mkIfNoValue {};
|
||||
nix.package = lib.mkForce pkgs.unstable.nixVersions.latest;
|
||||
nix.extraOptions = ''
|
||||
experimental-features = nix-command flakes
|
||||
'';
|
||||
manual = {
|
||||
html.enable = false;
|
||||
json.enable = false;
|
||||
manpages.enable = false;
|
||||
};
|
||||
programs.home-manager.enable = true;
|
||||
programs.git.enable = true;
|
||||
systemd.user.startServices = "sd-switch";
|
||||
})
|
||||
config.user);
|
||||
};
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
{pkgs, ...}: {
|
||||
home.packages = with pkgs; [
|
||||
nom
|
||||
pinta
|
||||
vesktop
|
||||
signal-desktop
|
||||
vesktop
|
||||
blockbench
|
||||
blender
|
||||
prismlauncher
|
||||
];
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
{pkgs, ...}: {
|
||||
programs.obs-studio = {
|
||||
enable = true;
|
||||
plugins = with pkgs.obs-studio-plugins; [
|
||||
wlrobs
|
||||
];
|
||||
};
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
{pkgs, ...}: {
|
||||
users.users.deva = {
|
||||
isNormalUser = true;
|
||||
shell = pkgs.zsh;
|
||||
description = "Deva Waves";
|
||||
initialPassword = "12345";
|
||||
extraGroups = ["wheel" "networkmanager" "audio" "docker" "input" "libvirtd" "plugdev" "video" "adbusers"];
|
||||
|
||||
openssh.authorizedKeys.keys = [
|
||||
(builtins.readFile ./id_dev.pub)
|
||||
];
|
||||
};
|
||||
|
||||
users.users.root = {
|
||||
shell = pkgs.zsh;
|
||||
openssh.authorizedKeys.keys = [
|
||||
(builtins.readFile ./id_dev.pub)
|
||||
];
|
||||
};
|
||||
}
|
Loading…
Reference in a new issue