diff --git a/modules/system/user-parts.nix b/modules/system/user-parts.nix index 5540b11..acf5766 100644 --- a/modules/system/user-parts.nix +++ b/modules/system/user-parts.nix @@ -3,48 +3,61 @@ { # user parts module declaration - # use `${user-parts..variable};` - # in place of regular declarations. - # eg. - # - # home-manager.users.${user-parts.user.username} = { - # OR - # home-manager.users.${config.nixos.user-parts.user.username} = { - # - # # # copies wallpapers from flake into ~/ - # # home.file."Wallpapers" = { - # # source = ../../assets/media/wallpapers; - # # target = ${user-parts.home-directory}/Pictures/Wallpapers; - # # }; + + # effectively a library of types reusable across the config + # to save myself having to hard-code my username everywhere + # now only needing to change it in the user.nix file + + # the hope was for this to enable multi-user, it did not + # however i think i can use this code to do so in future + + # general usage example: # + # - in your user.nix file + # nixos.user-parts = { + # submodule = { + # variable1 = "value"; + # variable2 = "value"; + # }; # }; # + # - in any module + # foo.bar = "${user-parts.submodule.variable1}"; + # + # this will let you re-use whatever values you set + # across the entire config and saves a lot of effort + flake.nixosModules.user-parts = { config, lib, ... }: { + options.nixos.user-parts = { user = lib.mkOption { type = lib.types.submodule { options = { + # user.username username = lib.mkOption { type = lib.types.str; default = "user"; }; + # user.avatar avatar = lib.mkOption { type = lib.types.str; default = "avatar.png"; }; + # user.home-directory home-directory = lib.mkOption { type = lib.types.str; - default = "/home/user/"; + # defalt declared below }; + # user.default-locale default-locale = lib.mkOption { type = lib.types.str; default = "en_US.UTF-8"; @@ -55,9 +68,11 @@ default = { }; }; + # user shell to use shell = lib.mkOption { type = lib.types.submodule { options = { + # fish, bash, zsh, etc. user-shell = lib.mkOption { type = lib.types.str; default = "pkgs.fish"; @@ -66,13 +81,16 @@ }; }; + # git config git = lib.mkOption { type = lib.types.submodule { options = { + # git signing username username = lib.mkOption { type = lib.types.str; default = "user"; }; + # git signing email email = lib.mkOption { type = lib.types.str; default = "user@noreply.codeberg.org"; @@ -88,6 +106,7 @@ # Make `nixos-variables` available as a module argument to all NixOS # modules (home-manager modules already get it via extraSpecialArgs). _module.args.user-parts = config.nixos.user-parts; + # sets user.home-directory's default value based on user.username's value nixos.user-parts.user = { home-directory = lib.mkDefault "/home/${config.nixos.user-parts.user.username}"; };