mirror of
https://github.com/foo-dogsquared/nixos-config.git
synced 2025-02-07 06:19:00 +00:00
config: add convention for setting profiles conditionally
This commit is contained in:
parent
1cb8b8c2cd
commit
ef2648bf3a
@ -112,6 +112,13 @@
|
||||
extraArgs = {
|
||||
inherit (inputs) nix-colors dotfiles;
|
||||
inherit inputs self;
|
||||
|
||||
# This is a variable that is used to check whether the module is
|
||||
# exported or not. Useful for configuring parts of the configuration
|
||||
# that is otherwise that cannot be exported for others' use.
|
||||
#
|
||||
# "Fds" stands for foo-dogsquared just because. :p
|
||||
_isInsideFds = true;
|
||||
};
|
||||
|
||||
mkHost = { system ? defaultSystem, extraModules ? [ ] }:
|
||||
|
@ -1,5 +1,6 @@
|
||||
= Profiles
|
||||
:toc:
|
||||
:check_variable: _isInsideFds
|
||||
|
||||
|
||||
We're defining profiles after how link:https://digga.divnix.com/concepts/profiles.html[digga library from divnix defines it].
|
||||
@ -13,6 +14,11 @@ ____
|
||||
|
||||
In other words, these are simple configuration that are typically composed of setting common NixOS options such as enabling NixOS services or installing system packages.
|
||||
|
||||
|
||||
|
||||
|
||||
== What are profiles, really?
|
||||
|
||||
However, unlike digga profiles, we do implement an interface (or a declaration) on top of the definition of options.
|
||||
Each profile should have an interface to be enabled first (e.g., `options.profiles.${profile}`) since it will be included as part of the included modules for our NixOS configurations.
|
||||
This basically makes it easier to create a centralized and one consistent version of a part of a configuration which we can just enable it anywhere multiple times.
|
||||
@ -25,11 +31,38 @@ As future reference, here's an exhaustive list of namespaces you should avoid us
|
||||
* `services` and `programs` shouldn't use any profiles at all since they are small in scope that they are more likely to be combined with other modules.
|
||||
|
||||
* Any modules under `workflows` are not exactly prohibited to use profiles since they are all-encompassing modules that creates a desktop that may be composed of multiple modules.
|
||||
However, it is heavily discouraged and sparingly used if at all.
|
||||
Since profiles are meant for specific setups, this could work nicely to be used for others except those with configurations with similarly set profiles such as mine (which would be nice or not depending on your intention).
|
||||
However, it is heavily discouraged.
|
||||
If used, be sure to put it under a check with `{check_variable}` which is an extra argument passed to various profiles (e.g., NixOS, home-manager) as an optional part of the configuration.
|
||||
Take note that workflows are also exported in the flake output.
|
||||
footnote:[Overall, I don't think it's not much of a threat to set profiles in the workflow unless users that is not me have conspicuously similar setup to mine. It's just discouraged to minimize stepping on as less as configurations as possible.]
|
||||
|
||||
* Really, anything that is being exported in the flake outputs (i.e., look for the attributes in `nix flake show`) unless explicitly stated like the case for `workflows`.
|
||||
|
||||
|
||||
|
||||
|
||||
== Setting profiles conditionally
|
||||
|
||||
The following snippet of a NixOS module with an optional part check with the simple boolean variable.
|
||||
|
||||
[subs=attributes, source, nix]
|
||||
----
|
||||
{ config, options, pkgs, lib, ... }@attrs:
|
||||
|
||||
{
|
||||
# ...
|
||||
|
||||
config = lib.mkIf cfg.enable (lib.mkMerge [
|
||||
{
|
||||
# Some required parts here.
|
||||
}
|
||||
|
||||
(lib.mkIf (attrs ? {check_variable} && attrs.{check_variable}) {
|
||||
# Set profiles here.
|
||||
})
|
||||
];
|
||||
}
|
||||
----
|
||||
|
||||
So yeah... have at it.
|
||||
This is useful for setting profiles inside of modules that are otherwise not possible to easily export for others' use (e.g., `workflows`).
|
||||
|
@ -1,4 +1,4 @@
|
||||
{ config, options, lib, pkgs, ... }:
|
||||
{ config, options, lib, pkgs, ... }@attrs:
|
||||
|
||||
let
|
||||
name = "a-happy-gnome";
|
||||
@ -19,10 +19,6 @@ let
|
||||
'';
|
||||
in
|
||||
{
|
||||
imports = [
|
||||
../../profiles/i18n.nix
|
||||
];
|
||||
|
||||
options.workflows.workflows.a-happy-gnome = {
|
||||
enable = lib.mkEnableOption "'A happy GNOME', foo-dogsquared's configuration of GNOME desktop environment";
|
||||
|
||||
@ -92,74 +88,83 @@ in
|
||||
};
|
||||
};
|
||||
|
||||
config = lib.mkIf cfg.enable {
|
||||
# Enable GNOME and GDM.
|
||||
services.xserver = {
|
||||
enable = true;
|
||||
displayManager.gdm.enable = true;
|
||||
desktopManager.gnome.enable = true;
|
||||
};
|
||||
config = lib.mkIf cfg.enable (lib.mkMerge [
|
||||
{
|
||||
# Enable GNOME and GDM.
|
||||
services.xserver = {
|
||||
enable = true;
|
||||
displayManager.gdm.enable = true;
|
||||
desktopManager.gnome.enable = true;
|
||||
};
|
||||
|
||||
xdg.portal = {
|
||||
enable = true;
|
||||
extraPortals = with pkgs; [
|
||||
xdg-desktop-portal-wlr
|
||||
];
|
||||
};
|
||||
xdg.portal = {
|
||||
enable = true;
|
||||
extraPortals = with pkgs; [
|
||||
xdg-desktop-portal-wlr
|
||||
];
|
||||
};
|
||||
|
||||
# All GNOME-related additional options.
|
||||
services.gnome = {
|
||||
core-os-services.enable = true;
|
||||
core-shell.enable = true;
|
||||
core-utilities.enable = true;
|
||||
};
|
||||
# All GNOME-related additional options.
|
||||
services.gnome = {
|
||||
core-os-services.enable = true;
|
||||
core-shell.enable = true;
|
||||
core-utilities.enable = true;
|
||||
|
||||
services.packagekit.enable = false;
|
||||
profiles.i18n = {
|
||||
enable = true;
|
||||
ibus.enable = true;
|
||||
};
|
||||
# It doesn't need to since we're not first-timers, yeah?
|
||||
gnome-initial-setup.enable = false;
|
||||
};
|
||||
|
||||
# Since we're using KDE Connect, we'll have to use gsconnect.
|
||||
programs.kdeconnect = {
|
||||
enable = true;
|
||||
package = pkgs.gnomeExtensions.gsconnect;
|
||||
};
|
||||
services.packagekit.enable = false;
|
||||
|
||||
# Bring all of the dconf keyfiles in there.
|
||||
programs.dconf = {
|
||||
enable = true;
|
||||
packages = [ dconfConfig ];
|
||||
# Since we're using KDE Connect, we'll have to use gsconnect.
|
||||
programs.kdeconnect = {
|
||||
enable = true;
|
||||
package = pkgs.gnomeExtensions.gsconnect;
|
||||
};
|
||||
|
||||
# The `user` profile needed to set custom system-wide settings in GNOME.
|
||||
# Also, this is a private option so take precautions with this.
|
||||
profiles.user = pkgs.writeTextFile {
|
||||
name = "a-happy-gnome";
|
||||
text = ''
|
||||
# Bring all of the dconf keyfiles in there.
|
||||
programs.dconf = {
|
||||
enable = true;
|
||||
packages = [ dconfConfig ];
|
||||
|
||||
# The `user` profile needed to set custom system-wide settings in GNOME.
|
||||
# Also, this is a private option so take precautions with this.
|
||||
profiles.user = pkgs.writeTextFile {
|
||||
name = "a-happy-gnome";
|
||||
text = ''
|
||||
user-db:user
|
||||
system-db:${name}-conf
|
||||
'';
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
xdg.mime = {
|
||||
enable = true;
|
||||
defaultApplications = {
|
||||
# Default application for web browser.
|
||||
"text/html" = "re.sonny.Junction.desktop";
|
||||
xdg.mime = {
|
||||
enable = true;
|
||||
defaultApplications = {
|
||||
# Default application for web browser.
|
||||
"text/html" = "re.sonny.Junction.desktop";
|
||||
|
||||
# Default handler for all files. Not all applications will
|
||||
# respect it, though.
|
||||
"x-scheme-handler/file" = "re.sonny.Junction.desktop";
|
||||
# Default handler for all files. Not all applications will
|
||||
# respect it, though.
|
||||
"x-scheme-handler/file" = "re.sonny.Junction.desktop";
|
||||
|
||||
# Default handler for directories.
|
||||
"inode/directory" = "re.sonny.Junction.desktop";
|
||||
# Default handler for directories.
|
||||
"inode/directory" = "re.sonny.Junction.desktop";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
environment.systemPackages = with pkgs; [
|
||||
# The application menu.
|
||||
junction
|
||||
] ++ cfg.shellExtensions ++ cfg.extraApps;
|
||||
};
|
||||
environment.systemPackages = with pkgs; [
|
||||
# The application menu.
|
||||
junction
|
||||
] ++ cfg.shellExtensions ++ cfg.extraApps;
|
||||
}
|
||||
|
||||
# Check whether this is inside of my personal configuration or nah.
|
||||
(lib.mkIf (attrs ? _isInsideFds && attrs._isInsideFds) {
|
||||
profiles.i18n = lib.mkDefault {
|
||||
enable = true;
|
||||
ibus.enable = true;
|
||||
};
|
||||
})
|
||||
]);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user