-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
202 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 0 additions & 9 deletions
9
docs/document/Nix/docs/Home Manager/1. What's home-manager.md
This file was deleted.
Oops, something went wrong.
86 changes: 86 additions & 0 deletions
86
docs/document/Nix/docs/Home Manager/2. Install Packages.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# Install Packages | ||
|
||
There's two ways to install packages using home-manager. | ||
|
||
- `home.packages`: for any package exists in a channel. | ||
- `programs.<pkg_name>`: for build in options for certain package by home-manager. | ||
|
||
## Install from a channel | ||
|
||
`home.packages` provides a explicit way to include what package should be installed. | ||
`pkgs` here is a channel unpacked from the`flake.nix`. | ||
|
||
```nix | ||
{ config, pkgs, ... }: { | ||
home.packages = with pkgs; [ | ||
git # package names came from channel | ||
neovim | ||
ripgrep | ||
openssh | ||
lazygit | ||
]; | ||
} | ||
``` | ||
|
||
```nix | ||
{ | ||
description = "Home Manager configuration of sharpchen"; | ||
inputs = { | ||
# Specify the source of Home Manager and Nixpkgs. | ||
unstablePkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; | ||
stablePkgs.url = "github:nixos/nixpkgs/nixos-24.05"; | ||
home-manager = { | ||
url = "github:nix-community/home-manager"; | ||
inputs.nixpkgs.follows = "unstablePkgs"; | ||
}; | ||
}; | ||
outputs = { stablePkgs, unstablePkgs, home-manager, ... }: | ||
let | ||
system = "x86_64-linux"; | ||
pkgs = unstablePkgs.legacyPackages.${system}; | ||
stable = unstablePkgs.legacyPackages.${system}; | ||
in { | ||
homeConfigurations."sharpchen" = home-manager.lib.homeManagerConfiguration { | ||
inherit pkgs; # [!code highlight] | ||
# 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 | ||
extraSpecialArgs = { inherit stable; }; | ||
}; | ||
}; | ||
} | ||
``` | ||
|
||
> [!TIP] | ||
> How do I know the package name? | ||
> Search on [NixOS Search](https://search.nixos.org/packages) to find the package you want. | ||
## Install by builtin option | ||
|
||
For some packages, home-manager provides builtin options to set them up. | ||
It seems `pkgs` is not involved, actually it was used by default for `programs.<pkg_name>`. | ||
So we should always make sure `pkgs` exists as a parameter for the function in `home.nix`, should be discussed later. | ||
|
||
```nix | ||
{ config, pkgs, ... }: { | ||
programs.git = { | ||
enable = true; | ||
userName = "foo"; | ||
userEmail = "[email protected]"; | ||
}; | ||
} | ||
``` | ||
|
||
*`enable` implies that the package will be installed implicitly.* | ||
|
||
:::info | ||
Only few packages has builtin options, how do I know what attribute I can set? | ||
Check out [Home-manager Options](https://nix-community.github.io/home-manager/options.xhtml) and search `programs.<pkg_name>` | ||
::: |
16 changes: 16 additions & 0 deletions
16
docs/document/Nix/docs/Home Manager/3. Managing Dotfiles.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Managing Dotfiles | ||
|
||
Managing config files is what a traiditional pm can't do. | ||
Home manager provides some approaches to do it. | ||
|
||
- `home.file`: directly creates a file with content to a path. | ||
- `text`: use string to represent content right inside nix file. | ||
- `source`: specifiy a target path to a file as the source of config. | ||
- `xdg.configFile`: use xdg config path as base path. | ||
- symlink | ||
|
||
## `home.file` | ||
|
||
## `xdg.configFile` | ||
|
||
## |
This file was deleted.
Oops, something went wrong.
61 changes: 61 additions & 0 deletions
61
docs/document/Nix/docs/Home Manager/Multiple Channels with Flakes.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Multiple Channels with Flakes | ||
|
||
You might want to use stable and unstable at the same time. | ||
As mentioned earlier, all attributes are passed from `flake.nix` to `home.nix`. | ||
So adding a new channel is simply adding a new attribute in `flake.nix` and use it in `home.nix`. | ||
|
||
## Choose one as your default channel | ||
|
||
You should already know that `pkgs` is a essential attribute that we should always assign. | ||
`programs.<pkg_name>` uses `pkgs` attribute implicitly, it's like a default channel solution. | ||
So just pick one channel as you like for it. A lot nix users actually prefer unstable over stable because it's not that unstale. | ||
|
||
```nix | ||
{ | ||
description = "Home Manager configuration of sharpchen"; | ||
inputs = { | ||
# Specify the source of Home Manager and Nixpkgs. | ||
# Names can be any | ||
unstablePkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; # [!code highlight] | ||
stablePkgs.url = "github:nixos/nixpkgs/nixos-24.05"; # [!code highlight] | ||
home-manager = { | ||
url = "github:nix-community/home-manager"; | ||
inputs.nixpkgs.follows = "unstablePkgs"; | ||
}; | ||
}; | ||
outputs = { stablePkgs, unstablePkgs, home-manager, ... }: | ||
let | ||
system = "x86_64-linux"; | ||
pkgs = unstablePkgs.legacyPackages.${system}; # choose unstable as pkgs # [!code highlight] | ||
stable = unstablePkgs.legacyPackages.${system}; # name non-default channel as you like! # [!code highlight] | ||
in { | ||
homeConfigurations."sharpchen" = home-manager.lib.homeManagerConfiguration { | ||
inherit pkgs; # export `pkgs` here, this is the only one `pkgs` # [!code highlight] | ||
# 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 | ||
extraSpecialArgs = { inherit stable; }; # export `stable` as arg here # [!code highlight] | ||
}; | ||
}; | ||
} | ||
``` | ||
|
||
Then add the attribute name in the funtion of `home.nix`: | ||
|
||
```nix | ||
{ config, pkgs, stable, ... }: # add `stable` here # [!code highlight] | ||
{ | ||
# ... | ||
home.packages = [ | ||
stable.harper # [!code highlight] | ||
stable.tmux # [!code highlight] | ||
]; | ||
} | ||
``` |