From 05d9dd9808817d15ac8bd99de517f3d392c43ccf Mon Sep 17 00:00:00 2001 From: Riley Apeldoorn Date: Mon, 19 Jun 2023 15:15:59 +0200 Subject: [PATCH 1/2] Refactor home-manager module imports --- flake.nix | 96 ++++++++++++++++++++++++----------------- shared/core/default.nix | 4 +- system/lime/core.nix | 10 +++-- system/lime/home.nix | 1 + 4 files changed, 67 insertions(+), 44 deletions(-) diff --git a/flake.nix b/flake.nix index 142f8bb..18cf208 100644 --- a/flake.nix +++ b/flake.nix @@ -11,57 +11,75 @@ nixos-hardware.url = github:NixOS/nixos-hardware; }; - outputs = args@{ home-manager, nixpkgs, agenix, nixos-hardware, ... }: with nixpkgs; { + outputs = args@{ self, home-manager, nixpkgs, agenix, nixos-hardware, ... }: with nixpkgs; { # Configurations for NixOS machines. - nixosConfigurations = - let mkUserConfig = path: { - imports = [ home-manager.nixosModules.home-manager ]; - config = { - home-manager.users."riley" = (import "${path}/home.nix"); + nixosConfigurations = let + # Generate a user configuration for the given user, based on the given home manager + # configuration. + userConfig = user: home: [ + home-manager.nixosModules.home-manager + ({ config, ... }: { + home-manager.users."${user}" = (home // { + config.home = { + inherit (config.system) stateVersion; + username = user; }; - }; - in { - - # Desktop system - "strawberry" = lib.nixosSystem { - system = "x86_64-linux"; - modules = [ - (mkUserConfig ./system/strawberry) - agenix.nixosModules.default - ./system/strawberry/core.nix - ./shared/core - ./shared/secrets.nix - ]; - specialArgs = args; - }; - - # Thinkpad - "lime" = lib.nixosSystem { - system = "x86_64-linux"; - modules = [ - (mkUserConfig ./system/lime) - agenix.nixosModules.default - nixos-hardware.nixosModules.lenovo-thinkpad-x390 - nixos-hardware.nixosModules.common-gpu-nvidia-disable - ./system/lime/core.nix - ./shared/core - ./shared/secrets.nix - ]; - specialArgs = args; - }; - + }).config; + }) + ]; + in { + # Desktop system + "strawberry" = lib.nixosSystem { + system = "x86_64-linux"; + modules = [ + ./system/strawberry/core.nix + ./shared/core + ] ++ (userConfig "riley" self.homeConfigurations."strawberry"); + specialArgs = args; }; + # Thinkpad + "lime" = lib.nixosSystem { + system = "x86_64-linux"; + modules = [ + ./system/lime/core.nix + ./shared/core + ] ++ (userConfig "riley" self.homeConfigurations."lime"); + specialArgs = args; + }; + }; # Configurations for non-NixOS machines. - homeConfigurations = with home-manager.lib; { + homeConfigurations = with home-manager.lib; let + pkgs = import nixpkgs { + system = "x86_64-linux"; + overlays = [ self.overlays.default ]; + }; + in { + # riley @ dev-lt-63 "dev-lt-63" = homeManagerConfiguration { - pkgs = nixpkgs.legacyPackages."x86_64-linux"; + inherit pkgs; modules = [ ./system/dev-lt-63/home.nix ./shared/home ]; }; + # riley @ strawberry + "strawberry" = homeManagerConfiguration { + inherit pkgs; + modules = [ + ./system/strawberry/home.nix + ./shared/home + ]; + }; + # riley @ lime + "lime" = homeManagerConfiguration { + inherit pkgs; + modules = [ + ./system/lime/home.nix + ./shared/home + ]; + }; }; overlays = { diff --git a/shared/core/default.nix b/shared/core/default.nix index c2e68bf..d604412 100644 --- a/shared/core/default.nix +++ b/shared/core/default.nix @@ -1,8 +1,10 @@ -{ pkgs, ... }: +{ pkgs, agenix, ... }: { imports = [ + agenix.nixosModules.default + ../secrets.nix ./services.nix ./backups.nix ./users.nix diff --git a/system/lime/core.nix b/system/lime/core.nix index 3483c80..026d464 100644 --- a/system/lime/core.nix +++ b/system/lime/core.nix @@ -1,6 +1,10 @@ -{ lib, modulesPath, ... }: { +{ lib, modulesPath, nixos-hardware, ... }: { - imports = [./hardware-configuration.nix]; + imports = [ + ./hardware-configuration.nix + nixos-hardware.nixosModules.lenovo-thinkpad-x390 + nixos-hardware.nixosModules.common-gpu-nvidia-disable + ]; custom = { gui.enable = true; @@ -15,7 +19,5 @@ system.stateVersion = "22.11"; services.xserver.libinput.enable = true; - home-manager.users."riley".home.stateVersion = "22.11"; - } diff --git a/system/lime/home.nix b/system/lime/home.nix index 1d3586c..8c684f5 100644 --- a/system/lime/home.nix +++ b/system/lime/home.nix @@ -9,4 +9,5 @@ }; }; programs.iamb.enable = true; + home.stateVersion = "22.11"; } \ No newline at end of file -- 2.45.2 From c2aa01557a109985b916eb40be83c19987f179e6 Mon Sep 17 00:00:00 2001 From: Riley Apeldoorn Date: Mon, 19 Jun 2023 15:28:11 +0200 Subject: [PATCH 2/2] Clean up flake.nix further --- flake.nix | 36 +++++++++--------------------------- 1 file changed, 9 insertions(+), 27 deletions(-) diff --git a/flake.nix b/flake.nix index 18cf208..212a02d 100644 --- a/flake.nix +++ b/flake.nix @@ -49,38 +49,20 @@ }; }; - # Configurations for non-NixOS machines. + # Configurations for home-manager. homeConfigurations = with home-manager.lib; let + forEachHost = lib.genAttrs [ "dev-lt-63" "strawberry" "lime" ]; pkgs = import nixpkgs { system = "x86_64-linux"; overlays = [ self.overlays.default ]; }; - in { - # riley @ dev-lt-63 - "dev-lt-63" = homeManagerConfiguration { - inherit pkgs; - modules = [ - ./system/dev-lt-63/home.nix - ./shared/home - ]; - }; - # riley @ strawberry - "strawberry" = homeManagerConfiguration { - inherit pkgs; - modules = [ - ./system/strawberry/home.nix - ./shared/home - ]; - }; - # riley @ lime - "lime" = homeManagerConfiguration { - inherit pkgs; - modules = [ - ./system/lime/home.nix - ./shared/home - ]; - }; - }; + in forEachHost (host: homeManagerConfiguration { + inherit pkgs; + modules = [ + ./system/${host}/home.nix + ./shared/home + ]; + }); overlays = { default = (import ./shared/overlay.nix); -- 2.45.2