From adc91138c584e67cd1e93d9185a99be8ee99fea4 Mon Sep 17 00:00:00 2001 From: Ryan Yin Date: Fri, 16 Aug 2024 10:33:07 +0800 Subject: [PATCH] feat: multi user --- flake.nix | 64 ++++++++++++++++++++-------------- home/{default.nix => core.nix} | 17 ++------- home/programs/browsers.nix | 5 +-- home/programs/git.nix | 5 ++- modules/system.nix | 12 +++---- users/ryan/home.nix | 22 ++++++++++++ users/ryan/nixos.nix | 14 ++++++++ users/suzi/home.nix | 22 ++++++++++++ users/suzi/nixos.nix | 14 ++++++++ 9 files changed, 122 insertions(+), 53 deletions(-) rename home/{default.nix => core.nix} (78%) create mode 100644 users/ryan/home.nix create mode 100644 users/ryan/nixos.nix create mode 100644 users/suzi/home.nix create mode 100644 users/suzi/nixos.nix diff --git a/flake.nix b/flake.nix index 64fedc7b..d5c78836 100644 --- a/flake.nix +++ b/flake.nix @@ -38,39 +38,51 @@ ... }: { nixosConfigurations = { - nixos-test = nixpkgs.lib.nixosSystem { - system = "x86_64-linux"; + nixos-test = let + username = "ryan"; + specialArgs = {inherit username;}; + in + nixpkgs.lib.nixosSystem { + inherit specialArgs; + system = "x86_64-linux"; - modules = [ - ./hosts/nixos-test + modules = [ + ./hosts/nixos-test + ./users/${username}/nixos.nix - home-manager.nixosModules.home-manager - { - home-manager.useGlobalPkgs = true; - home-manager.useUserPackages = true; + home-manager.nixosModules.home-manager + { + home-manager.useGlobalPkgs = true; + home-manager.useUserPackages = true; - home-manager.extraSpecialArgs = inputs; - home-manager.users.ryan = import ./home; - } - ]; - }; + home-manager.extraSpecialArgs = inputs // specialArgs; + home-manager.users.${username} = import ./users/${username}/home.nix; + } + ]; + }; - msi-rtx4090 = nixpkgs.lib.nixosSystem { - system = "x86_64-linux"; + msi-rtx4090 = let + username = "suzi"; # another username for this machine + specialArgs = {inherit username;}; + in + nixpkgs.lib.nixosSystem { + inherit specialArgs; + system = "x86_64-linux"; - modules = [ - ./hosts/msi-rtx4090 + modules = [ + ./hosts/msi-rtx4090 + ./users/${username}/nixos.nix - home-manager.nixosModules.home-manager - { - home-manager.useGlobalPkgs = true; - home-manager.useUserPackages = true; + home-manager.nixosModules.home-manager + { + home-manager.useGlobalPkgs = true; + home-manager.useUserPackages = true; - home-manager.extraSpecialArgs = inputs; - home-manager.users.ryan = import ./home; - } - ]; - }; + home-manager.extraSpecialArgs = inputs // specialArgs; + home-manager.users.${username} = import ./users/${username}/home.nix; + } + ]; + }; }; }; } diff --git a/home/default.nix b/home/core.nix similarity index 78% rename from home/default.nix rename to home/core.nix index df5a2041..0c5e9b3a 100644 --- a/home/default.nix +++ b/home/core.nix @@ -1,20 +1,9 @@ -{ config, pkgs, ... }: - -{ - - imports = [ - ./fcitx5 - ./i3 - ./programs - ./rofi - ./shell - ]; - +{username, ...}: { # Home Manager needs a bit of information about you and the # paths it should manage. home = { - username = "ryan"; - homeDirectory = "/home/ryan"; + inherit username; + homeDirectory = "/home/${username}"; # This value determines the Home Manager release that your # configuration is compatible with. This helps avoid breakage diff --git a/home/programs/browsers.nix b/home/programs/browsers.nix index d33c37ff..15c51bcd 100644 --- a/home/programs/browsers.nix +++ b/home/programs/browsers.nix @@ -1,6 +1,7 @@ { pkgs, config, + username, ... }: { programs = { @@ -14,7 +15,7 @@ firefox = { enable = true; - profiles.ryan = {}; + profiles.${username} = {}; }; }; -} \ No newline at end of file +} diff --git a/home/programs/git.nix b/home/programs/git.nix index 901b2068..efa546b9 100644 --- a/home/programs/git.nix +++ b/home/programs/git.nix @@ -7,7 +7,6 @@ programs.git = { enable = true; - userName = "Ryan Yin"; - userEmail = "xiaoyin_c@qq.com"; + # ... Other options ... }; -} \ No newline at end of file +} diff --git a/modules/system.nix b/modules/system.nix index c290ce78..d8b68496 100644 --- a/modules/system.nix +++ b/modules/system.nix @@ -1,20 +1,16 @@ { pkgs, lib, + username, ... -}: let - username = "ryan"; -in { +}: { # ============================= User related ============================= # Define a user account. Don't forget to set a password with ‘passwd’. - users.users.ryan = { + users.users.${username} = { isNormalUser = true; - description = "ryan"; + description = username; extraGroups = ["networkmanager" "wheel"]; - openssh.authorizedKeys.keys = [ - "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJx3Sk20pLL1b2PPKZey2oTyioODrErq83xG78YpFBoj admin@ryan-MBP" - ]; }; # given the users in this list the right to specify additional substituters via: # 1. `nixConfig.substituers` in `flake.nix` diff --git a/users/ryan/home.nix b/users/ryan/home.nix new file mode 100644 index 00000000..9583bcec --- /dev/null +++ b/users/ryan/home.nix @@ -0,0 +1,22 @@ +{pkgs, ...}: { + ################################################################################################################## + # + # All Ryan's Home Manager Configuration + # + ################################################################################################################## + + imports = [ + ../../home/core.nix + + ../../home/fcitx5 + ../../home/i3 + ../../home/programs + ../../home/rofi + ../../home/shell + ]; + + programs.git = { + userName = "Ryan Yin"; + userEmail = "xiaoyin_c@qq.com"; + }; +} diff --git a/users/ryan/nixos.nix b/users/ryan/nixos.nix new file mode 100644 index 00000000..3591ef5a --- /dev/null +++ b/users/ryan/nixos.nix @@ -0,0 +1,14 @@ +{ + ################################################################################################################## + # + # NixOS Configuration + # + ################################################################################################################## + + users.users.ryan = { + # Ryan's authorizedKeys + openssh.authorizedKeys.keys = [ + "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJx3Sk20pLL1b2PPKZey2oTyioODrErq83xG78YpFBoj ryan@ryan" + ]; + }; +} diff --git a/users/suzi/home.nix b/users/suzi/home.nix new file mode 100644 index 00000000..22189f55 --- /dev/null +++ b/users/suzi/home.nix @@ -0,0 +1,22 @@ +{pkgs, ...}: { + ################################################################################################################## + # + # All Suzi's Home Manager Configuration + # + ################################################################################################################## + + imports = [ + ../../home/core.nix + + ./fcitx5 + ./i3 + ./programs + ./rofi + ./shell + ]; + + programs.git = { + userName = "Suzi"; + userEmail = "suzi@writefor.fun"; + }; +} diff --git a/users/suzi/nixos.nix b/users/suzi/nixos.nix new file mode 100644 index 00000000..25504017 --- /dev/null +++ b/users/suzi/nixos.nix @@ -0,0 +1,14 @@ +{ + ################################################################################################################## + # + # NixOS Configuration + # + ################################################################################################################## + + users.users.suzi = { + # Suzi's authorizedKeys + openssh.authorizedKeys.keys = [ + "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJx3Sk20pLL1b2PPKZey2oTyioODrErq83xG78YpFBoj suzi@suzi" + ]; + }; +}