From bc342f05e5fe673ad024af556425f1df8cb07846 Mon Sep 17 00:00:00 2001 From: Stefan Ellmauthaler Date: Tue, 16 Nov 2021 14:42:33 +0100 Subject: [PATCH] CONF added variables for different features to be defined hostbased Signed-off-by: Stefan Ellmauthaler --- baseconfiguration.nix | 9 +++++++-- default.nix | 4 +--- layer/default.nix | 4 ++++ layer/graphical.nix | 25 ++++++++++++++----------- machine/ellmauthaler/default.nix | 6 +++++- machine/nucturne/default.nix | 8 ++++++-- machine/stel-xps/default.nix | 8 ++++++-- options.nix | 21 +++++++++++++++++++++ users/ellmau/autorandr.nix | 2 +- users/ellmau/default.nix | 4 ++-- users/ellmau/dunst.nix | 2 +- users/ellmau/i3.nix | 12 +++++++----- users/ellmau/polybar.nix | 4 ++-- 13 files changed, 77 insertions(+), 32 deletions(-) create mode 100644 layer/default.nix create mode 100644 options.nix diff --git a/baseconfiguration.nix b/baseconfiguration.nix index 83e6ef8..a0b2159 100644 --- a/baseconfiguration.nix +++ b/baseconfiguration.nix @@ -1,4 +1,4 @@ -{ pkgs, name, type, flakes, flakeOutputs, ...}: +{ pkgs, name, flakes, flakeOutputs, ...}: { config, pkgs, lib, ...}: { imports = @@ -11,7 +11,11 @@ ./programs/aspell.nix # home-manager entry-point ./users - ] ++ type; + # layers + ./layer + # options + ./options.nix + ]; time.timeZone = "Europe/Berlin"; @@ -27,6 +31,7 @@ networking = { useDHCP = false; + hostName = config.variables.hostName; }; nix = { diff --git a/default.nix b/default.nix index 55b03b9..13362b9 100644 --- a/default.nix +++ b/default.nix @@ -6,9 +6,8 @@ let system = if args ? system then args.system else "x86_64-linux"; extraModules = if args ? extraModules then args.extraModules else [ ]; extraOverlays = if args ? extraOverlays then args.extraOverlays else [ ]; - type = if args ? type then args.type else [ ./layer/graphical.nix ]; pkgs = flakes.nixpkgs; - configuration = if args ? configuration then args.configuration else import ./baseconfiguration.nix {inherit extraOverlays system pkgs name type flakes flakeOutputs;} ; + configuration = if args ? configuration then args.configuration else import ./baseconfiguration.nix {inherit extraOverlays system pkgs name flakes flakeOutputs;} ; in { inherit name; @@ -35,6 +34,5 @@ flakes.nixpkgs.lib.listToAttrs (map mkMachine [ { name = "ellmauthaler"; extraModules = [ flakes.home-manager.nixosModules.home-manager ]; - type = [ ./layer/server.nix ]; } ]) diff --git a/layer/default.nix b/layer/default.nix new file mode 100644 index 0000000..cf515ab --- /dev/null +++ b/layer/default.nix @@ -0,0 +1,4 @@ +{ config, pkgs, lib, ...}: +{ + imports = [ ./graphical.nix ]; +} diff --git a/layer/graphical.nix b/layer/graphical.nix index f3d5f04..91bda45 100644 --- a/layer/graphical.nix +++ b/layer/graphical.nix @@ -1,13 +1,16 @@ -{ config, pkgs, ... }: +{ config, pkgs, lib, ... }: +let + isgraphical = config.variables.graphical; +in { - networking.networkmanager.enable = true; + networking.networkmanager.enable = isgraphical; services = { xserver = { - enable = true; - displayManager.lightdm.enable = true; + enable = isgraphical; + displayManager.lightdm.enable = isgraphical; windowManager.i3 = { - enable = true; + enable = isgraphical; extraPackages = with pkgs; [ rofi # launcher polybarFull # bar @@ -27,16 +30,16 @@ printing.enable = true; }; - sound.enable = true; + sound.enable = isgraphical; hardware = { - pulseaudio.enable = true; - bluetooth.enable = true; + pulseaudio.enable = isgraphical; + bluetooth.enable = isgraphical; }; - services.blueman.enable = true; + services.blueman.enable = isgraphical; - environment.systemPackages = with pkgs; [ + environment.systemPackages = if isgraphical then with pkgs; [ firefox alacritty thunderbird @@ -46,5 +49,5 @@ keepassxc gnome.libsecret arandr - ]; + ] else [ ]; } diff --git a/machine/ellmauthaler/default.nix b/machine/ellmauthaler/default.nix index 98ddf4d..2123497 100644 --- a/machine/ellmauthaler/default.nix +++ b/machine/ellmauthaler/default.nix @@ -1,7 +1,11 @@ { config, pkgs, ...}: { - networking ={ + + variables = { hostName = "ellmauthaler"; + }; + + networking = { domain = "net"; }; } diff --git a/machine/nucturne/default.nix b/machine/nucturne/default.nix index 43a8714..e14980a 100644 --- a/machine/nucturne/default.nix +++ b/machine/nucturne/default.nix @@ -1,4 +1,8 @@ { config, pkgs, ...}: { - networking.hostName = "nucturne"; # define the hostname -} \ No newline at end of file + variables= { + hostName = "nucturne"; + graphical = true; + }; + #networking.hostName = "nucturne"; # define the hostname +} diff --git a/machine/stel-xps/default.nix b/machine/stel-xps/default.nix index 3afcdec..c3e02e5 100644 --- a/machine/stel-xps/default.nix +++ b/machine/stel-xps/default.nix @@ -1,8 +1,12 @@ { config, pkgs, ...}: { imports = [ ./printer.nix ]; - - networking.hostName = "stel-xps"; # define the hostname + + variables = { + hostName = "stel-xps"; + graphical = true; + }; + #networking.hostName = "stel-xps"; # define the hostname environment.systemPackages = with pkgs; [ brightnessctl diff --git a/options.nix b/options.nix new file mode 100644 index 0000000..a93c16b --- /dev/null +++ b/options.nix @@ -0,0 +1,21 @@ +{ config, pkgs, lib, ...}: +{ + options.variables = with lib; { + hostName = mkOption { + type = types.str; + example = "nucturne"; + description = "Hostname of the system"; + default = "hostnamenotset"; + }; + graphical = mkOption { + type = types.bool; + default = false; + description = "Whether to enable the graphical environment"; + }; + server = mkOption { + type = types.bool; + default = false; + description = "Whether this system is a server"; + }; + }; +} diff --git a/users/ellmau/autorandr.nix b/users/ellmau/autorandr.nix index d5f0bff..effda6d 100644 --- a/users/ellmau/autorandr.nix +++ b/users/ellmau/autorandr.nix @@ -2,7 +2,7 @@ { home-manager.users.ellmau = { programs.autorandr = { - enable = true; + enable = config.variables.graphical; profiles = { "home" = { fingerprint = { diff --git a/users/ellmau/default.nix b/users/ellmau/default.nix index 88cb0a4..2099dc5 100644 --- a/users/ellmau/default.nix +++ b/users/ellmau/default.nix @@ -40,8 +40,8 @@ notify = true; tray = "auto"; }; - blueman-applet.enable = true; - network-manager-applet.enable = true ; + blueman-applet.enable = config.variables.graphical; + network-manager-applet.enable = config.variables.graphical ; gnome-keyring = { enable = true; components = [ "pkcs11" "secrets" "ssh" ]; diff --git a/users/ellmau/dunst.nix b/users/ellmau/dunst.nix index 0ba9b8f..055477d 100644 --- a/users/ellmau/dunst.nix +++ b/users/ellmau/dunst.nix @@ -2,7 +2,7 @@ { home-manager.users.ellmau = { services.dunst = { - enable = true; + enable = config.variables.graphical; iconTheme = { package = pkgs.numix-icon-theme; name = "Numix"; diff --git a/users/ellmau/i3.nix b/users/ellmau/i3.nix index 6698cbf..0fff9e7 100644 --- a/users/ellmau/i3.nix +++ b/users/ellmau/i3.nix @@ -1,10 +1,12 @@ { config, pkgs, lib, ...}: { - home-manager.users.ellmau = { - xdg = { - configFile."i3" = { - source = conf/i3; - recursive = true; + config = lib.mkIf config.variables.graphical { + home-manager.users.ellmau = { + xdg = { + configFile."i3" = { + source = conf/i3; + recursive = true; + }; }; }; }; diff --git a/users/ellmau/polybar.nix b/users/ellmau/polybar.nix index dae87d2..39518ac 100644 --- a/users/ellmau/polybar.nix +++ b/users/ellmau/polybar.nix @@ -1,8 +1,8 @@ -{ pkgs, ...}: +{ config, pkgs, ...}: { home-manager.users.ellmau = { services.polybar = { - enable = true; + enable = config.variables.graphical; package = pkgs.polybarFull; settings = let