Update home-manager modules and related configs

This commit is contained in:
Gabriel Arazas 2021-11-29 17:56:24 +08:00
parent db5fc8269e
commit e2699c2cea
11 changed files with 180 additions and 37 deletions

6
flake.lock generated
View File

@ -42,11 +42,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1638097282,
"narHash": "sha256-EXCzj9b8X/lqDPJapxZThIOKL5ASbpsJZ+8L1LnY1ig=",
"lastModified": 1638129630,
"narHash": "sha256-vaYC1DhrR1nao2rQ8fUf4PNhBLfSeCi2LVrDXTxUu1Y=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "78cb77b29d37a9663e05b61abb4fa09465da4b70",
"rev": "9f25a8ac3a985ba213f775b19750efefdecc9974",
"type": "github"
},
"original": {

View File

@ -12,24 +12,38 @@
outputs = inputs@{ self, nixpkgs, home-manager, ... }:
let
libExtended = nixpkgs.lib.extend
(final: prev: (import ./lib { inherit inputs; lib = final; }));
# All the target systems.
systems = [
"x86_64-linux"
"i686-linux"
"x86_64-darwin"
"aarch64-linux"
"armv6l-linux"
"armv7l-linux"
];
forAllSystems = f: nixpkgs.lib.genAttrs systems (system: f system);
libExtended = nixpkgs.lib.extend (final: prev:
(import ./lib {
inherit inputs;
lib = final;
}));
hostDefaultConfig = {
# Stallman-senpai will be disappointed.
nixpkgs.config.allowUnfree = true;
# We live in a Unicode world and dominantly English in technical fields so we'll
# have to go with it.
i18n.defaultLocale = "en_US.UTF-8";
# Sane config for the package manager.
nix.gc = {
automatic = true;
dates = "monthly";
options = "--delete-older-than 2w";
};
# TODO: Remove this after nix-command and flakes has been considered stable.
#
# Since we're using flakes to make this possible, we need it.
@ -39,37 +53,38 @@
'';
};
userDefaultConfig = {
system = "x86_64-linux";
};
userDefaultConfig = { system = "x86_64-linux"; };
in {
# Exposes only my library with the custom functions to make it easier to include in other flakes.
lib = import ./lib { inherit inputs; lib = nixpkgs.lib; };
lib = import ./lib {
inherit inputs;
lib = nixpkgs.lib;
};
# A list of NixOS configurations from the `./hosts` folder.
# It also has some sensible default configurations.
nixosConfigurations =
libExtended.mapAttrs (host: path: libExtended.mkHost path hostDefaultConfig) (libExtended.filesToAttr ./hosts);
nixosConfigurations = libExtended.mapAttrs
(host: path: libExtended.mkHost path hostDefaultConfig)
(libExtended.filesToAttr ./hosts);
# We're going to make our custom modules available for our flake. Whether
# or not this is a good thing is debatable, I just want to test it.
nixosModules =
libExtended.mapAttrs (_: path: import path) (libExtended.filesToAttr ./modules);
nixosModules = libExtended.mapAttrs (_: path: import path)
(libExtended.filesToAttr ./modules);
homeConfigurations = let
excludedModules = [
"config" # The common user-specific configurations.
"modules" # User-specific Nix modules.
];
in libExtended.mapAttrs (user: path:
home-manager.lib.homeManagerConfiguration {
system = "x86_64-linux";
configuration = import path;
homeDirectory = "/home/${user}";
username = user;
}) (libExtended.filterAttrs (n: v: !libExtended.elem n excludedModules)
(libExtended.filesToAttr ./users));
homeConfigurations =
let
excludedModules = [
"config" # The common user-specific configurations.
"modules" # User-specific Nix modules.
];
in
libExtended.mapAttrs (user: path:
home-manager.lib.homeManagerConfiguration {
system = "x86_64-linux";
configuration = import path;
homeDirectory = "/home/${user}";
username = user;
})
(libExtended.filterAttrs (n: v: !libExtended.elem n excludedModules) (libExtended.filesToAttr ./users));
};
}

12
hosts/README.adoc Normal file
View File

@ -0,0 +1,12 @@
= Host-specific configuration
:toc:
These are configurations that are specific to a machine (e.g., desktop, servers, VM, containers).
Ideally, it should be made minimal as much as possible considering you also have to manage your users.
For managing users, there are multiple ways to manage them with this config:
* The usual `users.users.${user}` from system configuration (see `man configuration.nix.5`).
* Modularize them (see link:../users/README.adoc[User-specific configuration] for more information).
If you have user-specific configs in set, you have to manage them with link:../modules/users.nix[`modules.users.users`] which is my implementation of managing users (e.g., `modules.users.users = [ "foo-dogsquared" ]`).

View File

