Move colors and machinevars into modules

This commit is contained in:
Oystein Kristoffer Tveit 2022-06-21 01:47:36 +02:00
parent 2eae0e5ebf
commit 79a995e19e
27 changed files with 456 additions and 275 deletions

View File

@ -1,30 +0,0 @@
rec {
monokai = {
foreground = monokai.white;
background = monokai.black;
black = "#272822";
red = "#f92672";
green = "#a6e22e";
yellow = "#f4bf75";
blue = "#66d9ef";
magenta = "#ae81ff";
cyan = "#a1efe4";
white = "#f8f8f2";
};
paper = {
background = "#f2e3bd";
foreground = "#2f343f";
black = "#222222";
red = "#C30771";
green = "#10A778";
yellow = "#A89C14";
blue = "#008ec4";
magenta = "#523C79";
cyan = "#20A5BA";
white = "#f7f3ee";
};
default = monokai;
}

View File

@ -25,6 +25,11 @@
inputs.nixpkgs.follows = "nixpkgs";
};
vscode-server = {
url = "github:msteen/nixos-vscode-server";
flake = false;
};
# Nix expressions and keys (TODO: move keys to another solution like agenix)
# which should be kept from the main repo for privacy reasons.
#
@ -36,10 +41,11 @@
};
};
outputs = {
outputs = inputs@{
self,
nixpkgs,
home-manager,
vscode-server,
secrets,
fonts,
dotfiles,
@ -59,19 +65,6 @@
overlays = [ self.overlays.lib ];
};
specialArgs = {
secrets = secrets.outputs.default;
colorTheme = import ./common/colors.nix;
inputs = {
inherit self;
inherit home-manager;
inherit dotfiles;
inherit fonts;
inherit website;
inherit secrets;
};
};
in {
overlays = {
lib = import ./overlays/lib;
@ -86,65 +79,45 @@
inherit system;
inherit pkgs;
extraSpecialArgs = specialArgs // {
machineVars = {
hostname = "machine";
headless = false;
screens = 1;
gaming = true;
laptop = false;
};
};
username = "h7x4";
homeDirectory = "/home/h7x4";
stateVersion = "22.05";
configuration = {
imports = [
./home.nix
./modules
];
machineVars = {
headless = false;
fixDisplayCommand = "echo 'not available'";
gaming = true;
development = true;
laptop = false;
};
};
};
};
nixosConfigurations = let
# String -> AttrSet -> AttrSet
nixSys = name: extraOpts: machineVars:
nixSys = name:
nixpkgs.lib.nixosSystem {
inherit system;
inherit pkgs;
inherit (pkgs) lib;
specialArgs = specialArgs // { inherit machineVars; };
modules = [
"${home-manager}/nixos"
./modules
./hosts/common.nix
./hosts/${name}/configuration.nix
"${vscode-server}/default.nix"
{ config._module.args = { inherit inputs; secrets = secrets.outputs.default; }; }
];
} // extraOpts;
};
in {
Tsuki = nixSys "tsuki" {} {
hostname = "tsuki";
headless = true;
gaming = false;
laptop = false;
Tsuki = nixSys "tsuki";
Eisei = nixSys "eisei";
kasei = nixSys "kasei";
};
Eisei = nixSys "eisei" {} {
hostname = "eisei";
headless = false;
screens = 1;
gaming = false;
laptop = true;
};
kasei = nixSys "kasei" {} {
hostname = "kasei";
headless = false;
screens = 2;
gaming = true;
laptop = false;
};
};
};
}

View File

