diff --git a/docs/nix-flakes.adoc b/docs/nix-flakes.adoc index 487dde44..34b8b0f0 100644 --- a/docs/nix-flakes.adoc +++ b/docs/nix-flakes.adoc @@ -84,6 +84,10 @@ and `nixpkgs` url to `github:NixOS/nixpkgs/nixos-22.05`. * The Home Manager library is exported by the flake under `lib.hm`. + +* You can use the above `flake.nix` as a template in `~/.config/nixpkgs` by +[source,console] +$ nix flake new ~/.config/nixpkgs -t github:nix-community/home-manager ==== 2. Install Home Manager and apply the configuration by @@ -170,6 +174,11 @@ The Home Manager configuration is then part of the NixOS configuration and is automatically rebuilt with the system when using the appropriate command for the system, such as `nixos-rebuild switch --flake `. +You can use the above `flake.nix` as a template in `/etc/nixos` by + +[source,console] +$ nix flake new /etc/nixos -t github:nix-community/home-manager#nixos + [[sec-flakes-nix-darwin-module]] === nix-darwin module @@ -213,3 +222,8 @@ is similar to that of NixOS. The `flake.nix` would be: and it is also rebuilt with the nix-darwin generations. The rebuild command here may be `darwin-rebuild switch --flake `. + +You can use the above `flake.nix` as a template in `~/.config/darwin` by + +[source,console] +$ nix flake new ~/.config/darwin -t github:nix-community/home-manager#nix-darwin diff --git a/flake.nix b/flake.nix index c2885d62..a4e570e9 100644 --- a/flake.nix +++ b/flake.nix @@ -20,6 +20,23 @@ # unofficial; deprecated in Nix 2.8 darwinModule = self.darwinModules.default; + templates = { + standalone = { + path = ./templates/standalone; + description = "Standalone setup"; + }; + nixos = { + path = ./templates/nixos; + description = "Home Manager as a NixOS module,"; + }; + nix-darwin = { + path = ./templates/nix-darwin; + description = "Home Manager as a nix-darwin module,"; + }; + }; + + defaultTemplate = self.templates.standalone; + lib = { hm = (import ./modules/lib/stdlib-extended.nix nixpkgs.lib).hm; homeManagerConfiguration = { modules ? [ ], pkgs, lib ? pkgs.lib diff --git a/templates/nix-darwin/flake.nix b/templates/nix-darwin/flake.nix new file mode 100644 index 00000000..85b1db41 --- /dev/null +++ b/templates/nix-darwin/flake.nix @@ -0,0 +1,31 @@ +{ + description = "NixOS configuration"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + darwin.url = "github:lnl7/nix-darwin"; + darwin.inputs.nixpkgs.follows = "nixpkgs"; + home-manager.url = "github:nix-community/home-manager"; + home-manager.inputs.nixpkgs.follows = "nixpkgs"; + }; + + outputs = inputs@{ nixpkgs, home-manager, darwin, ... }: { + darwinConfigurations = { + hostname = darwin.lib.darwinSystem { + system = "x86_64-darwin"; + modules = [ + ./configuration.nix + home-manager.darwinModules.home-manager + { + home-manager.useGlobalPkgs = true; + home-manager.useUserPackages = true; + home-manager.users.jdoe = import ./home.nix; + + # Optionally, use home-manager.extraSpecialArgs to pass + # arguments to home.nix + } + ]; + }; + }; + }; +} diff --git a/templates/nixos/flake.nix b/templates/nixos/flake.nix new file mode 100644 index 00000000..fd4d0cd4 --- /dev/null +++ b/templates/nixos/flake.nix @@ -0,0 +1,29 @@ +{ + description = "NixOS configuration"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + home-manager.url = "github:nix-community/home-manager"; + home-manager.inputs.nixpkgs.follows = "nixpkgs"; + }; + + outputs = inputs@{ nixpkgs, home-manager, ... }: { + nixosConfigurations = { + hostname = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + modules = [ + ./configuration.nix + home-manager.nixosModules.home-manager + { + home-manager.useGlobalPkgs = true; + home-manager.useUserPackages = true; + home-manager.users.jdoe = import ./home.nix; + + # Optionally, use home-manager.extraSpecialArgs to pass + # arguments to home.nix + } + ]; + }; + }; + }; +} diff --git a/templates/standalone/flake.nix b/templates/standalone/flake.nix new file mode 100644 index 00000000..c35ca3fa --- /dev/null +++ b/templates/standalone/flake.nix @@ -0,0 +1,29 @@ +{ + description = "Home Manager configuration of Jane Doe"; + + inputs = { + # Specify the source of Home Manager and Nixpkgs. + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + home-manager = { + url = "github:nix-community/home-manager"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = { nixpkgs, home-manager, ... }: + let + system = "x86_64-linux"; + pkgs = nixpkgs.legacyPackages.${system}; + in { + homeConfigurations.jdoe = home-manager.lib.homeManagerConfiguration { + inherit pkgs; + + # Specify your home configuration modules here, for example, + # the path to your home.nix. + modules = [ ./home.nix ]; + + # Optionally use extraSpecialArgs + # to pass through arguments to home.nix + }; + }; +}