@ -21,6 +21,7 @@
dev = {
enable = true;
shell.enable = true;
virtualization.enable = true;
};
editors = {
emacs.enable = true;

View File

@ -42,8 +42,8 @@ modules/
dev = path/to/dev.nix;
editors = path/to/editors.nix;
specific = {
borg = path/to/specific/borg.nix
prometheus = path/to/specific/prometheus.nix
borg = path/to/specific/borg.nix;
prometheus = path/to/specific/prometheus.nix;
};
themes = path/to/themes; # Since it has a 'default.nix' detected, we're using it instead.
users = path/to/users.nix;

View File

@ -10,18 +10,20 @@ let
mkUser = user: path:
let
userModule = import path;
defaultConfig = {
home.username = user;
home.homeDirectory = "/home/${user}";
xdg.enable = true;
};
in
{
{
users.users.${user} = {
isNormalUser = true;
extraGroups = [ "wheel" ];
};
home-manager.users.${user} = defaultConfig // import path;
home-manager.users.${user} = userModule // defaultConfig;
};
in
{

View File

@ -19,3 +19,36 @@ Here's an example of a sample user config placed in `users/hello.nix`.
----
This is to be imported to `homeManagerConfiguration` in the flake outputs and when indicated from `config.modules.users.users` (e.g., `modules.users.users = [ "hello" ];`).
== Modules
There are also user modules (in link:./modules[`./modules`]) that are imported to use with home-manager, allowing you to extend it as you wish.
It works just like link:https://github.com/nix-community/home-manager/tree/master/modules[home-manager modules].
For easier identification, it should be stored with `modules` as the top-level attribute (e.g., `modules.alacritty`, `modules.i18n`).
Here's an example user module that simply ports my Alacritty config.
[source, nix]
----
{ config, options, lib, pkgs, ... }:
let
cfg = config.modules.alacritty;
in
{
options.modules.alacritty.enable = lib.mkEnableOption "Ports my Alacritty configuration.";
config = lib.mkIf cfg.enable {
home.packages = with pkgs; [ alacritty ];
xdg.configFile."alacritty" = {
source = ../config/alacritty
recursive = true;
};
};
}
----

View File

@ -1,11 +1,20 @@
{ config, options, lib, pkgs, ... }:
{
programs.direnv.enable = true;
fonts.fontconfig.enable = true;
# My specific usual stuff.
programs.git = {
enable = true;
lfs.enable = true;
userName = "foo-dogsquared";
userEmail = "foo.dogsquared@gmail.com";
};
# My custom modules.
modules = {
alacritty.enable = true;
i18n.enable = true;
dev.enable = true;
};
}

View File

@ -0,0 +1,16 @@
{ config, options, lib, pkgs, ... }:
let
cfg = config.modules.alacritty;
in
{
options.modules.alacritty.enable = lib.mkEnableOption "Enable Alacritty config";
config = lib.mkIf cfg.enable {
home.packages = with pkgs; [ alacritty ];
xdg.configFile."alacritty" = {
source = ../config/alacritty/alacritty.yml;
recursive = true;
};
};
}

34
users/modules/dev.nix Normal file
View File

@ -0,0 +1,34 @@
{ config, options, lib, pkgs, ... }:
let
cfg = config.modules.dev;
in
{
options.modules.dev = {
enable = lib.mkEnableOption "Enable my user-specific development setup.";
shell.enable = lib.mkEnableOption "Configures my shell of choice.";
};
config = lib.mkIf cfg.enable (lib.mkMerge [
({
home.packages = with pkgs; [
neovim # My text editor of choice.
lazygit # Git interface for the lazy.
fzf # A fuzzy finder that enables fuzzy finding not furry finding, a common misconception.
gopass # An improved version of the password manager for hipsters.
# Coreutils replacement.
fd # Oh nice, a more reliable `find`.
ripgrep # On nice, a more reliable `grep`.
exa # Oh nice, a shinier `ls`.
bat # dog > bat > cat
];
programs.direnv = {
enable = true;
nix-direnv.enable = true;
};
programs.zoxide.enable = true;
})
]);
}

21
users/modules/i18n.nix Normal file
View File

@ -0,0 +1,21 @@
{ config, options, lib, pkgs, ... }:
let
cfg = config.modules.i18n;
in
{
options.modules.i18n.enable = lib.mkEnableOption "Enable fcitx5 as input method engine.";
config = lib.mkIf cfg.enable {
i18n.inputMethod = {
enabled = "fcitx5";
fcitx5.addons = with pkgs; [
fcitx5-gtk # Add support for GTK-based programs.
libsForQt5.fcitx5-qt # Add support for QT-based programs.
fcitx5-lua # Add Lua support.
fcitx5-rime # Chinese input addon.
fcitx5-mozc # Japanese input addon.
];
};
};
}