From aa1336bb8d8ff501d5977481298b4229d472416e Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 3 Jan 2024 16:49:19 +0000 Subject: [PATCH 01/18] modules: add common This should define modules that are identical, or very similar. The driving force is to be able to use `my.profiles` on home-manager and NixOS without repeating myself. In the future I might migrate other modules, such as `nixos/system/nix`... --- modules/common/default.nix | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 modules/common/default.nix diff --git a/modules/common/default.nix b/modules/common/default.nix new file mode 100644 index 0000000..d0c90de --- /dev/null +++ b/modules/common/default.nix @@ -0,0 +1,31 @@ +# Modules that are common to various module systems +# Usually with very small differences, if any, between them. +{ lib, type ? null, ... }: +let + allowedTypes = [ + "nixos" + "home" + "darwin" + ]; + + allowedTypesString = lib.concatStringSep ", " (builtins.map lib.escapeNixString allowedTypes); +in +{ + config = { + assertions = [ + { + assertion = type != null; + message = '' + You must provide `type` as part of specialArgs to use the common modules. + It must be one of ${allowedTypesString}. + ''; + } + { + assertion = type != null -> builtins.elem type allowedTypes; + message = '' + `type` specialArgs must be one of ${allowedTypesString}. + ''; + } + ]; + }; +} From d1137429055b7cd67ebf6d3438eb6880d9b0de84 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 3 Jan 2024 16:50:05 +0000 Subject: [PATCH 02/18] nixos: home: import common modules --- modules/common/default.nix | 4 ++-- modules/nixos/home/default.nix | 13 ++++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/modules/common/default.nix b/modules/common/default.nix index d0c90de..cb06c9e 100644 --- a/modules/common/default.nix +++ b/modules/common/default.nix @@ -3,9 +3,9 @@ { lib, type ? null, ... }: let allowedTypes = [ - "nixos" - "home" "darwin" + "home" + "nixos" ]; allowedTypesString = lib.concatStringSep ", " (builtins.map lib.escapeNixString allowedTypes); diff --git a/modules/nixos/home/default.nix b/modules/nixos/home/default.nix index fe00704..071509b 100644 --- a/modules/nixos/home/default.nix +++ b/modules/nixos/home/default.nix @@ -13,16 +13,23 @@ in config = lib.mkIf cfg.enable { home-manager = { - # Not a fan of out-of-directory imports, but this is a good exception - users.${config.my.user.name} = import "${inputs.self}/modules/home"; + users.${config.my.user.name} = { + # Not a fan of out-of-directory imports, but this is a good exception + imports = [ + "${inputs.self}/modules/common" + "${inputs.self}/modules/home" + ]; + }; # Nix Flakes compatibility useGlobalPkgs = true; useUserPackages = true; - # Forward inputs to home-manager configuration extraSpecialArgs = { + # Forward inputs to home-manager configuration inherit inputs; + # For consumption by common modules + type = "home"; }; }; }; From fe6df44b855ea700e35800d864134910e3caa0dd Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 3 Jan 2024 16:50:16 +0000 Subject: [PATCH 03/18] flake: home-manager: import common modules --- flake/home-manager.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/flake/home-manager.nix b/flake/home-manager.nix index 34af375..2f7e245 100644 --- a/flake/home-manager.nix +++ b/flake/home-manager.nix @@ -14,6 +14,8 @@ let # Enable home-manager programs.home-manager.enable = true; } + # Import common modules + "${self}/modules/common" ]; mkHome = name: system: inputs.home-manager.lib.homeManagerConfiguration { @@ -36,6 +38,8 @@ let extraSpecialArgs = { # Inject inputs to use them in global registry inherit inputs; + # For consumption by common modules + type = "home"; }; }; From 61c234d9323a2ca3028bf4adbe1e1dc53d400958 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 3 Jan 2024 16:50:22 +0000 Subject: [PATCH 04/18] flake: nixos: import common modules --- flake/nixos.nix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/flake/nixos.nix b/flake/nixos.nix index b48b551..c5d9ede 100644 --- a/flake/nixos.nix +++ b/flake/nixos.nix @@ -12,6 +12,8 @@ let } # Include generic settings "${self}/modules/nixos" + # Import common modules + "${self}/modules/common" ]; buildHost = name: system: lib.nixosSystem { @@ -24,6 +26,8 @@ let inherit (self) lib; # Inject inputs to use them in global registry inherit inputs; + # For consumption by common modules + type = "nixos"; }; }; in From 2027bb327e4ba3f875f8322b2d48b185d863f03e Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 3 Jan 2024 16:51:34 +0000 Subject: [PATCH 05/18] common: add profiles I will be migrating each sub-module one by one. --- modules/common/default.nix | 4 ++++ modules/common/profiles/default.nix | 7 +++++++ 2 files changed, 11 insertions(+) create mode 100644 modules/common/profiles/default.nix diff --git a/modules/common/default.nix b/modules/common/default.nix index cb06c9e..0a26f45 100644 --- a/modules/common/default.nix +++ b/modules/common/default.nix @@ -11,6 +11,10 @@ let allowedTypesString = lib.concatStringSep ", " (builtins.map lib.escapeNixString allowedTypes); in { + imports = [ + ./profiles + ]; + config = { assertions = [ { diff --git a/modules/common/profiles/default.nix b/modules/common/profiles/default.nix new file mode 100644 index 0000000..06511ac --- /dev/null +++ b/modules/common/profiles/default.nix @@ -0,0 +1,7 @@ +# Configuration that spans accross system and home, or are almagations of modules +{ ... }: +{ + imports = [ + # FIXME: empty + ]; +} From 034cd3ac550f5aa8bc5606f87d15ab911bcad42d Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 3 Jan 2024 16:51:34 +0000 Subject: [PATCH 06/18] common: profiles: migrate bluetooth --- modules/common/profiles/bluetooth/default.nix | 19 +++++++++++++++++++ modules/common/profiles/default.nix | 2 +- modules/nixos/profiles/bluetooth/default.nix | 15 --------------- modules/nixos/profiles/default.nix | 1 - 4 files changed, 20 insertions(+), 17 deletions(-) create mode 100644 modules/common/profiles/bluetooth/default.nix delete mode 100644 modules/nixos/profiles/bluetooth/default.nix diff --git a/modules/common/profiles/bluetooth/default.nix b/modules/common/profiles/bluetooth/default.nix new file mode 100644 index 0000000..bfb8bfc --- /dev/null +++ b/modules/common/profiles/bluetooth/default.nix @@ -0,0 +1,19 @@ +{ config, lib, type, ... }: +let + cfg = config.my.profiles.bluetooth; +in +{ + options.my.profiles.bluetooth = with lib; { + enable = mkEnableOption "bluetooth profile"; + }; + + config = lib.mkIf cfg.enable (lib.mkMerge [ + (lib.optionalAttrs (type == "home") { + my.home.bluetooth.enable = true; + }) + + (lib.optionalAttrs (type == "nixos") { + my.hardware.bluetooth.enable = true; + }) + ]); +} diff --git a/modules/common/profiles/default.nix b/modules/common/profiles/default.nix index 06511ac..a71f3be 100644 --- a/modules/common/profiles/default.nix +++ b/modules/common/profiles/default.nix @@ -2,6 +2,6 @@ { ... }: { imports = [ - # FIXME: empty + ./bluetooth ]; } diff --git a/modules/nixos/profiles/bluetooth/default.nix b/modules/nixos/profiles/bluetooth/default.nix deleted file mode 100644 index 292d0d1..0000000 --- a/modules/nixos/profiles/bluetooth/default.nix +++ /dev/null @@ -1,15 +0,0 @@ -{ config, lib, ... }: -let - cfg = config.my.profiles.bluetooth; -in -{ - options.my.profiles.bluetooth = with lib; { - enable = mkEnableOption "bluetooth profile"; - }; - - config = lib.mkIf cfg.enable { - my.hardware.bluetooth.enable = true; - - my.home.bluetooth.enable = true; - }; -} diff --git a/modules/nixos/profiles/default.nix b/modules/nixos/profiles/default.nix index 43d5a84..c442eec 100644 --- a/modules/nixos/profiles/default.nix +++ b/modules/nixos/profiles/default.nix @@ -2,7 +2,6 @@ { ... }: { imports = [ - ./bluetooth ./devices ./gtk ./laptop From ac03fb3b316e8bbf2e42ab39596061643ba1cb85 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 3 Jan 2024 17:03:09 +0000 Subject: [PATCH 07/18] common: profiles: migrate devices --- modules/common/profiles/default.nix | 1 + modules/common/profiles/devices/default.nix | 22 +++++++++++++++++++++ modules/nixos/profiles/default.nix | 1 - modules/nixos/profiles/devices/default.nix | 20 ------------------- 4 files changed, 23 insertions(+), 21 deletions(-) create mode 100644 modules/common/profiles/devices/default.nix delete mode 100644 modules/nixos/profiles/devices/default.nix diff --git a/modules/common/profiles/default.nix b/modules/common/profiles/default.nix index a71f3be..447e906 100644 --- a/modules/common/profiles/default.nix +++ b/modules/common/profiles/default.nix @@ -3,5 +3,6 @@ { imports = [ ./bluetooth + ./devices ]; } diff --git a/modules/common/profiles/devices/default.nix b/modules/common/profiles/devices/default.nix new file mode 100644 index 0000000..bd16d70 --- /dev/null +++ b/modules/common/profiles/devices/default.nix @@ -0,0 +1,22 @@ +{ config, lib, type, ... }: +let + cfg = config.my.profiles.devices; +in +{ + options.my.profiles.devices = with lib; { + enable = mkEnableOption "devices profile"; + }; + + config = lib.mkIf cfg.enable (lib.mkMerge [ + (lib.optionalAttrs (type == "nixos") { + my.hardware = { + ergodox.enable = true; + + mx-ergo.enable = true; + }; + + # MTP devices auto-mount via file explorers + services.gvfs.enable = true; + }) + ]); +} diff --git a/modules/nixos/profiles/default.nix b/modules/nixos/profiles/default.nix index c442eec..2bcbba2 100644 --- a/modules/nixos/profiles/default.nix +++ b/modules/nixos/profiles/default.nix @@ -2,7 +2,6 @@ { ... }: { imports = [ - ./devices ./gtk ./laptop ./wm diff --git a/modules/nixos/profiles/devices/default.nix b/modules/nixos/profiles/devices/default.nix deleted file mode 100644 index 7dbd299..0000000 --- a/modules/nixos/profiles/devices/default.nix +++ /dev/null @@ -1,20 +0,0 @@ -{ config, lib, ... }: -let - cfg = config.my.profiles.devices; -in -{ - options.my.profiles.devices = with lib; { - enable = mkEnableOption "devices profile"; - }; - - config = lib.mkIf cfg.enable { - my.hardware = { - ergodox.enable = true; - - mx-ergo.enable = true; - }; - - # MTP devices auto-mount via file explorers - services.gvfs.enable = true; - }; -} From 9f82f2a7e869c349546226133b245189c35798c9 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 3 Jan 2024 17:03:47 +0000 Subject: [PATCH 08/18] common: profiles: migrate gtk --- modules/common/profiles/default.nix | 1 + modules/common/profiles/gtk/default.nix | 21 +++++++++++++++++++++ modules/nixos/profiles/default.nix | 1 - modules/nixos/profiles/gtk/default.nix | 17 ----------------- 4 files changed, 22 insertions(+), 18 deletions(-) create mode 100644 modules/common/profiles/gtk/default.nix delete mode 100644 modules/nixos/profiles/gtk/default.nix diff --git a/modules/common/profiles/default.nix b/modules/common/profiles/default.nix index 447e906..30c1f29 100644 --- a/modules/common/profiles/default.nix +++ b/modules/common/profiles/default.nix @@ -4,5 +4,6 @@ imports = [ ./bluetooth ./devices + ./gtk ]; } diff --git a/modules/common/profiles/gtk/default.nix b/modules/common/profiles/gtk/default.nix new file mode 100644 index 0000000..3fe1309 --- /dev/null +++ b/modules/common/profiles/gtk/default.nix @@ -0,0 +1,21 @@ +{ config, lib, type, ... }: +let + cfg = config.my.profiles.gtk; +in +{ + options.my.profiles.gtk = with lib; { + enable = mkEnableOption "gtk profile"; + }; + + config = lib.mkIf cfg.enable (lib.mkMerge [ + (lib.optionalAttrs (type == "home") { + # GTK theme configuration + my.home.gtk.enable = true; + }) + + (lib.optionalAttrs (type == "nixos") { + # Allow setting GTK configuration using home-manager + programs.dconf.enable = true; + }) + ]); +} diff --git a/modules/nixos/profiles/default.nix b/modules/nixos/profiles/default.nix index 2bcbba2..683bd87 100644 --- a/modules/nixos/profiles/default.nix +++ b/modules/nixos/profiles/default.nix @@ -2,7 +2,6 @@ { ... }: { imports = [ - ./gtk ./laptop ./wm ./x diff --git a/modules/nixos/profiles/gtk/default.nix b/modules/nixos/profiles/gtk/default.nix deleted file mode 100644 index a8d6d9a..0000000 --- a/modules/nixos/profiles/gtk/default.nix +++ /dev/null @@ -1,17 +0,0 @@ -{ config, lib, ... }: -let - cfg = config.my.profiles.gtk; -in -{ - options.my.profiles.gtk = with lib; { - enable = mkEnableOption "gtk profile"; - }; - - config = lib.mkIf cfg.enable { - # Allow setting GTK configuration using home-manager - programs.dconf.enable = true; - - # GTK theme configuration - my.home.gtk.enable = true; - }; -} From 53594d2fb4f00e9d47e3e4cc8c6224b37329180c Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 3 Jan 2024 17:05:16 +0000 Subject: [PATCH 09/18] common: profiles: migrate laptop --- modules/common/profiles/default.nix | 1 + modules/common/profiles/laptop/default.nix | 27 ++++++++++++++++++++++ modules/nixos/profiles/default.nix | 1 - modules/nixos/profiles/laptop/default.nix | 23 ------------------ 4 files changed, 28 insertions(+), 24 deletions(-) create mode 100644 modules/common/profiles/laptop/default.nix delete mode 100644 modules/nixos/profiles/laptop/default.nix diff --git a/modules/common/profiles/default.nix b/modules/common/profiles/default.nix index 30c1f29..712e20b 100644 --- a/modules/common/profiles/default.nix +++ b/modules/common/profiles/default.nix @@ -5,5 +5,6 @@ ./bluetooth ./devices ./gtk + ./laptop ]; } diff --git a/modules/common/profiles/laptop/default.nix b/modules/common/profiles/laptop/default.nix new file mode 100644 index 0000000..68e979a --- /dev/null +++ b/modules/common/profiles/laptop/default.nix @@ -0,0 +1,27 @@ +{ config, lib, type, ... }: +let + cfg = config.my.profiles.laptop; +in +{ + options.my.profiles.laptop = with lib; { + enable = mkEnableOption "laptop profile"; + }; + + config = lib.mkIf cfg.enable (lib.mkMerge [ + (lib.optionalAttrs (type == "home") { + # Enable battery notifications + my.home.power-alert.enable = true; + }) + + (lib.optionalAttrs (type == "nixos") { + # Enable touchpad support + services.xserver.libinput.enable = true; + + # Enable TLP power management + my.services.tlp.enable = true; + + # Enable upower power management + my.hardware.upower.enable = true; + }) + ]); +} diff --git a/modules/nixos/profiles/default.nix b/modules/nixos/profiles/default.nix index 683bd87..1951298 100644 --- a/modules/nixos/profiles/default.nix +++ b/modules/nixos/profiles/default.nix @@ -2,7 +2,6 @@ { ... }: { imports = [ - ./laptop ./wm ./x ]; diff --git a/modules/nixos/profiles/laptop/default.nix b/modules/nixos/profiles/laptop/default.nix deleted file mode 100644 index 20a29d7..0000000 --- a/modules/nixos/profiles/laptop/default.nix +++ /dev/null @@ -1,23 +0,0 @@ -{ config, lib, ... }: -let - cfg = config.my.profiles.laptop; -in -{ - options.my.profiles.laptop = with lib; { - enable = mkEnableOption "laptop profile"; - }; - - config = lib.mkIf cfg.enable { - # Enable touchpad support - services.xserver.libinput.enable = true; - - # Enable TLP power management - my.services.tlp.enable = true; - - # Enable upower power management - my.hardware.upower.enable = true; - - # Enable battery notifications - my.home.power-alert.enable = true; - }; -} From 334a3346b85e09645a0acaec8655bf62e4857695 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 3 Jan 2024 17:05:37 +0000 Subject: [PATCH 10/18] common: profiles: migrate wm --- modules/common/profiles/default.nix | 1 + modules/common/profiles/wm/default.nix | 36 ++++++++++++++++++++++++++ modules/nixos/profiles/default.nix | 1 - modules/nixos/profiles/wm/default.nix | 29 --------------------- 4 files changed, 37 insertions(+), 30 deletions(-) create mode 100644 modules/common/profiles/wm/default.nix delete mode 100644 modules/nixos/profiles/wm/default.nix diff --git a/modules/common/profiles/default.nix b/modules/common/profiles/default.nix index 712e20b..034d993 100644 --- a/modules/common/profiles/default.nix +++ b/modules/common/profiles/default.nix @@ -6,5 +6,6 @@ ./devices ./gtk ./laptop + ./wm ]; } diff --git a/modules/common/profiles/wm/default.nix b/modules/common/profiles/wm/default.nix new file mode 100644 index 0000000..4c974e1 --- /dev/null +++ b/modules/common/profiles/wm/default.nix @@ -0,0 +1,36 @@ +{ config, lib, type, ... }: +let + cfg = config.my.profiles.wm; + + applyWm = wm: configs: lib.mkIf (cfg.windowManager == wm) (lib.my.merge configs); +in +{ + options.my.profiles.wm = with lib; { + windowManager = mkOption { + type = with types; nullOr (enum [ "i3" ]); + default = null; + example = "i3"; + description = "Which window manager to use"; + }; + }; + + config = lib.mkMerge [ + (applyWm "i3" [ + (lib.optionalAttrs (type == "home") { + # i3 settings + my.home.wm.windowManager = "i3"; + # Screenshot tool + my.home.flameshot.enable = true; + # Auto disk mounter + my.home.udiskie.enable = true; + }) + + (lib.optionalAttrs (type == "nixos") { + # Enable i3 + services.xserver.windowManager.i3.enable = true; + # udiskie fails if it can't find this dbus service + services.udisks2.enable = true; + }) + ]) + ]; +} diff --git a/modules/nixos/profiles/default.nix b/modules/nixos/profiles/default.nix index 1951298..6b4db55 100644 --- a/modules/nixos/profiles/default.nix +++ b/modules/nixos/profiles/default.nix @@ -2,7 +2,6 @@ { ... }: { imports = [ - ./wm ./x ]; } diff --git a/modules/nixos/profiles/wm/default.nix b/modules/nixos/profiles/wm/default.nix deleted file mode 100644 index c227328..0000000 --- a/modules/nixos/profiles/wm/default.nix +++ /dev/null @@ -1,29 +0,0 @@ -{ config, lib, ... }: -let - cfg = config.my.profiles.wm; -in -{ - options.my.profiles.wm = with lib; { - windowManager = mkOption { - type = with types; nullOr (enum [ "i3" ]); - default = null; - example = "i3"; - description = "Which window manager to use"; - }; - }; - - config = lib.mkMerge [ - (lib.mkIf (cfg.windowManager == "i3") { - # Enable i3 - services.xserver.windowManager.i3.enable = true; - # i3 settings - my.home.wm.windowManager = "i3"; - # Screenshot tool - my.home.flameshot.enable = true; - # Auto disk mounter - my.home.udiskie.enable = true; - # udiskie fails if it can't find this dbus service - services.udisks2.enable = true; - }) - ]; -} From ad17fed0bfacd35230780bc4f949a2dedcb5ae04 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 3 Jan 2024 17:05:54 +0000 Subject: [PATCH 11/18] common: profiles: migrate X --- modules/common/profiles/default.nix | 1 + modules/common/profiles/x/default.nix | 27 +++++++++++++++++++++++++++ modules/nixos/default.nix | 1 - modules/nixos/profiles/default.nix | 7 ------- modules/nixos/profiles/x/default.nix | 23 ----------------------- 5 files changed, 28 insertions(+), 31 deletions(-) create mode 100644 modules/common/profiles/x/default.nix delete mode 100644 modules/nixos/profiles/default.nix delete mode 100644 modules/nixos/profiles/x/default.nix diff --git a/modules/common/profiles/default.nix b/modules/common/profiles/default.nix index 034d993..43d5a84 100644 --- a/modules/common/profiles/default.nix +++ b/modules/common/profiles/default.nix @@ -7,5 +7,6 @@ ./gtk ./laptop ./wm + ./x ]; } diff --git a/modules/common/profiles/x/default.nix b/modules/common/profiles/x/default.nix new file mode 100644 index 0000000..907e03c --- /dev/null +++ b/modules/common/profiles/x/default.nix @@ -0,0 +1,27 @@ +{ config, lib, pkgs, type, ... }: +let + cfg = config.my.profiles.x; +in +{ + options.my.profiles.x = with lib; { + enable = mkEnableOption "X profile"; + }; + + config = lib.mkIf cfg.enable (lib.mkMerge [ + (lib.optionalAttrs (type == "home") { + # X configuration + my.home.x.enable = true; + }) + + (lib.optionalAttrs (type == "nixos") { + # Enable the X11 windowing system. + services.xserver.enable = true; + # Nice wallpaper + services.xserver.displayManager.lightdm.background = + let + wallpapers = "${pkgs.plasma5Packages.plasma-workspace-wallpapers}/share/wallpapers"; + in + "${wallpapers}/summer_1am/contents/images/2560x1600.jpg"; + }) + ]); +} diff --git a/modules/nixos/default.nix b/modules/nixos/default.nix index 3648631..2eaa2e6 100644 --- a/modules/nixos/default.nix +++ b/modules/nixos/default.nix @@ -5,7 +5,6 @@ imports = [ ./hardware ./home - ./profiles ./programs ./secrets ./services diff --git a/modules/nixos/profiles/default.nix b/modules/nixos/profiles/default.nix deleted file mode 100644 index 6b4db55..0000000 --- a/modules/nixos/profiles/default.nix +++ /dev/null @@ -1,7 +0,0 @@ -# Configuration that spans accross system and home, or are almagations of modules -{ ... }: -{ - imports = [ - ./x - ]; -} diff --git a/modules/nixos/profiles/x/default.nix b/modules/nixos/profiles/x/default.nix deleted file mode 100644 index ea77939..0000000 --- a/modules/nixos/profiles/x/default.nix +++ /dev/null @@ -1,23 +0,0 @@ -{ config, lib, pkgs, ... }: -let - cfg = config.my.profiles.x; -in -{ - options.my.profiles.x = with lib; { - enable = mkEnableOption "X profile"; - }; - - config = lib.mkIf cfg.enable { - # Enable the X11 windowing system. - services.xserver.enable = true; - # Nice wallpaper - services.xserver.displayManager.lightdm.background = - let - wallpapers = "${pkgs.plasma5Packages.plasma-workspace-wallpapers}/share/wallpapers"; - in - "${wallpapers}/summer_1am/contents/images/2560x1600.jpg"; - - # X configuration - my.home.x.enable = true; - }; -} From 272a8fb7b992b1ebfa3da23d0adce5b85efbea5f Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 3 Jan 2024 16:51:34 +0000 Subject: [PATCH 12/18] common: profiles: forward profiles to home-manager We can only do this now that every profile has been migrated, otherwise we would get errors about undeclared modules... It's not perfect, but it's good enough. This is only done for `type == "nixos"` for now, as I don't have any Darwin configurations... --- modules/common/profiles/default.nix | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/modules/common/profiles/default.nix b/modules/common/profiles/default.nix index 43d5a84..d899bc7 100644 --- a/modules/common/profiles/default.nix +++ b/modules/common/profiles/default.nix @@ -1,5 +1,5 @@ # Configuration that spans accross system and home, or are almagations of modules -{ ... }: +{ config, lib, type, ... }: { imports = [ ./bluetooth @@ -9,4 +9,17 @@ ./wm ./x ]; + + config = lib.mkMerge [ + # Transparently enable home-manager profiles as well + (lib.optionalAttrs (type == "nixos") { + home-manager.users.${config.my.user.name} = { + config = { + my = { + inherit (config.my) profiles; + }; + }; + }; + }) + ]; } From 33a7d0a141353f472f46e492c3b02a1f697184e7 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 3 Jan 2024 17:55:14 +0000 Subject: [PATCH 13/18] hosts: nixos: porthos: add profiles --- hosts/nixos/porthos/default.nix | 1 + hosts/nixos/porthos/profiles.nix | 4 ++++ 2 files changed, 5 insertions(+) create mode 100644 hosts/nixos/porthos/profiles.nix diff --git a/hosts/nixos/porthos/default.nix b/hosts/nixos/porthos/default.nix index 2dea899..39e2998 100644 --- a/hosts/nixos/porthos/default.nix +++ b/hosts/nixos/porthos/default.nix @@ -7,6 +7,7 @@ ./hardware.nix ./home.nix ./networking.nix + ./profiles.nix ./secrets ./services.nix ./system.nix diff --git a/hosts/nixos/porthos/profiles.nix b/hosts/nixos/porthos/profiles.nix new file mode 100644 index 0000000..3ec736c --- /dev/null +++ b/hosts/nixos/porthos/profiles.nix @@ -0,0 +1,4 @@ +{ ... }: +{ + # Nothing +} From dd7134ca3ea8f5e9bdb873b715490e408101bf8e Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Thu, 7 Dec 2023 21:31:46 +0000 Subject: [PATCH 14/18] flake: add hosts This will allow other modules to cross-reference which hosts exist on which system. My main use-case is to automatically declare home-manager configuration for the home configuration of NixOS hosts. I also include Darwin in case I ever want to use that in the future, though that is unlikely for the moment. --- flake/default.nix | 1 + flake/hosts.nix | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 flake/hosts.nix diff --git a/flake/default.nix b/flake/default.nix index 65102e1..e4b2e8f 100644 --- a/flake/default.nix +++ b/flake/default.nix @@ -13,6 +13,7 @@ flake-parts.lib.mkFlake { inherit inputs; } { ./checks.nix ./dev-shells.nix ./home-manager.nix + ./hosts.nix ./lib.nix ./nixos.nix ./overlays.nix diff --git a/flake/hosts.nix b/flake/hosts.nix new file mode 100644 index 0000000..7d95fdc --- /dev/null +++ b/flake/hosts.nix @@ -0,0 +1,21 @@ +# Define `hosts.{darwin,home,nixos}` options for consumption in other modules +{ lib, ... }: +let + mkHostsOption = description: lib.mkOption { + inherit description; + type = with lib.types; attrsOf str; + default = { }; + example = { name = "x86_64-linux"; }; + }; +in +{ + options = { + hosts = { + darwin = mkHostsOption "Darwin hosts"; + + homes = mkHostsOption "Home Manager hosts"; + + nixos = mkHostsOption "NixOS hosts"; + }; + }; +} From e33357f72e0398c06b00adc8c706a747ac020dd9 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Thu, 7 Dec 2023 21:33:10 +0000 Subject: [PATCH 15/18] flake: nixos: use 'hosts' option --- flake/nixos.nix | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/flake/nixos.nix b/flake/nixos.nix index c5d9ede..49b7770 100644 --- a/flake/nixos.nix +++ b/flake/nixos.nix @@ -1,4 +1,4 @@ -{ self, inputs, lib, ... }: +{ self, config, inputs, lib, ... }: let defaultModules = [ { @@ -32,8 +32,12 @@ let }; in { - flake.nixosConfigurations = lib.mapAttrs buildHost { - aramis = "x86_64-linux"; - porthos = "x86_64-linux"; + config = { + hosts.nixos = { + aramis = "x86_64-linux"; + porthos = "x86_64-linux"; + }; + + flake.nixosConfigurations = lib.mapAttrs buildHost config.hosts.nixos; }; } From d94c9da1c17e85403bfd8d045d2496013c75805d Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Thu, 7 Dec 2023 21:41:05 +0000 Subject: [PATCH 16/18] flake: home-manager: use 'hosts' option --- flake/home-manager.nix | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/flake/home-manager.nix b/flake/home-manager.nix index 2f7e245..7d87a61 100644 --- a/flake/home-manager.nix +++ b/flake/home-manager.nix @@ -1,5 +1,7 @@ -{ self, inputs, lib, ... }: +{ self, config, inputs, lib, ... }: let + inherit (config) hosts; + defaultModules = [ # Include generic settings "${self}/modules/home" @@ -43,18 +45,19 @@ let }; }; - homes = { +in +{ + hosts.homes = { "ambroisie@bazin" = "x86_64-linux"; "ambroisie@mousqueton" = "x86_64-linux"; }; -in -{ + perSystem = { system, ... }: { # Work-around for https://github.com/nix-community/home-manager/issues/3075 legacyPackages = { homeConfigurations = let - filteredHomes = lib.filterAttrs (_: v: v == system) homes; + filteredHomes = lib.filterAttrs (_: v: v == system) hosts.homes; allHomes = filteredHomes // { # Default configuration ambroisie = system; From c593180cf2c3bacf59650c3ce54218214de94283 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Thu, 7 Dec 2023 21:44:01 +0000 Subject: [PATCH 17/18] flake: home-manager: refactor 'mkHome' This will allow making a similar function for NixOS homes. --- flake/home-manager.nix | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/flake/home-manager.nix b/flake/home-manager.nix index 7d87a61..9536c46 100644 --- a/flake/home-manager.nix +++ b/flake/home-manager.nix @@ -20,7 +20,7 @@ let "${self}/modules/common" ]; - mkHome = name: system: inputs.home-manager.lib.homeManagerConfiguration { + mkHomeCommon = mainModules: system: inputs.home-manager.lib.homeManagerConfiguration { # Work-around for home-manager # * not letting me set `lib` as an extraSpecialArgs # * not respecting `nixpkgs.overlays` [1] @@ -33,9 +33,7 @@ let ]; }; - modules = defaultModules ++ [ - "${self}/hosts/homes/${name}" - ]; + modules = defaultModules ++ mainModules; extraSpecialArgs = { # Inject inputs to use them in global registry @@ -45,6 +43,7 @@ let }; }; + mkHome = name: mkHomeCommon [ "${self}/hosts/homes/${name}" ]; in { hosts.homes = { From 0fb2ed977e62275b803c4ba72894ec35953a3c27 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Thu, 7 Dec 2023 21:56:25 +0000 Subject: [PATCH 18/18] flake: home-manager: export NixOS homes And here is what the last few commits were building up to. This is neat, but won't be useful *very* often. --- flake/home-manager.nix | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/flake/home-manager.nix b/flake/home-manager.nix index 9536c46..bbbabc0 100644 --- a/flake/home-manager.nix +++ b/flake/home-manager.nix @@ -44,6 +44,11 @@ let }; mkHome = name: mkHomeCommon [ "${self}/hosts/homes/${name}" ]; + + mkNixosHome = name: mkHomeCommon [ + "${self}/hosts/nixos/${name}/home.nix" + "${self}/hosts/nixos/${name}/profiles.nix" + ]; in { hosts.homes = { @@ -61,8 +66,18 @@ in # Default configuration ambroisie = system; }; + homeManagerHomes = lib.mapAttrs mkHome allHomes; + + filteredNixosHosts = lib.filterAttrs (_: v: v == system) hosts.nixos; + nixosHomes' = lib.mapAttrs mkNixosHome filteredNixosHosts; + nixosHomeUsername = (host: self.nixosConfigurations.${host}.config.my.user.name); + nixosHomes = lib.mapAttrs' (host: lib.nameValuePair "${nixosHomeUsername host}@${host}") nixosHomes'; in - lib.mapAttrs mkHome allHomes; + lib.foldl' lib.mergeAttrs { } + [ + homeManagerHomes + nixosHomes + ]; }; }; }