@ -1,7 +1,7 @@
{ pkgs, machineVars, inputs, ... } @ args: let
{ pkgs, config, inputs, ... } @ args: let
inherit (pkgs) lib;
inherit (pkgs.lib) mkForce mkIf optionals;
graphics = !machineVars.headless;
graphics = !config.machineVars.headless;
in {
imports = [
./shellOptions.nix
@ -17,6 +17,8 @@ in {
./programs/tmux.nix
./programs/zsh
./modules
inputs.secrets.outputs.nixosModule
] ++ optionals graphics [
./misc/mimetypes.nix
@ -38,6 +40,8 @@ in {
./services/sxhkd.nix
];
inherit (config) machineVars colors;
home = {
stateVersion = "22.05";
username = "h7x4";

View File

@ -1,14 +1,17 @@
{ pkgs, config, inputs, specialArgs, ... }:
{ pkgs, config, inputs, secrets, ... }:
let
inherit (pkgs) lib;
# inherit (specialArgs) machineVars;
inherit (config) machineVars;
has_graphics = !config.machineVars.headless;
in {
time.timeZone = "Europe/Oslo";
i18n.defaultLocale = "en_US.UTF-8";
# nixpkgs.config = {
# allowUnfree = true;
# };
nixpkgs.config = {
allowUnfree = true;
};
console = {
font = "Lat2-Terminus16";
@ -30,7 +33,7 @@ in {
builders-use-substitutes = true
'';
distributedBuilds = config.networking.hostname != "Tsuki";
distributedBuilds = (config.networking.hostName != "Tsuki");
binaryCaches = [
"https://cache.nixos.org/"
];
@ -58,11 +61,11 @@ in {
VISUAL = "nvim";
};
systemPackages = with pkgs; [
systemPackages = with pkgs; ([
wget
] + lib.optionals (!machineVars.headless) [
] ++ (lib.optionals (!machineVars.headless) [
haskellPackages.xmobar
];
]));
shells = with pkgs; [
bashInteractive
@ -101,6 +104,8 @@ in {
fonts = {
enableDefaultFonts = true;
fontDir.enable = true;
fonts = with pkgs; [
cm_unicode
dejavu_fonts
@ -154,18 +159,19 @@ in {
home-manager = {
useGlobalPkgs = true;
extraSpecialArgs = specialArgs;
extraSpecialArgs = { inherit inputs; inherit secrets; };
# TODO: figure out why specialArgs isn't accessible from the root home file.
users.h7x4 = import ../home.nix {
inherit pkgs;
inherit (specialArgs) machineVars inputs;
inherit inputs;
inherit config;
};
};
services = {
tumbler.enable = !machineVars.headless;
gnome.gnome-keyring.enable = !machineVars.headless;
tumbler.enable = !config.machineVars.headless;
gnome.gnome-keyring.enable = !config.machineVars.headless;
openssh = {
# enable = true;
@ -175,7 +181,7 @@ in {
};
dbus = {
enable = !machineVars.headless;
# enable = !machineVars.headless;
packages = with pkgs; [
gcr
dconf
@ -183,7 +189,17 @@ in {
};
xserver = {
enable = !machineVars.headless;
# TODO: What is going on here?
# For some reason, this leads to infinite recursion.
# This needs to be fixed!
# Same with `displayManager.lightdm.enable`
# options are defined in each hosts config file for the time being.
#
# I have a hypothesis that there are some asserts within xserver that
# makes it so that other software can not be activated at the same time
# and that those asserts triggers some kind of evaluation chain that
# recurses infinitely.
# enable = !config.machineVars.headless;
layout = "us";
xkbOptions = "caps:escape";
@ -194,7 +210,7 @@ in {
desktopManager = {
xterm.enable = false;
xfce.enable = true;
xfce.enable = !config.machineVars.headless;
};
windowManager.xmonad = {
@ -204,16 +220,16 @@ in {
# displayManager.startx.enable = true;
# displayManager.gdm.enable = true;
displayManager.lightdm.enable = true;
# displayManager.lightdm.enable = !config.machineVars.headless;
displayManager.defaultSession = "none+xmonad";
};
};
programs = {
dconf.enable = !machineVars.headless;
dconf.enable = !config.machineVars.headless;
git.enable = true;
light.enable = !machineVars.headless;
light.enable = !config.machineVars.headless;
npm.enable = true;
tmux.enable = true;
@ -252,12 +268,63 @@ in {
};
};
environment.shellAliases.fixDisplay = let
inherit (config.machineVars) screens headless fixDisplayCommand;
screenToArgs = screen: with screen;
"--output ${name} --mode ${resolution}"
+ (lib.optionalString (frequency != null) " --rate ${frequency}");
screenArgs = lib.concatStringsSep " " (lib.mapAttrsToList screenToArgs screens);
in lib.mkIf (!headless)
(lib.mkMerge [
"xrandr ${screenArgs}"
(lib.mkIf (fixDisplayCommand != null) fixDisplayCommand)
]);
system.extraDependencies =
lib.optionals (config.machineVars.development) (with pkgs; [
asciidoc
asciidoctor
cabal2nix
clang
dart
dotnet-sdk
dotnet-sdk_3
dotnet-sdk_5
dotnetPackages.Nuget
elm2nix
elmPackages.elm
flutter
gcc
ghc
ghcid
haskellPackages.Cabal_3_6_3_0
maven
nixfmt
nixpkgs-fmt
# nixpkgs-hammering
nodePackages.node2nix
nodePackages.npm
nodePackages.sass
nodePackages.typescript
nodePackages.yarn
nodejs
plantuml
python3
rustc
rustc
rustup
sqlcheck
sqlint
sqlite
sqlite-web
]);
sound = {
enable = !machineVars.headless;
enable = !config.machineVars.headless;
mediaKeys.enable = true;
};
hardware.pulseaudio.enable = !machineVars.headless;
hardware.pulseaudio.enable = !config.machineVars.headless;
security.sudo.extraConfig = ''
Defaults lecture = always

View File

@ -6,9 +6,27 @@
in {
imports = [
./hardware-configuration.nix
../../pluggables/tools/programming.nix
];
# TODO: See ../common.nix
services.xserver.enable = true;
services.xserver.displayManager.lightdm.enable = true;
machineVars = {
gaming = true;
creative = true;
development = true;
headless = false;
laptop = true;
screens = {
"eDP-1" = {
resolution = "1920x1080";
};
};
};
systemd.targets = {
sleep.enable = false;
suspend.enable = false;

View File

@ -2,9 +2,12 @@
{
imports = [
./hardware-configuration.nix
../../pluggables/tools/programming.nix
];
# TODO: See ../common.nix
services.xserver.enable = true;
services.xserver.displayManager.lightdm.enable = true;
systemd.targets = {
sleep.enable = false;
suspend.enable = false;

View File

@ -1,29 +1,36 @@
{ config, lib, pkgs, ... }:
{
imports =
[
imports = [
./hardware-configuration.nix
../../pluggables/tools/programming.nix
./services/nginx.nix
# ./services/dokuwiki.nix
# ./services/gitlab
./services/gitea
./services/jitsi.nix
# ./services/openldap.nix
./services/plex.nix
./services/hydra.nix
./services/matrix.nix
# ./services/libvirt.nix
./services/grafana.nix
# ./services/calibre.nix
# ./services/dokuwiki.nix
./services/gitea
# ./services/gitlab
./services/grafana.nix
./services/hydra.nix
./services/jitsi.nix
# ./services/keycloak.nix
# ./services/libvirt.nix
./services/matrix.nix
./services/nginx.nix
# ./services/openldap.nix
./services/openvpn.nix
./services/plex.nix
# ./services/samba.nix
./services/searx.nix
# ./services/syncthing.nix
./services/vscode-server.nix
];
# TODO: See ../common.nix
services.xserver.enable = false;
services.xserver.displayManager.lightdm.enable = false;
machineVars = {
headless = true;
};
systemd.targets = {
sleep.enable = false;
suspend.enable = false;

View File

@ -0,0 +1,9 @@
{ }:
{
services.keycloak = {
enable = true;
database = {
type = "postgresql";
};
};
}

View File

@ -21,7 +21,10 @@
listeners = [
{
port = secrets.ports.matrix.listener;
bind_address = "::1";
bind_addresses = [
"0.0.0.0"
"::1"
];
type = "http";
tls = false;
x_forwarded = true;
@ -58,7 +61,7 @@
};
};
services.redis.enable = true;
# services.redis.enable = true;
services.mx-puppet-discord = {
enable = true;

View File

@ -0,0 +1,17 @@
{ config, pkgs, lib, secrets, ... }: {
services.postgresql = {
enable = true;
# port = secrets.ports.postgres
# dataDir =
# settings = {};
};
services.pgadmin = {
enable = true;
openFirewall = true;
# port = secrets.ports.pgadmin
# settings = {
# };
};
}

View File

@ -0,0 +1,8 @@
{ ... }:
{
imports = [
(fetchTarball "https://github.com/msteen/nixos-vscode-server/tarball/master")
];
services.vscode-server.enable = true;
}

72
modules/colors.nix Normal file
View File

@ -0,0 +1,72 @@
{ pkgs, lib, config, ... }:
let
cfg = config.colors;
inherit (lib) types mkOption;
in {
options.colors = let
colorType = types.str;
mkColorOption = mkOption {
# name =
type = colorType;
};
colorSetType = types.submodule ({ name, ... }: {
name = mkOption {
type = types.str;
default = name;
};
foreground = mkColorOption;
background = mkColorOption;
black = mkColorOption;
red = mkColorOption;
green = mkColorOption;
yellow = mkColorOption;
blue = mkColorOption;
magenta = mkColorOption;
cyan = mkColorOption;
white = mkColorOption;
});
in {
colorSets = mkOption {
type = types.attrsof colorSetType;
};
defaultColorSet = mkOption {
description = "the default color to use for applications";
type = colorSetType;
default = cfg.color.colorSets.monokai;
};
};
config = {
colors.colorSets = {
monokai = rec {
foreground = white;
background = black;
black = "#272822";
red = "#f92672";
green = "#a6e22e";
yellow = "#f4bf75";
blue = "#66d9ef";
magenta = "#ae81ff";
cyan = "#a1efe4";
white = "#f8f8f2";
};
paper = {
background = "#f2e3bd";
foreground = "#2f343f";
black = "#222222";
red = "#C30771";
green = "#10A778";
yellow = "#A89C14";
blue = "#008ec4";
magenta = "#523C79";
cyan = "#20A5BA";
white = "#f7f3ee";
};
};
};
}

7
modules/default.nix Normal file
View File

@ -0,0 +1,7 @@
{ ... }:
{
imports = [
./colors.nix
./machineVars.nix
];
}

72
modules/machineVars.nix Normal file
View File

@ -0,0 +1,72 @@
{ pkgs, config, ... }:
let
inherit (pkgs) lib;
inherit (lib) types mkEnableOption mkOption mkIf;
cfg = config.machineVars;
in {
options.machineVars = {
headless = mkEnableOption "Whether or not the machine should have graphical output.";
screens = mkOption {
type = types.attrsOf (types.submodule ( { name, ...}: {
options = {
resolution = mkOption {
type = types.str;
example = "1920x1080";
description = "The resolution of the screen";
};
name = mkOption {
type = types.str;
default = name;
example = "DP-1";
description = "The name of the screen";
};
freq = mkOption {
type = types.nullOr types.str;
example = "60.00";
description = "The update frequency of the screen, defined in Hz";
};
};
}));
default = { };
description = "A detailed description of the machines screens.";
};
gaming = mkEnableOption "Whether or not the machine should have gaming software installed.";
development = mkEnableOption "Whether or not the machine should come with developmen
t tools preinstalled.";
creative = mkEnableOption "Whether or not the machine should have creative software
(music, video and image editing) installed.";
laptop = mkEnableOption "Whether the machine is a laptop";
fixDisplayCommand = mkOption {
type = types.nullOr types.str;
default = null;
};
};
config = {
assertions = [
{
assertion = cfg.headless -> !cfg.creative;
message = "A headless machine can't have creative software installed.";
}
{
assertion = cfg.headless -> !cfg.gaming;
message = "A headless machine can't have gaming software installed.";
}
{
assertion = cfg.headless -> (cfg.screens == { } && cfg.fixDisplayCommand == null);
message = "A headless machine can't have any screens.";
}
];
warnings = lib.optionals (0 < (lib.length (builtins.attrNames cfg.screens)) && (cfg.fixDisplayCommand != null)) [
"You are overriding the fixDisplayCommand even though machineVars.screens is defined. One of these should be omitted"
];
};
}

View File

@ -1,4 +1,4 @@
{ pkgs, machineVars, ... }:
{ pkgs, config, ... }:
{
home.packages = with pkgs; [
asciidoctor
@ -51,13 +51,14 @@
mmv
mps-youtube
mtr
navi
neofetch
nix-diff
nix-index
nix-output-monitor
nix-tree
nix-zsh-completions
nixops
# nixops
nmap
ouch
pandoc
@ -86,6 +87,8 @@
wavemon
wiki-tui
youtube-dl
yq
zip
# Needed for VSCode liveshare
desktop-file-utils
@ -94,8 +97,7 @@
icu
openssl
xorg.xprop
] ++ (
lib.optionals (!machineVars.headless) [
] ++ lib.optionals (!config.machineVars.headless) [
ahoviewer
anki
audacity
@ -151,9 +153,9 @@
zeal
zoom-us
zotero
] ++ lib.optionals (machineVars.laptop) [
] ++ lib.optionals (config.machineVars.laptop) [
touchegg
] ++ lib.optionals (machineVars.gaming) [
] ++ lib.optionals (config.machineVars.gaming) [
citra
desmume
minecraft
@ -163,7 +165,6 @@
steam-tui
stepmania
taisei
]
);
];
}

View File

@ -1,26 +0,0 @@
{ pkgs }:
{
services.deluge = {
enable = true;
user = "h7x4";
# https://git.deluge-torrent.org/deluge/tree/deluge/core/preferencesmanager.py#n41
# config = {
# download_location = "";
# share_ratio_limit = "";
# daemon_port = "";
# listen_ports = "";
# };
openFirewall = true;
# authFile =
declarative = true;
web = {
enable = true;
# port =
openFirewall = true;
};
};
}

View File

@ -1,41 +0,0 @@
{ pkgs, ... }:
{
system.extraDependencies = with pkgs; [
asciidoc
asciidoctor
cabal2nix
clang
dart
dotnet-sdk
dotnet-sdk_3
dotnet-sdk_5
dotnetPackages.Nuget
elm2nix
elmPackages.elm
flutter
gcc
ghc
ghcid
haskellPackages.Cabal_3_6_2_0
maven
nixfmt
nixpkgs-fmt
# nixpkgs-hammering
nodePackages.node2nix
nodePackages.npm
nodePackages.sass
nodePackages.typescript
nodePackages.yarn
nodejs
plantuml
python3
rustc
rustc
rustup
sqlcheck
sqlint
sqlite
sqlite-web
];
}

View File

@ -1,4 +1,4 @@
{ lib, pkgs, colorTheme, ... }:
{ pkgs, lib, config, ... }:
{
programs.alacritty = {
enable = true;
@ -22,10 +22,10 @@
primaryColors = [ "foreground" "background" ];
in
{
primary = getAttrs primaryColors colorTheme.default;
primary = getAttrs primaryColors config.colors.defaultColorSet;
normal = let
removePrimaryColorAttrs = n: v: !(any (pc: n ? pc) primaryColors);
in filterAttrs removePrimaryColorAttrs colorTheme.default;
in filterAttrs removePrimaryColorAttrs config.colors.defaultColorSet;
};
background_opacity = 1.0;

View File

@ -1,13 +1,36 @@
{ pkgs, colorTheme, ... }: let
{ pkgs, config, ... }: let
inherit (pkgs) lib;
in {
programs.xmobar = let
networkCard = "wlp2s0f0u7u4";
disks = [
"/"
"/data"
"/data/disks/data2"
];
mpd_status_script = pkgs.writeShellScript "mpd-status" ''
MPD_STATUS=$(${pkgs.mpc}/bin/mpc 2>/dev/null | sed -n '2{p;q}' | cut -d ' ' -f1)
case "$MPD_STATUS" in
"[playing]")
echo "<fn=2><fc=#00ff00></fc></fn>"
# echo "[<fn=2><fc=#00ff00>行</fc></fn>]"
exit 0
;;
"[paused]")
echo "<fn=2><fc=#ff0000></fc></fn>"
# echo "[<fn=1><fc=#ff0000>止</fc></fn>]"
exit 0
;;
*)
echo "<fn=2><fc=#AA0000></fc></fn>"
# echo "[<fn=1><fc=#AA0000>無</fc></fn>]"
exit 0
;;
esac
'';
in {
enable = true;
extraConfig = ''
@ -22,7 +45,7 @@ in {
]
, borderColor = "black"
, border = TopB
, bgColor = "#272822"
, bgColor = "${config.colors.defaultColorSet.background}"
, fgColor = "grey"
, alpha = 255
, position = Static { xpos = 0 , ypos = 0, width = 1920, height = 40 }
@ -48,7 +71,7 @@ in {
Run Memory ["-t","<usedratio>%"] 10,
Run Swap ["-t", "<usedratio>%"] 100,
Run Date "%a %_d %b - %H:%M - W%W" "date" 10,
Run Com "${./scripts/mpd_status.sh}" [] "mpc" 10,
Run Com "${mpd_status_script}" [] "mpc" 10,
-- Run Com "${./scripts/wireless.sh}" [] "wi" 100,
Run Com "${./scripts/volume.py}" [] "vol" 10,
Run UnsafeStdinReader,

View File

@ -1,4 +1,4 @@
{ colorTheme, ... }:
{ config, ... }:
{
services.stalonetray = {
enable = true;
@ -7,7 +7,7 @@
transparent = false;
dockapp_mode = "none";
geometry = "8x1-0+0";
background = colorTheme.default.background;
background = config.colors.defaultColorSet.background;
kludges = "force_icons_size";
grow_gravity = "NW";
icon_gravity = "NW";

View File

@ -1,4 +1,4 @@
{ pkgs, config, machineVars, ... }: let
{ pkgs, config, ... }: let
# FIXME: lib should be imported directly as a module argument.
inherit (pkgs) lib;
@ -141,6 +141,7 @@ in rec {
hms = "home-manager switch";
nxr = "sudo nixos-rebuild switch";
nxp = "nix-shell -p ";
nxc = "sudoedit /etc/nixos/configuration.nix";
nxh = "vim ~/.config/nixpkgs/home.nix";
@ -262,13 +263,6 @@ in rec {
view-latex = "${texlive.combined.scheme-full}/bin/latexmk -pdf -pvc main.tex";
reload-tmux = "${tmux}/bin/tmux source $HOME/.config/tmux/tmux.conf";
fixdisplay = let
commands = {
"kasei" = "xrandr --output DVI-I-1 --mode 1920x1080 --pos 1920x0 -r 60 --primary --output DP-3 --mode 1920x1080 --pos 0x0 -r 144";
};
in
if commands ? ${machineVars.hostname} then commands.${machineVars.hostname} else "echo \"fixdisplay not defined for this hostname\"";
};
# ░█▀▀░█▀▀░█▀█░█▀▀░█▀▄░█▀█░▀█▀░█▀▀░█▀▄