Skip to content

Commit

Permalink
preferences: move to option based setup
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnRTitor committed Nov 3, 2024
1 parent fb736df commit 75d778a
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 43 deletions.
9 changes: 5 additions & 4 deletions flake/default.nix
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
let
inherit ((import ../preferences.nix).systemSettings) systemarch;
in {
{config, ... }:
{
imports = [
./hosts.nix # NixOS hosts/desktop systems are are defined there
./options-definitions.nix
../preferences.nix
];

# systems for which you want to build the `perSystem` attributes
systems = [
systemarch
config.myOptions.systemSettings.systemarch
# "x86_64-linux"
# "aarch64-linux"
];
Expand Down
3 changes: 2 additions & 1 deletion flake/hosts.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
config,
inputs,
self,
...
}: let
inherit (inputs) nixpkgs nixpkgs-edge nixpkgs-master;
inherit (nixpkgs) lib; # use lib from nixpkgs

inherit (import ../preferences.nix) systemSettings userSettings servicesSettings;
inherit (config.myOptions) systemSettings userSettings servicesSettings;

# bleeding edge packages from nixpkgs unstable branch, for packages that need immediate updates
pkgs-edge = import nixpkgs-edge {
Expand Down
84 changes: 84 additions & 0 deletions flake/options-definitions.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{lib, ... }:
{
options.myOptions = {
# ---- SYSTEM SETTINGS ---- #
systemSettings = {
systemarch = lib.mkOption {
type = lib.types.singleLineStr;
default = "x86_64-linux";
description = "System architecture";
};
hostname = lib.mkOption {
type = lib.types.singleLineStr;
default = "NixOS";
description = "Hostname";
};
timezone = lib.mkOption {
type = lib.types.singleLineStr;
default = "America/New_York";
description = "Timezone";
};
locale = lib.mkOption {
type = lib.types.singleLineStr;
default = "en_US.UTF-8";
description = "Locale";
};
additionalLocale = lib.mkOption {
type = lib.types.singleLineStr;
default = "en_IN";
description = "Additonal Locale";
};
stableversion = lib.mkOption {
type = lib.types.singleLineStr;
default = "24.11";
description = "Stable version (DO NOT CHANGE)";
};
secureboot = lib.mkEnableOption "Secure Boot";
laptop = lib.mkEnableOption "Laptop features";
};

# ----- USER SETTINGS ----- #
userSettings = {
username = lib.mkOption {
type = lib.types.singleLineStr;
default = "alice";
description = "Username";
};
name = lib.mkOption {
type = lib.types.singleLineStr;
default = "Alice";
description = "Name/Identifier";
};
gitname = lib.mkOption {
type = lib.types.singleLineStr;
default = "Alice";
description = "Name used for Git operations";
};
gitemail = lib.mkOption {
type = lib.types.singleLineStr;
default = "[email protected]";
description = "Email used for Git operations";
};
gpgkey = lib.mkOption {
type = lib.types.singleLineStr;
description = "GPG key ID for Git operations";
};
shell = lib.mkOption {
type = lib.types.enum [ "zsh" "bash" ];
default = "zsh";
description = "User default shell";
};
};

servicesSettings = {
adb = lib.mkEnableOption "ADB";
avahi = lib.mkEnableOption "Avahi";
nginx = lib.mkEnableOption "Nginx";
containers = lib.mkEnableOption "Containers";
tpm = lib.mkEnableOption "TPM";
virtualisation = lib.mkEnableOption "Virtualisation";
printing = lib.mkEnableOption "Printing";
apparmor = lib.mkEnableOption "AppArmor";
};
};
}
61 changes: 32 additions & 29 deletions preferences.nix
Original file line number Diff line number Diff line change
@@ -1,34 +1,37 @@
{...}:
{
# ---- SYSTEM SETTINGS ---- #
systemSettings = {
systemarch = "x86_64-linux"; # system arch
hostname = "Ainz-NIX"; # hostname
timezone = "Asia/Kolkata"; # select timezone
locale = "en_US.UTF-8"; # select locale
localeoverride = "en_IN";
stableversion = "24.11";
secureboot = true;
laptop = false;
};
myOptions = {
# ---- SYSTEM SETTINGS ---- #
systemSettings = {
systemarch = "x86_64-linux"; # system arch
hostname = "Ainz-NIX"; # hostname
timezone = "Asia/Kolkata"; # select timezone
locale = "en_US.UTF-8"; # select locale
additionalLocale = "en_IN";
stableversion = "24.11";
secureboot = true;
laptop = false;
};

# ----- USER SETTINGS ----- #
userSettings = {
username = "masum"; # username
name = "Masum R."; # name/identifier
gitname = "John Titor"; # git name
gitemail = "[email protected]"; # git email
gpgkey = "29B0514F4E3C1CC0"; # gpg key
shell = "zsh"; # user default shell # choose either zsh or bash
};
# ----- USER SETTINGS ----- #
userSettings = {
username = "masum"; # username
name = "Masum R."; # name/identifier
gitname = "John Titor"; # git name
gitemail = "[email protected]"; # git email
gpgkey = "29B0514F4E3C1CC0"; # gpg key
shell = "zsh"; # user default shell # choose either zsh or bash
};

servicesSettings = {
adb = false;
avahi = false;
nginx = true;
containers = false;
tpm = false;
virtualisation = false;
printing = false;
apparmor = false;
servicesSettings = {
adb = false;
avahi = false;
nginx = true;
containers = false;
tpm = false;
virtualisation = false;
printing = false;
apparmor = false;
};
};
}
18 changes: 9 additions & 9 deletions system/locale.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
i18n.defaultLocale = systemSettings.locale;

i18n.extraLocaleSettings = {
LC_ADDRESS = systemSettings.localeoverride;
LC_IDENTIFICATION = systemSettings.localeoverride;
LC_MEASUREMENT = systemSettings.localeoverride;
LC_MONETARY = systemSettings.localeoverride;
LC_NAME = systemSettings.localeoverride;
LC_NUMERIC = systemSettings.localeoverride;
LC_PAPER = systemSettings.localeoverride;
LC_TELEPHONE = systemSettings.localeoverride;
LC_TIME = systemSettings.localeoverride;
LC_ADDRESS = systemSettings.additionalLocale;
LC_IDENTIFICATION = systemSettings.additionalLocale;
LC_MEASUREMENT = systemSettings.additionalLocale;
LC_MONETARY = systemSettings.additionalLocale;
LC_NAME = systemSettings.additionalLocale;
LC_NUMERIC = systemSettings.additionalLocale;
LC_PAPER = systemSettings.additionalLocale;
LC_TELEPHONE = systemSettings.additionalLocale;
LC_TIME = systemSettings.additionalLocale;
};

# Configure keymap in X11
Expand Down

0 comments on commit 75d778a

Please sign in to comment.