flake: add templates (#2892)
Add example flakes from `docs/nix-flakes.adoc` as templates.
This commit is contained in:
parent
375631f35b
commit
8e4220e6c6
|
@ -84,6 +84,10 @@ and `nixpkgs` url to `github:NixOS/nixpkgs/nixos-22.05`.
|
||||||
|
|
||||||
* The Home Manager library is exported by the flake under
|
* The Home Manager library is exported by the flake under
|
||||||
`lib.hm`.
|
`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
|
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
|
and is automatically rebuilt with the system when using the appropriate command
|
||||||
for the system, such as `nixos-rebuild switch --flake <flake-uri>`.
|
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]]
|
[[sec-flakes-nix-darwin-module]]
|
||||||
=== 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.
|
and it is also rebuilt with the nix-darwin generations.
|
||||||
The rebuild command here may be `darwin-rebuild switch --flake <flake-uri>`.
|
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
flake.nix
17
flake.nix
|
@ -20,6 +20,23 @@
|
||||||
# unofficial; deprecated in Nix 2.8
|
# unofficial; deprecated in Nix 2.8
|
||||||
darwinModule = self.darwinModules.default;
|
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 = {
|
lib = {
|
||||||
hm = (import ./modules/lib/stdlib-extended.nix nixpkgs.lib).hm;
|
hm = (import ./modules/lib/stdlib-extended.nix nixpkgs.lib).hm;
|
||||||
homeManagerConfiguration = { modules ? [ ], pkgs, lib ? pkgs.lib
|
homeManagerConfiguration = { modules ? [ ], pkgs, lib ? pkgs.lib
|
||||||
|
|
31
templates/nix-darwin/flake.nix
Normal file
31
templates/nix-darwin/flake.nix
Normal file
|
@ -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
templates/nixos/flake.nix
Normal file
29
templates/nixos/flake.nix
Normal file
|
@ -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
templates/standalone/flake.nix
Normal file
29
templates/standalone/flake.nix
Normal file
|
@ -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
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in a new issue