Boilerplate reduction (I understand strings in nix now!)

This commit is contained in:
Emmet 2023-06-22 14:53:10 -05:00
parent c7f3327147
commit b4a0d72a92
17 changed files with 136 additions and 144 deletions

View file

@ -11,23 +11,14 @@
locale = "en_US.UTF-8"; # select locale
# ----- USER SETTINGS ----- #
name = "emmet"; # username
username = "emmet"; # username
name = "Emmet"; # name/identifier
email = "librephoenix3@pm.me"; # email (used for certain configurations)
dotfilesDir = "~/.dotfiles"; # absolute path of the repo
dotfilesDir = "~/.dotfiles"; # absolute path of the repo locally
theme = "ayu-dark"; # selcted theme from my themes directory
wm = "xmonad"; # Selected window manager or desktop environment
# --- PATH CALCULATIONS -- #
homeNixPath = ./. + "/profiles"+("/"+profile)+"/home.nix";
configurationNixPath = ./. + "/profiles"+("/"+profile)+"/configuration.nix";
systemWMNixPath = ./. + "/system/wm"+("/"+wm)+".nix";
userWMNixPath = ./. + "/user/wm"+("/"+wm+"/"+wm)+".nix";
themePolarityPath = "/themes/"+theme+"/polarity.txt";
themePolarity = lib.removeSuffix "\n" (builtins.readFile (./. + themePolarityPath));
backgroundUrlPath = "/themes/"+theme+"/backgroundurl.txt";
backgroundUrl = builtins.readFile (./. + backgroundUrlPath);
backgroundSha256Path = "/themes/"+theme+"/backgroundsha256.txt";
backgroundSha256 = builtins.readFile (./. + backgroundSha256Path);
font = "Inconsolata"; # Selected font
fontPkg = pkgs.inconsolata; # Font package
# set pkgs to correct type
pkgs = import nixpkgs {
@ -42,20 +33,17 @@
homeConfigurations = {
emmet = home-manager.lib.homeManagerConfiguration {
inherit pkgs;
modules = [
homeNixPath
];
modules = [ (./. + "/profiles"+("/"+profile)+"/home.nix") ]; # load home.nix from profile
extraSpecialArgs = {
myName = name;
myHostname = hostname;
myHomeDir = "/home/"+name;
myEmail = email;
myDotfilesDir = dotfilesDir;
myTheme = theme;
myThemePolarity = themePolarity;
myBackgroundUrl = backgroundUrl;
myBackgroundSha256 = backgroundSha256;
inherit userWMNixPath;
inherit username;
inherit name;
inherit hostname;
inherit email;
inherit dotfilesDir;
inherit theme;
inherit font;
inherit fontPkg;
inherit wm;
inherit (inputs) nix-doom-emacs;
inherit (inputs) stylix;
inherit (inputs) eaf;
@ -67,17 +55,17 @@
nixosConfigurations = {
snowfire = lib.nixosSystem {
inherit system;
modules = [ configurationNixPath ];
modules = [ (./. + "/profiles"+("/"+profile)+"/configuration.nix") ]; # load configuration.nix from profile
specialArgs = {
myName = name;
myHostname = hostname;
myTimezone = timezone;
myLocale = locale;
myTheme = theme;
myThemePolarity = themePolarity;
myBackgroundUrl = backgroundUrl;
myBackgroundSha256 = backgroundSha256;
inherit systemWMNixPath;
inherit username;
inherit name;
inherit hostname;
inherit timezone;
inherit locale;
inherit theme;
inherit font;
inherit fontPkg;
inherit wm;
inherit (inputs) stylix;
inherit (inputs) blocklist-hosts;
};

View file

@ -1,4 +1,4 @@
{ config, lib, pkgs, blocklist-hosts, myName, myHostname, myTimezone, myLocale, myTheme, myBackgroundUrl, myBackgroundSha256, ... }:
{ config, lib, pkgs, blocklist-hosts, username, hostname, timezone, locale, ... }:
args@{ ... }:
@ -32,26 +32,26 @@ args@{ ... }:
boot.loader.efi.efiSysMountPoint = "/boot/efi";
# Networking
networking.hostName = myHostname; # Define your hostname.
networking.hostName = hostname; # Define your hostname.
networking.networkmanager.enable = true; # Use networkmanager
# Timezone and locale
time.timeZone = myTimezone; # time zone
i18n.defaultLocale = myLocale;
time.timeZone = timezone; # time zone
i18n.defaultLocale = locale;
i18n.extraLocaleSettings = {
LC_ADDRESS = myLocale;
LC_IDENTIFICATION = myLocale;
LC_MEASUREMENT = myLocale;
LC_MONETARY = myLocale;
LC_NAME = myLocale;
LC_NUMERIC = myLocale;
LC_PAPER = myLocale;
LC_TELEPHONE = myLocale;
LC_TIME = myLocale;
LC_ADDRESS = locale;
LC_IDENTIFICATION = locale;
LC_MEASUREMENT = locale;
LC_MONETARY = locale;
LC_NAME = locale;
LC_NUMERIC = locale;
LC_PAPER = locale;
LC_TELEPHONE = locale;
LC_TIME = locale;
};
# User account
users.users.${myName} = {
users.users.${username} = {
isNormalUser = true;
description = "Emmet";
extraGroups = [ "networkmanager" "wheel" ];

View file

@ -1,10 +1,10 @@
{ config, lib, pkgs, python3Packages, nix-doom-emacs, stylix, myName, myEmail, myHomeDir, myDotfilesDir, myTheme, ... }:
{ config, lib, pkgs, python3Packages, nix-doom-emacs, stylix, username, email, dotfilesDir, theme, ... }:
{
# Home Manager needs a bit of information about you and the paths it should
# manage.
home.username = myName;
home.homeDirectory = myHomeDir;
home.username = username;
home.homeDirectory = "/home/"+username;
programs.home-manager.enable = true;

View file

@ -2,7 +2,7 @@
# your system. Help is available in the configuration.nix(5) man page
# and in the NixOS manual (accessible by running nixos-help).
{ config, lib, pkgs, blocklist-hosts, myName, myHostname, myTimezone, myLocale, myTheme, myBackgroundUrl, myBackgroundSha256, ... }:
{ config, lib, pkgs, blocklist-hosts, username, name, hostname, timezone, locale, wm, theme, ... }:
{
imports =
[ ../work/configuration.nix # Personal is essentially work system + games

View file

@ -1,10 +1,10 @@
{ config, lib, pkgs, python3Packages, nix-doom-emacs, stylix, myName, myEmail, myHomeDir, myDotfilesDir, myTheme, ... }:
{ config, lib, pkgs, python3Packages, nix-doom-emacs, stylix, username, email, dotfilesDir, theme, ... }:
{
# Home Manager needs a bit of information about you and the paths it should
# manage.
home.username = myName;
home.homeDirectory = myHomeDir;
home.username = username;
home.homeDirectory = "/home/"+username;
programs.home-manager.enable = true;

View file

@ -2,7 +2,7 @@
# your system. Help is available in the configuration.nix(5) man page
# and in the NixOS manual (accessible by running nixos-help).
{ config, lib, pkgs, blocklist-hosts, myName, myHostname, myTimezone, myLocale, systemWMNixPath, myTheme, myBackgroundUrl, myBackgroundSha256, ... }:
{ config, lib, pkgs, blocklist-hosts, username, name, hostname, timezone, locale, wm, theme, ... }:
{
imports =
[ ../../system/hardware-configuration.nix
@ -10,7 +10,7 @@
../../system/hardware/opengl.nix
../../system/hardware/printing.nix
../../system/hardware/bluetooth.nix
systemWMNixPath # My window manager selected from flake
(./. + "../../../system/wm"+("/"+wm)+".nix") # My window manager
../../system/app/flatpak.nix
../../system/security/doas.nix
../../system/security/gpg.nix
@ -41,28 +41,28 @@
boot.loader.efi.efiSysMountPoint = "/boot/efi";
# Networking
networking.hostName = myHostname; # Define your hostname.
networking.hostName = hostname; # Define your hostname.
networking.networkmanager.enable = true; # Use networkmanager
# Timezone and locale
time.timeZone = myTimezone; # time zone
i18n.defaultLocale = myLocale;
time.timeZone = timezone; # time zone
i18n.defaultLocale = locale;
i18n.extraLocaleSettings = {
LC_ADDRESS = myLocale;
LC_IDENTIFICATION = myLocale;
LC_MEASUREMENT = myLocale;
LC_MONETARY = myLocale;
LC_NAME = myLocale;
LC_NUMERIC = myLocale;
LC_PAPER = myLocale;
LC_TELEPHONE = myLocale;
LC_TIME = myLocale;
LC_ADDRESS = locale;
LC_IDENTIFICATION = locale;
LC_MEASUREMENT = locale;
LC_MONETARY = locale;
LC_NAME = locale;
LC_NUMERIC = locale;
LC_PAPER = locale;
LC_TELEPHONE = locale;
LC_TIME = locale;
};
# User account
users.users.${myName} = {
users.users.${username} = {
isNormalUser = true;
description = "Emmet";
description = name;
extraGroups = [ "networkmanager" "wheel" ];
packages = with pkgs; [];
uid = 1000;

View file

@ -1,17 +1,17 @@
{ config, lib, pkgs, python3Packages, nix-doom-emacs, stylix, myName, myEmail, myHomeDir, myDotfilesDir, myTheme, userWMNixPath, ... }:
{ config, lib, pkgs, python3Packages, nix-doom-emacs, stylix, username, email, dotfilesDir, theme, wm, ... }:
{
# Home Manager needs a bit of information about you and the paths it should
# manage.
home.username = myName;
home.homeDirectory = myHomeDir;
home.username = username;
home.homeDirectory = "/home/"+username;
programs.home-manager.enable = true;
imports = [
nix-doom-emacs.hmModule
stylix.homeManagerModules.stylix
userWMNixPath # My window manager selected from flake
(./. + "../../../user/wm"+("/"+wm+"/"+wm)+".nix") # My window manager selected from flake
../../user/shell/sh.nix # My zsh and bash config
../../user/shell/cli-collection.nix # Useful CLI apps
../../user/bin/phoenix.nix # My nix command wrapper

View file

@ -21,10 +21,10 @@ My system-level Nix modules are organized into this directory:
Variables can be imported from [[../flake.nix][flake.nix]] by setting the =specialArgs= block inside the flake (see [[../flake.nix][my flake]] for more details). This allows variables to merely be managed in one place ([[../flake.nix][flake.nix]]) rather than having to manage them in multiple locations.
I currently import the following variables to the system config:
- =myName= - Username
- =myHostname= - Hostname for machine
- =myTimezone= - Timezone for machine
- =myLocale= - Locale for machine
- =myTheme= - base16 theme stored in ../themes to be used
- =myBackgroundUrl= - Direct link to background wallpaper (used for login screen)
- =myBackgroundSha256= - Checksum for background image used when downloading
- =username= - Username
- =hostname= - Hostname for machine
- =timezone= - Timezone for machine
- =locale= - Locale for machine
- =theme= - base16 theme stored in ../themes to be used
- =backgroundUrl= - Direct link to background wallpaper (used for login screen)
- =backgroundSha256= - Checksum for background image used when downloading

View file

@ -1,4 +1,4 @@
{ config, lib, pkgs, myName, storageDriver ? null, ... }:
{ config, lib, pkgs, username, storageDriver ? null, ... }:
assert lib.asserts.assertOneOf "storageDriver" storageDriver [
null
@ -17,5 +17,5 @@ assert lib.asserts.assertOneOf "storageDriver" storageDriver [
storageDriver = storageDriver;
autoPrune.enable = true;
};
users.users.${myName}.extraGroups = [ "docker" ];
users.users.${username}.extraGroups = [ "docker" ];
}

View file

@ -1,11 +1,11 @@
{ config, myName, pkgs, ... }:
{ config, username, pkgs, ... }:
{
# Doas instead of sudo
security.doas.enable = true;
security.sudo.enable = false;
security.doas.extraRules = [{
users = [ "${myName}" ];
users = [ "${username}" ];
keepEnv = true;
persist = true;
}];

View file

@ -1,33 +1,34 @@
{ config, pkgs, stylix, myTheme, myThemePolarity, myBackgroundUrl, myBackgroundSha256, ... }:
{ config, lib, pkgs, stylix, theme, font, fontPkg, ... }:
let
myFont = "Inconsolata";
myFontPkg = pkgs.inconsolata;
myThemePath = "../../../themes/"+myTheme+"/"+myTheme+".yaml";
myLightDMTheme = if myThemePolarity == "light" then "Adwaita" else "Adwaita-dark";
themePath = "../../../themes/"+theme+"/"+theme+".yaml";
themePolarity = lib.removeSuffix "\n" (builtins.readFile (./. + "../../../themes"+("/"+theme)+"/polarity.txt"));
myLightDMTheme = if themePolarity == "light" then "Adwaita" else "Adwaita-dark";
backgroundUrl = builtins.readFile (./. + "../../../themes"+("/"+theme)+"/backgroundurl.txt");
backgroundSha256 = builtins.readFile (./. + "../../../themes/"+("/"+theme)+"/backgroundsha256.txt");
in
{
imports = [ stylix.nixosModules.stylix ];
stylix.autoEnable = false;
stylix.polarity = myThemePolarity;
stylix.polarity = themePolarity;
stylix.image = pkgs.fetchurl {
url = myBackgroundUrl;
sha256 = myBackgroundSha256;
url = backgroundUrl;
sha256 = backgroundSha256;
};
stylix.base16Scheme = ./. + myThemePath;
stylix.base16Scheme = ./. + themePath;
stylix.fonts = {
monospace = {
name = myFont;
package = myFontPkg;
name = font;
package = fontPkg;
};
serif = {
name = myFont;
package = myFontPkg;
name = font;
package = fontPkg;
};
sansSerif = {
name = myFont;
package = myFontPkg;
name = font;
package = fontPkg;
};
emoji = {
name = "Noto Color Emoji";

View file

@ -41,12 +41,12 @@ My user-level Nix modules are organized into this directory:
Variables can be imported from [[../flake.nix][flake.nix]] by setting the =extraSpecialArgs= block inside the flake (see [[../flake.nix][my flake]] for more details). This allows variables to merely be managed in one place ([[../flake.nix][flake.nix]]) rather than having to manage them in multiple locations.
I currently import the following variables to the system config:
- =myName= - Username
- =myHostname= - Hostname for machine
- =myHomeDir= - Absolute path to home directory derived from =myName=
- =myEmail= - Email
- =myDotfilesDir= - Path to my dotfiles directory on the system
- =myTheme= - base16 theme stored in ../themes to be used
- =myThemePolarity= - whether theme is =light= or =dark=
- =myBackgroundUrl= - Direct link to background wallpaper (used for login screen)
- =myBackgroundSha256= - Checksum for background image used when downloading
- =username= - Username
- =hostname= - Hostname for machine
- =myHomeDir= - Absolute path to home directory derived from =username=
- =email= - Email
- =dotfilesDir= - Path to my dotfiles directory on the system
- =theme= - base16 theme stored in ../themes to be used
- =themePolarity= - whether theme is =light= or =dark=
- =backgroundUrl= - Direct link to background wallpaper (used for login screen)
- =backgroundSha256= - Checksum for background image used when downloading

View file

@ -1,6 +1,7 @@
{ config, lib, pkgs, eaf, eaf-browser, org-nursery, myThemePolarity, ... }:
{ config, lib, pkgs, eaf, eaf-browser, org-nursery, theme, ... }:
let
myDashboardLogo = ./. + "/nix-" + myThemePolarity + ".png";
themePolarity = lib.removeSuffix "\n" (builtins.readFile (./. + "../../../../themes"+("/"+theme)+"/polarity.txt"));
dashboardLogo = ./. + "/nix-" + themePolarity + ".png";
in
{
programs.doom-emacs = {
@ -78,7 +79,7 @@ in
home.file.".emacs.d/org-nursery" = {
source = "${org-nursery}";
};
home.file.".emacs.d/dashboard-logo.png".source = myDashboardLogo;
home.file.".emacs.d/dashboard-logo.png".source = dashboardLogo;
home.file.".emacs.d/scripts/copy-link-or-file/copy-link-or-file-to-clipboard.sh" = {
source = ./scripts/copy-link-or-file/copy-link-or-file-to-clipboard.sh;
executable = true;

View file

@ -1409,9 +1409,10 @@ Any git package can be configured for a particular commit or branch:
* Nix Integration
In order to have Nix load my Doom Emacs configuration [[./doom.nix][doom.nix]], which I source in the =imports= block of my [[../../home.nix][home.nix]].
#+BEGIN_SRC nix :tangle doom.nix
{ config, lib, pkgs, eaf, eaf-browser, org-nursery, myThemePolarity, ... }:
{ config, lib, pkgs, eaf, eaf-browser, org-nursery, theme, ... }:
let
myDashboardLogo = ./. + "/nix-" + myThemePolarity + ".png";
themePolarity = lib.removeSuffix "\n" (builtins.readFile (./. + "../../../../themes"+("/"+theme)+"/polarity.txt"));
dashboardLogo = ./. + "/nix-" + themePolarity + ".png";
in
{
programs.doom-emacs = {
@ -1489,7 +1490,7 @@ in
home.file.".emacs.d/org-nursery" = {
source = "${org-nursery}";
};
home.file.".emacs.d/dashboard-logo.png".source = myDashboardLogo;
home.file.".emacs.d/dashboard-logo.png".source = dashboardLogo;
home.file.".emacs.d/scripts/copy-link-or-file/copy-link-or-file-to-clipboard.sh" = {
source = ./scripts/copy-link-or-file/copy-link-or-file-to-clipboard.sh;
executable = true;

View file

@ -1,10 +1,10 @@
{ config, lib, pkgs, myName, myEmail, ... }:
{ config, lib, pkgs, username, email, ... }:
{
home.packages = [ pkgs.git ];
programs.git.enable = true;
programs.git.userName = myName;
programs.git.userEmail = myEmail;
programs.git.userName = username;
programs.git.userEmail = email;
programs.git.extraConfig = {
init.defaultBranch = "main";
};

View file

@ -1,4 +1,4 @@
{ config, lib, pkgs, myName, myDotfilesDir, ... }:
{ config, lib, pkgs, username, dotfilesDir, ... }:
let
# This sets up my "phoenix" script with my configuration paths
@ -6,12 +6,12 @@ let
myPhoenixScript = ''
if [ "$1" = "sync" ]; then
if [ "$2" != "user" ]; then
pushd ''+myDotfilesDir+'';
pushd ''+dotfilesDir+'';
sudo nixos-rebuild switch --flake .#;
popd;
elif [ "2" != "system" ]; then
pushd ''+myDotfilesDir+'';
home-manager switch --flake .#''+myName+'';
pushd ''+dotfilesDir+'';
home-manager switch --flake .#''+username+'';
popd;
which xmobar &> /dev/null && killall xmobar;
which xmonad &> /dev/null && xmonad --recompile && xmonad --restart;
@ -19,7 +19,7 @@ let
[ -f ~/.fehbg-stylix ] &> /dev/null && ~/.fehbg-stylix;
fi
elif [ "$1" = "update" ]; then
pushd ''+myDotfilesDir+'';
pushd ''+dotfilesDir+'';
nix flake update;
popd;
if [ -d ~/.emacs.d/eaf/app/browser ]

View file

@ -1,32 +1,33 @@
{ config, pkgs, myTheme, myThemePolarity, myBackgroundUrl, myBackgroundSha256, ... }:
{ config, lib, pkgs, theme, font, fontPkg, ... }:
let
myFont = "Inconsolata";
myFontPkg = pkgs.inconsolata;
myThemePath = "../../../themes/"+myTheme+"/"+myTheme+".yaml";
themePath = "../../../themes"+("/"+theme+"/"+theme)+".yaml";
themePolarity = lib.removeSuffix "\n" (builtins.readFile (./. + "../../../themes"+("/"+theme)+"/polarity.txt"));
backgroundUrl = builtins.readFile (./. + "../../../themes"+("/"+theme)+"/backgroundurl.txt");
backgroundSha256 = builtins.readFile (./. + "../../../themes/"+("/"+theme)+"/backgroundsha256.txt");
in
{
home.file.".currenttheme".text = myTheme;
home.file.".currenttheme".text = theme;
stylix.autoEnable = false;
stylix.polarity = myThemePolarity;
stylix.polarity = themePolarity;
stylix.image = pkgs.fetchurl {
url = myBackgroundUrl;
sha256 = myBackgroundSha256;
url = backgroundUrl;
sha256 = backgroundSha256;
};
stylix.base16Scheme = ./. + myThemePath;
stylix.base16Scheme = ./. + themePath;
stylix.fonts = {
monospace = {
name = myFont;
package = myFontPkg;
name = font;
package = fontPkg;
};
serif = {
name = myFont;
package = myFontPkg;
name = font;
package = fontPkg;
};
sansSerif = {
name = myFont;
package = myFontPkg;
name = font;
package = fontPkg;
};
emoji = {
name = "Noto Color Emoji";
@ -51,8 +52,8 @@ in
#!/bin/sh
feh --no-fehbg --bg-fill ''+
pkgs.fetchurl {
url = myBackgroundUrl;
sha256 = myBackgroundSha256;
url = backgroundUrl;
sha256 = backgroundSha256;
}+'';
'';
home.file.".fehbg-stylix".executable = true;