-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: add 'System management with nix flakes' guide #441
Open
woile
wants to merge
1
commit into
hercules-ci:main
Choose a base branch
from
woile:feat/new-guide
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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 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,132 @@ | ||
# System management with nix flakes | ||
|
||
If your goal is to control your machine using [nix flakes](https://nixos.wiki/wiki/Flakes), this guide is for you. | ||
|
||
Machines come in different flavors, you may already be using nixos, another linux distribution or mac (with arm or intel architecture). You can manage them all using "the flake way". | ||
|
||
Be sure to have nix installed in your system. | ||
|
||
Let's start! | ||
|
||
## Terminology | ||
|
||
- `host`: a machine, like a desktop computer, a laptop or a server in the cloud | ||
- `hostname`: name given to the machine, use `hostname -s` to retrieve it in unix systems | ||
- `templates`: in this context they refer to nix templates | ||
|
||
## Getting started | ||
|
||
All of our configurations will be conveniently housed within a `nixos-config` folder, irrespective of the underlying system being used. | ||
|
||
No matter the system used, we are gonna create a folder that will contain all the configurations for the host system. You have the option to back up the project on a Git platform such as GitHub, GitLab, Gittea, and others. Additionally, you can easily extend it to multiple hosts if needed. | ||
|
||
If you publish your configuration to github, please add the label `flake-parts-nixos-flake` to make it easier to find. | ||
|
||
Let's begin | ||
|
||
```sh | ||
mkdir ~/nixos-config | ||
cd ~/nixos-config | ||
``` | ||
|
||
And we are going to initialize the fantastic [nixos-flake](https://github.com/srid/nixos-flake) which uses itself flakes-parts. | ||
|
||
```sh | ||
nix flake init -t github:srid/nixos-flake | ||
``` | ||
|
||
This will initialize a flake with support for nixos, nix-darwin and home-manager combined. | ||
|
||
If you'd rather initialize only a macos, or another linux distribution, check the [nixos-flake docs](https://zero-to-flakes.com/nixos-flake/templates). | ||
|
||
## Configuring different systems | ||
|
||
### On nixos | ||
|
||
Your nix configuration should be on `/etc/nixos`, you should have something like: | ||
|
||
```console | ||
$ ls /etc/nixos | ||
configuration.nix hardware-configuration.nix | ||
``` | ||
|
||
Let's copy the existing system there. | ||
|
||
```sh | ||
TARGET="~/nixos-config/hosts/$(hostname -s)" | ||
mkdir -p "$TARGET" | ||
cp -r /etc/nixos "$TARGET" | ||
``` | ||
|
||
Now it's time for you to dig into the `flake.nix`, update the `TODO`s with your `username` and `hostname`, and | ||
finally, import the configurations that we previously copied. | ||
|
||
The last step is to activate the flake: | ||
|
||
```sh | ||
nix run .#activate | ||
``` | ||
|
||
### On other linux distributions | ||
|
||
If you are using a non-nixos linux distribution, you probably should use the `home` template (you can add other systems later). And you'll use nix as a replacement for your dotfiles, with the advantage of having a declarative language, with declarative aliases, packages from nixpkgs and many more configurations. | ||
|
||
```sh | ||
nix flake init -t github:srid/nixos-flake#home | ||
``` | ||
|
||
Configure at will. | ||
|
||
And finally, activate it: | ||
|
||
```sh | ||
nix run .#activate-home | ||
``` | ||
|
||
### On Mac | ||
|
||
If you are on an Intel Mac, change `mkARMMacosSystem` to `mkIntelMacosSystem` and run | ||
|
||
```sh | ||
nix run .#activate | ||
``` | ||
|
||
## Folder structure | ||
|
||
You can use this set up as a starting point for a multi-machine and multi-user configuration for your fleet of machines. | ||
|
||
```sh | ||
nixos-config/ | ||
├── hardware/ | ||
│ ├── sd-image/ | ||
│ └── dell-xps13.nix # example of a specific hardware | ||
├── home/ | ||
│ └── default.nix # shared home config | ||
├── hosts/ | ||
├── nix-darwin/ | ||
│ └── default.nix | ||
├── nixos/ | ||
│ └── default.nix | ||
├── users/ | ||
│ ├── config.nix | ||
│ └── default.nix | ||
├── flake.lock | ||
└── flake.nix | ||
``` | ||
|
||
inside the `hosts` you'd create a "host" combining a user + home + nixos* + nix-darwin* + hardware\* | ||
|
||
\* optional, depends on your needs | ||
|
||
## Getting help | ||
|
||
For questions related to flake-parts head to the [flake-parts discussions](https://github.com/hercules-ci/flake-parts/discussions) on github. | ||
|
||
For questions related to nixos-flake head to the [nixos-flake discussions](https://github.com/srid/nixos-flake/discussions) on github. | ||
|
||
|
||
## Resources | ||
|
||
- https://github.com/srid/nixos-config | ||
- https://github.com/lovesegfault/nix-config | ||
- https://nixos-and-flakes.thiscute.world/nixos-with-flakes/modularize-the-configuration |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like
nixos-flake.md
is best put in srid/nixos-unified#25 (comment) rather than flake-parts repo (which documents flake-parts itself rather than explaining individual modules from elsewhere).