Skip to content

Commit

Permalink
flake: add templates (nix-community#2892)
Browse files Browse the repository at this point in the history
Add example flakes from `docs/nix-flakes.adoc` as templates.
  • Loading branch information
MaxCan-Code authored Aug 27, 2022
1 parent 375631f commit 8e4220e
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 0 deletions.
14 changes: 14 additions & 0 deletions docs/nix-flakes.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 <flake-uri>`.

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

Expand Down Expand Up @@ -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 <flake-uri>`.

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
17 changes: 17 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions templates/nix-darwin/flake.nix
Original file line number Diff line number Diff line change
@@ -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
}
];
};
};
};
}
29 changes: 29 additions & 0 deletions templates/nixos/flake.nix
Original file line number Diff line number Diff line change
@@ -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
}
];
};
};
};
}
29 changes: 29 additions & 0 deletions templates/standalone/flake.nix
Original file line number Diff line number Diff line change
@@ -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
};
};
}

0 comments on commit 8e4220e

Please sign in to comment.