From 0a6227d667d1d2bc6a79de24fd12becc523f2e2f Mon Sep 17 00:00:00 2001 From: Imran Hossain Date: Sun, 11 Apr 2021 17:46:27 -0400 Subject: [PATCH] flake.nix: Add packages and defaultPackages outputs (#1913) --- flake.nix | 53 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/flake.nix b/flake.nix index 6dfc52be..a3afaab3 100644 --- a/flake.nix +++ b/flake.nix @@ -1,26 +1,43 @@ { description = "Home Manager for Nix"; - outputs = { self, nixpkgs }: rec { - nixosModules.home-manager = import ./nixos; - nixosModule = self.nixosModules.home-manager; + outputs = { self, nixpkgs }: + let + # List of systems supported by home-manager binary + supportedSystems = nixpkgs.lib.platforms.unix; - darwinModules.home-manager = import ./nix-darwin; - darwinModule = self.darwinModules.home-manager; + # Function to generate a set based on supported systems + forAllSystems = f: + nixpkgs.lib.genAttrs supportedSystems (system: f system); - lib = { - hm = import ./modules/lib { lib = nixpkgs.lib; }; - homeManagerConfiguration = { configuration, system, homeDirectory - , username, extraSpecialArgs ? { } - , pkgs ? builtins.getAttr system nixpkgs.outputs.legacyPackages - , check ? true }@args: - import ./modules { - inherit pkgs check extraSpecialArgs; - configuration = { ... }: { - imports = [ configuration ]; - home = { inherit homeDirectory username; }; + nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; }); + in rec { + nixosModules.home-manager = import ./nixos; + nixosModule = self.nixosModules.home-manager; + + darwinModules.home-manager = import ./nix-darwin; + darwinModule = self.darwinModules.home-manager; + + packages = forAllSystems (system: { + home-manager = nixpkgsFor.${system}.callPackage ./home-manager { }; + }); + + defaultPackage = + forAllSystems (system: self.packages.${system}.home-manager); + + lib = { + hm = import ./modules/lib { lib = nixpkgs.lib; }; + homeManagerConfiguration = { configuration, system, homeDirectory + , username, extraSpecialArgs ? { } + , pkgs ? builtins.getAttr system nixpkgs.outputs.legacyPackages + , check ? true }@args: + import ./modules { + inherit pkgs check extraSpecialArgs; + configuration = { ... }: { + imports = [ configuration ]; + home = { inherit homeDirectory username; }; + }; }; - }; + }; }; - }; }