2019-12-03 06:18:30 +01:00
|
|
|
# Introduction
|
2020-01-05 11:43:28 +01:00
|
|
|
A NixOS configuration template using the experimental [flakes][rfc] mechanism.
|
|
|
|
Its aim is to provide a generic repository which neatly separates concerns
|
2020-01-11 05:55:09 +01:00
|
|
|
and allows one to get up and running with NixOS faster than ever.
|
2020-01-04 04:23:13 +01:00
|
|
|
|
2020-01-11 07:49:18 +01:00
|
|
|
Please be advised, flakes are still an experimental feature.
|
|
|
|
Presuming they get [merged][rfc], even more will become possible, e.g.
|
|
|
|
[nixops](https://nixos.org/nixops)/[disnix](https://nixos.org/disnix)
|
2020-01-04 04:23:13 +01:00
|
|
|
support.
|
2019-12-05 09:36:15 +01:00
|
|
|
|
2020-01-08 00:37:46 +01:00
|
|
|
#### Flake Talk:
|
|
|
|
[![Flake talk at NixConf][thumb]][video]
|
2019-12-05 09:36:15 +01:00
|
|
|
|
2020-01-08 00:37:46 +01:00
|
|
|
Keep in mind that flakes are meant to deprecate nix-channels. I'd recommend not
|
|
|
|
installing any. If your really want them, they should work if you wire them
|
|
|
|
up with your `NIX_PATH`.
|
|
|
|
|
|
|
|
# Setup
|
2020-01-04 01:47:17 +01:00
|
|
|
|
2020-01-05 11:43:28 +01:00
|
|
|
```sh
|
|
|
|
# not needed if using direnv
|
|
|
|
nix-shell
|
2020-01-04 01:47:17 +01:00
|
|
|
|
2020-01-05 11:43:28 +01:00
|
|
|
git checkout -b $new_branch template
|
2020-01-04 01:47:17 +01:00
|
|
|
|
2020-01-11 07:49:18 +01:00
|
|
|
# set a root password, preferably with `hashedPassword`
|
|
|
|
$EDITOR ./users/root/default.nix
|
|
|
|
|
2020-01-05 11:43:28 +01:00
|
|
|
# generate hardware config
|
|
|
|
nixos-generate-config --show-hardware-config > ./hosts/${new_host}.nix
|
2020-01-04 01:47:17 +01:00
|
|
|
|
2020-01-07 21:57:55 +01:00
|
|
|
# Edit the new file, removing `not-detected.nix` from the imports.
|
2020-01-07 21:04:32 +01:00
|
|
|
# In order to maintain purity flakes cannot resolve from the NIX_PATH.
|
|
|
|
# You may also want to import ./hosts/NixOS.nix from here which sets up
|
|
|
|
# an efi bootloader, enables Network Manager and sets an empty root password.
|
|
|
|
# Otherwise you'll need to set the bootloader, network and password yourself.
|
|
|
|
|
|
|
|
# Also ensure your file systems are set the way you want. And import
|
|
|
|
# any ./profiles you may wish to try out.
|
|
|
|
$EDITOR ./hosts/${new_host}.nix
|
|
|
|
|
|
|
|
# backup existing config and ensure configuration lives in expected location
|
|
|
|
mv /etc/nixos /etc/nixos.old
|
2020-01-06 08:01:00 +01:00
|
|
|
ln -s $PWD /etc/nixos
|
2020-01-04 01:47:17 +01:00
|
|
|
|
2020-01-07 00:57:35 +01:00
|
|
|
# a flake is vcs based, so only git aware files are bundled
|
|
|
|
# adding a new file to staging is enough
|
|
|
|
git add ./hosts/${new_host}.nix
|
|
|
|
|
2020-01-06 02:26:09 +01:00
|
|
|
# `rebuild` wrapper for `nix build` bypassing `nixos-rebuild`
|
|
|
|
# Usage: rebuild [host] {switch|boot|test|dry-activate}
|
2019-12-05 09:36:15 +01:00
|
|
|
|
2020-01-05 11:43:28 +01:00
|
|
|
# You can specify any of the host configurations living in the ./hosts
|
|
|
|
# directory. If omitted, it will default to your systems current hostname.
|
2020-01-07 21:02:35 +01:00
|
|
|
# This will be run as root.
|
2020-01-05 11:43:28 +01:00
|
|
|
rebuild $new_host switch
|
2020-01-04 01:47:17 +01:00
|
|
|
|
2020-01-11 07:49:18 +01:00
|
|
|
# you may wish to start by creating a user
|
|
|
|
mkdir users/new-user && $EDITOR users/new-user/default.nix
|
2020-01-02 07:17:50 +01:00
|
|
|
```
|
2019-12-05 09:36:15 +01:00
|
|
|
|
2020-01-11 07:49:18 +01:00
|
|
|
Best to read the [doc](DOC.md), in order to understand the impetus behind
|
|
|
|
the directory structure.
|
2019-12-05 09:36:15 +01:00
|
|
|
|
2020-01-04 01:47:17 +01:00
|
|
|
|
|
|
|
## Additional Capabilities
|
|
|
|
|
2020-01-05 11:43:28 +01:00
|
|
|
```sh
|
|
|
|
# make an iso image based on ./hosts/niximg.nix
|
2020-01-02 07:17:50 +01:00
|
|
|
rebuild iso
|
2019-12-05 09:36:15 +01:00
|
|
|
|
2020-01-05 11:43:28 +01:00
|
|
|
# install any package the flake exports
|
|
|
|
nix profile install ".#packages.x86_64-linux.myPackage"
|
2019-12-05 09:36:15 +01:00
|
|
|
```
|
|
|
|
|
2020-01-11 07:49:18 +01:00
|
|
|
this flake exports multiple outputs for use in other flakes, or forks
|
|
|
|
of this one:
|
2020-01-05 11:43:28 +01:00
|
|
|
```nix
|
|
|
|
# external flake.nix
|
|
|
|
{
|
|
|
|
# ...
|
|
|
|
inputs.nixflk.url = "github:nrdxp/nixflk";
|
|
|
|
|
|
|
|
outputs = { self, nixpkgs, nixflk }: {
|
|
|
|
|
2020-01-06 02:26:09 +01:00
|
|
|
nixosConfigurations.newConfig = nixflk.nixosConfigurations.someConfig;
|
|
|
|
|
2020-01-05 11:43:28 +01:00
|
|
|
nixosConfigurations.myConfig = nixpkgs.lib.nixosSystem {
|
|
|
|
system = "x86_64-linux";
|
|
|
|
modules = [
|
|
|
|
{ nixpkgs.overlays = nixflk.overlays; }
|
|
|
|
nixflk.nixosModules.myModule
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
2020-01-04 01:47:17 +01:00
|
|
|
|
2020-01-05 11:43:28 +01:00
|
|
|
```
|
2020-01-02 07:17:50 +01:00
|
|
|
|
2020-01-11 07:49:18 +01:00
|
|
|
### NUR usage
|
2020-01-06 08:01:00 +01:00
|
|
|
|
2020-01-11 07:49:18 +01:00
|
|
|
You can use packages, modules and overlays from the
|
|
|
|
[Nix User Repository][nur].
|
2020-01-02 07:17:50 +01:00
|
|
|
|
2020-01-11 07:49:18 +01:00
|
|
|
Since NUR packages are completely unchecked, they are not included by default.
|
|
|
|
Check out the NUR [branch](https://github.com/nrdxp/nixflk/tree/NUR) for usage.
|
2020-01-06 08:16:21 +01:00
|
|
|
|
2019-12-03 06:18:30 +01: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 07:17:50 +01:00
|
|
|
[direnv]: https://direnv.net
|
2019-12-03 06:18:30 +01:00
|
|
|
[NixOS]: https://nixos.org
|
2020-01-11 07:49:18 +01:00
|
|
|
[nur]: https://github.com/nix-community/NUR
|
2019-12-03 06:18:30 +01:00
|
|
|
[old]: https://github.com/nrdxp/nixos
|
2020-01-02 07:17:50 +01: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
|
2020-01-08 00:37:46 +01:00
|
|
|
[thumb]: https://img.youtube.com/vi/UeBX7Ide5a0/hqdefault.jpg
|