diff --git a/flake.lock b/flake.lock index 9f0d129..0f30101 100644 --- a/flake.lock +++ b/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": { diff --git a/flake.nix b/flake.nix index d5a6a09..d1b5d2a 100644 --- a/flake.nix +++ b/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 - ]; - }; }; } diff --git a/home.nix b/home.nix deleted file mode 100644 index 722fb48..0000000 --- a/home.nix +++ /dev/null @@ -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"; -} diff --git a/os/default.nix b/os/configuration.nix similarity index 94% rename from os/default.nix rename to os/configuration.nix index 14f966c..a7a2486 100644 --- a/os/default.nix +++ b/os/configuration.nix @@ -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"; diff --git a/user/desktop/default.nix b/os/desktop/core.nix similarity index 93% rename from user/desktop/default.nix rename to os/desktop/core.nix index c1c17b0..0a0288d 100644 --- a/user/desktop/default.nix +++ b/os/desktop/core.nix @@ -3,10 +3,6 @@ config, ... }: { - imports = [ - ./gnome.nix - ]; - home.packages = [ pkgs.noto-fonts pkgs.noto-fonts-emoji diff --git a/user/desktop/gnome.nix b/os/desktop/gnome.nix similarity index 100% rename from user/desktop/gnome.nix rename to os/desktop/gnome.nix diff --git a/user/desktop/nix-wallpaper.png b/os/desktop/nix-wallpaper.png similarity index 100% rename from user/desktop/nix-wallpaper.png rename to os/desktop/nix-wallpaper.png diff --git a/user/desktop/wallpaper.jpg b/os/desktop/wallpaper.jpg similarity index 100% rename from user/desktop/wallpaper.jpg rename to os/desktop/wallpaper.jpg diff --git a/user/dev/default.nix b/os/dev/default.nix similarity index 100% rename from user/dev/default.nix rename to os/dev/default.nix diff --git a/user/dev/lf-icons b/os/dev/lf-icons similarity index 100% rename from user/dev/lf-icons rename to os/dev/lf-icons diff --git a/user/dev/wezterm.lua b/os/dev/wezterm.lua similarity index 100% rename from user/dev/wezterm.lua rename to os/dev/wezterm.lua diff --git a/os/gnome_support.nix b/os/gnome_support.nix new file mode 100644 index 0000000..95e2fa9 --- /dev/null +++ b/os/gnome_support.nix @@ -0,0 +1,5 @@ +{ + services.xserver.displayManager.gdm.enable = true; + services.xserver.desktopManager.gnome.enable = true; + services.xserver.enable = true; +} diff --git a/user/id_dev.pub b/os/id_dev.pub similarity index 100% rename from user/id_dev.pub rename to os/id_dev.pub diff --git a/user/services.nix b/os/services.nix similarity index 100% rename from user/services.nix rename to os/services.nix diff --git a/user/shell/bash.nix b/os/shell/bash.nix similarity index 100% rename from user/shell/bash.nix rename to os/shell/bash.nix diff --git a/user/shell/prompt-zen.toml b/os/shell/prompt-zen.toml similarity index 100% rename from user/shell/prompt-zen.toml rename to os/shell/prompt-zen.toml diff --git a/user/shell/zsh.nix b/os/shell/zsh.nix similarity index 100% rename from user/shell/zsh.nix rename to os/shell/zsh.nix diff --git a/user/shell/zshrc b/os/shell/zshrc similarity index 100% rename from user/shell/zshrc rename to os/shell/zshrc diff --git a/os/users.nix b/os/users.nix new file mode 100644 index 0000000..ef69d90 --- /dev/null +++ b/os/users.nix @@ -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) + ]; + }; +} diff --git a/os/util/user.nix b/os/util/user.nix new file mode 100644 index 0000000..91eda7a --- /dev/null +++ b/os/util/user.nix @@ -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); + }; +} diff --git a/user/apps/default.nix b/user/apps/default.nix deleted file mode 100644 index 2783cec..0000000 --- a/user/apps/default.nix +++ /dev/null @@ -1,12 +0,0 @@ -{pkgs, ...}: { - home.packages = with pkgs; [ - nom - pinta - vesktop - signal-desktop - vesktop - blockbench - blender - prismlauncher - ]; -} diff --git a/user/apps/obs.nix b/user/apps/obs.nix deleted file mode 100644 index c9e1333..0000000 --- a/user/apps/obs.nix +++ /dev/null @@ -1,8 +0,0 @@ -{pkgs, ...}: { - programs.obs-studio = { - enable = true; - plugins = with pkgs.obs-studio-plugins; [ - wlrobs - ]; - }; -} diff --git a/user/users.nix b/user/users.nix deleted file mode 100644 index f1498db..0000000 --- a/user/users.nix +++ /dev/null @@ -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) - ]; - }; -}