2019-12-03 08:18:30 +03:00
|
|
|
# Introduction
|
|
|
|
|
2019-12-05 11:36:15 +03:00
|
|
|
This project is under construction as a rewrite of my [legacy][old]
|
2020-01-04 06:23:13 +03:00
|
|
|
NixOS configuration using the experimental [flakes][rfc] mechanism. Its aim is
|
|
|
|
to provide a generic template repository which neatly separates concerns and
|
|
|
|
allows one to get up and running with NixOS faster than ever.
|
|
|
|
|
2020-01-04 06:37:07 +03:00
|
|
|
Flakes are still an experimental feature, but once they finally get merged
|
2020-01-04 06:23:13 +03:00
|
|
|
even more will become possible, including [nixops](https://nixos.org/nixops)
|
|
|
|
support.
|
2019-12-05 11:36:15 +03:00
|
|
|
|
|
|
|
|
|
|
|
#### [Flake Talk][video]
|
|
|
|
|
2020-01-02 09:17:50 +03:00
|
|
|
# Usage
|
2020-01-04 03:47:17 +03:00
|
|
|
|
2020-01-02 09:17:50 +03:00
|
|
|
Enter a nix-shell either manually or automatically using [direnv][direnv]. This
|
|
|
|
will set up the exerimental nix features that need to be available to use
|
2020-01-04 03:47:17 +03:00
|
|
|
[flakes][pr].
|
|
|
|
|
|
|
|
Start a new branch based on the template branch:
|
|
|
|
```
|
|
|
|
git checkout -b <new_branch> template
|
|
|
|
```
|
|
|
|
|
|
|
|
You may want to use a generated hardware config for your machine:
|
|
|
|
```
|
|
|
|
nixos-generate-config --show-hardware-config > ./hosts/<new_host>.nix
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
A basic `rebuild` command is included in the shell to replace
|
2020-01-04 06:23:13 +03:00
|
|
|
`nixos-rebuild` for now:
|
2019-12-05 11:36:15 +03:00
|
|
|
|
2020-01-02 09:17:50 +03:00
|
|
|
```
|
|
|
|
Usage: rebuild [host] {switch|boot|test}
|
2020-01-04 03:47:17 +03:00
|
|
|
|
|
|
|
#example using above generated config
|
|
|
|
rebuild <new_host> switch
|
2020-01-02 09:17:50 +03:00
|
|
|
```
|
2019-12-05 11:36:15 +03:00
|
|
|
|
2020-01-02 09:17:50 +03:00
|
|
|
You can specify one of the host configurations from the [hosts](hosts)
|
|
|
|
directory. If omitted, it will default to your systems current hostname.
|
2019-12-05 11:36:15 +03:00
|
|
|
|
2020-01-04 03:47:17 +03:00
|
|
|
And now you should be ready to start writing your nix configuration or import
|
|
|
|
some of the already existing profiles. Review [contributing](#contributing)
|
|
|
|
below on how to structure your expressions. And be sure to update the
|
|
|
|
[locale.nix](local/locale.nix) for your region.
|
|
|
|
|
2020-01-04 05:07:42 +03:00
|
|
|
You can always check out my personal branch
|
2020-01-04 06:23:13 +03:00
|
|
|
[`nrdxp`](https://github.com/nrdxp/nixflk/tree/nrdxp), for concrete examples.
|
2020-01-04 03:47:17 +03:00
|
|
|
|
|
|
|
## Additional Capabilities
|
|
|
|
|
2020-01-04 06:23:13 +03:00
|
|
|
Making iso images:
|
2020-01-02 09:17:50 +03:00
|
|
|
```
|
|
|
|
rebuild iso
|
|
|
|
```
|
2019-12-05 11:36:15 +03:00
|
|
|
|
2020-01-02 09:17:50 +03:00
|
|
|
Will make a minimal and bootable iso image of the [niximg](hosts/niximg.nix)
|
|
|
|
configuration. You can customize the image by editing this file.
|
2019-12-05 11:36:15 +03:00
|
|
|
|
2020-01-02 09:17:50 +03:00
|
|
|
You can also install the packages declared in [pkgs](pkgs) without needing
|
|
|
|
to install NixOS. For example:
|
2019-12-05 11:36:15 +03:00
|
|
|
```
|
2020-01-02 09:17:50 +03:00
|
|
|
# from top-level
|
|
|
|
nix profile install ".#packages.x86_64-linux.purs"
|
2019-12-05 11:36:15 +03:00
|
|
|
```
|
|
|
|
|
2020-01-04 03:47:17 +03:00
|
|
|
A similar mechanism exists to import the modules and overlays declared in the
|
|
|
|
flake to allow for seemless sharing between configurations.
|
|
|
|
|
2020-01-02 09:17:50 +03:00
|
|
|
# Contributing
|
|
|
|
|
2020-01-04 03:47:17 +03:00
|
|
|
The purpose of this repository is to provide a standardized template structure
|
2020-01-04 06:23:13 +03:00
|
|
|
for NixOS machine expressions, thus enabling simpler sharing and reuse of nix
|
2020-01-04 03:47:17 +03:00
|
|
|
expressions.
|
|
|
|
|
|
|
|
Say your friend and you are using this repository, each with your own unique
|
|
|
|
nix epxpressions. By simply importing your friends flake from `flake.nix` as an
|
|
|
|
input, you can have access to all of the packages, modules, overlays, and even
|
|
|
|
entire system configurations your friend has defined!
|
2020-01-02 09:17:50 +03:00
|
|
|
|
|
|
|
## Hosts
|
|
|
|
Distributions for particular machines should be stored in the [hosts](hosts)
|
|
|
|
directory. Every file in this directory will be added automatically to the
|
2020-01-04 06:23:13 +03:00
|
|
|
the `nixosConfigurations` flake output. See the
|
|
|
|
[`default.nix`](hosts/default.nix) for the implementation details.
|
2020-01-02 09:17:50 +03:00
|
|
|
|
|
|
|
## Profiles
|
2020-01-04 06:23:13 +03:00
|
|
|
More abstract configurations suitable for reuse by multiple machines should
|
|
|
|
go in the [profiles](profiles) directory. A distinction is made between a module
|
2020-01-04 03:47:17 +03:00
|
|
|
and profile, in that a profile is simly a regular NixOS module, without any new
|
2020-01-04 06:23:13 +03:00
|
|
|
option declarations. If you want to declare new
|
|
|
|
[options](https://nixos.org/nixos/manual/options.html), create an expression
|
|
|
|
under the [modules](modules) directory instead.
|
2020-01-04 03:47:17 +03:00
|
|
|
|
|
|
|
Every profile should have a `default.nix` to easily import it. You can also
|
|
|
|
stick things in the profile's subdirectory which are not automatically
|
|
|
|
imported, but are meant to be manually imported from a host (useful for less
|
|
|
|
common, or specialized configurations).
|
|
|
|
|
|
|
|
Importantly, every subdirectory in a profile should be independantly importable.
|
|
|
|
For example, a zsh directory lives under [profiles/develop](profiles/develop/zsh).
|
|
|
|
It's written in a generic way to allow in to be imported without the entire
|
|
|
|
[develop](profiles/develop) if one so wished. This provides a wonderful level of
|
|
|
|
granularity.
|
2019-12-03 08:18:30 +03:00
|
|
|
|
2020-01-02 09:17:50 +03:00
|
|
|
In addition, profiles can depend on other profiles. For example, The
|
|
|
|
[graphical](profiles/graphical) profile depends on [develop](profiles/develop)
|
|
|
|
simply by importing it in its [`default.nix`](profiles/graphical/default.nix).
|
2019-12-03 08:18:30 +03:00
|
|
|
|
2020-01-04 06:23:13 +03:00
|
|
|
You can, optionally, choose to export your profiles via the flake output. If
|
|
|
|
you add an attribute to [profiles/default.nix](profiles/default.nix) named
|
|
|
|
\<your-profile>, then it will become available to other flakes via
|
|
|
|
`nixosModules.profiles.<your-profile>`.
|
|
|
|
|
2020-01-02 09:17:50 +03:00
|
|
|
## Users
|
2020-01-04 04:06:01 +03:00
|
|
|
User declaration belongs in the `users` directory. Everything related to
|
2020-01-02 09:17:50 +03:00
|
|
|
your user should be declared here. For convenience, [home-manager][home-manager]
|
2020-01-04 06:23:13 +03:00
|
|
|
is available automatically for home directory setup and should only be used
|
|
|
|
from this directory.
|
2020-01-02 09:17:50 +03:00
|
|
|
|
2020-01-04 03:05:26 +03:00
|
|
|
## Secrets
|
2020-01-04 03:57:44 +03:00
|
|
|
Anything you wish to keep encrypted goes in the `secrets` directory, which is
|
|
|
|
created on first entering a `nix-shell`.
|
2020-01-04 03:54:27 +03:00
|
|
|
|
|
|
|
Be sure to run `git crypt init`, before committing anything to this directory.
|
|
|
|
Be sure to check out git-crypts [documentation](https://github.com/AGWA/git-crypt)
|
|
|
|
if your not familiar. The filter is already set up to encrypt everything in this
|
|
|
|
folder by default.
|
2020-01-04 03:05:26 +03:00
|
|
|
|
|
|
|
To keep [profiles](profiles) resuable across configurations, secrets should
|
2020-01-04 04:06:01 +03:00
|
|
|
only be imported from the `users` directory.
|
2020-01-04 03:05:26 +03:00
|
|
|
|
2020-01-02 09:17:50 +03:00
|
|
|
## Modules and Packages
|
|
|
|
All [modules](modules/default.nix) and [pkgs](pkgs/default.nix) are available
|
2020-01-04 06:23:13 +03:00
|
|
|
for every configuration automatically. Simply add an expression to one of
|
|
|
|
these directories declaring your module or package, and update the
|
2020-01-02 09:17:50 +03:00
|
|
|
corresponding `default.nix` to point to it. Now you can use your new module or
|
2020-01-04 06:23:13 +03:00
|
|
|
install your new package as usual from any profile.
|
2020-01-02 09:17:50 +03:00
|
|
|
|
|
|
|
Doing this will also add them to the flake's `nixosModules` or `overlays`
|
|
|
|
outputs to import them easily into an external NixOS configuration as well.
|
|
|
|
|
|
|
|
## Pull Requests
|
|
|
|
|
2020-01-04 03:47:17 +03:00
|
|
|
While much of your work in this template may be idiosyncratic in nature. Anything
|
|
|
|
that might be generally useful to the broader NixOS community can be synced to
|
|
|
|
the `template` branch to provide a host of useful NixOS configurations available
|
|
|
|
"out of the box". If you wish to contribute such an expression please follow
|
2020-01-04 06:23:13 +03:00
|
|
|
these guidelines:
|
2020-01-04 03:47:17 +03:00
|
|
|
|
2020-01-04 08:06:31 +03:00
|
|
|
* format your code with [`nixfmt`][nixfmt]
|
2020-01-04 06:23:13 +03:00
|
|
|
* The commit message follows the same semantics as [nixpkgs][nixpkgs].
|
|
|
|
* You can use a `#` symbol to specify abiguities. For example,
|
|
|
|
`develop#zsh: <rest of commit message>` would tell me that your updating the
|
|
|
|
`zsh` subprofile living under the `develop` profile.
|
2019-12-03 08:18:30 +03:00
|
|
|
|
|
|
|
|
2020-01-04 03:47:17 +03:00
|
|
|
|
2019-12-03 08:18:30 +03:00
|
|
|
# License
|
|
|
|
|
|
|
|
This software is licensed under the [MIT License](COPYING).
|
|
|
|
|
|
|
|
Note: MIT license does not apply to the packages built by this configuration,
|
|
|
|
merely to the files in this repository (the Nix expressions, build
|
|
|
|
scripts, NixOS modules, etc.). It also might not apply to patches
|
|
|
|
included here, which may be derivative works of the packages to
|
|
|
|
which they apply. The aforementioned artifacts are all covered by the
|
|
|
|
licenses of the respective packages.
|
|
|
|
|
2020-01-02 09:17:50 +03:00
|
|
|
[direnv]: https://direnv.net
|
2020-01-04 03:47:17 +03:00
|
|
|
[home-manager]: https://github.com/rycee/home-manager
|
2019-12-03 08:18:30 +03:00
|
|
|
[NixOS]: https://nixos.org
|
2020-01-04 08:06:31 +03:00
|
|
|
[nixfmt]: https://github.com/serokell/nixfmt
|
2020-01-02 09:17:50 +03:00
|
|
|
[nixpkgs]: https://github.com/NixOS/nixpkgs
|
2019-12-03 08:18:30 +03:00
|
|
|
[old]: https://github.com/nrdxp/nixos
|
2020-01-02 09:17:50 +03:00
|
|
|
[pr]: https://github.com/NixOS/nixpkgs/pull/68897
|
|
|
|
[rfc]: https://github.com/tweag/rfcs/blob/flakes/rfcs/0049-flakes.md
|
|
|
|
[video]: https://www.youtube.com/watch?v=UeBX7Ide5a0
|