2020-12-29 01:27:32 +03:00
> Since flakes are still quite new, I've listed some learning resources
> [below](#resources).
2019-12-03 08:18:30 +03:00
# Introduction
2020-08-03 01:10:53 +03:00
Herein lies a [NixOS][NixOS] configuration template using the new [flakes][wiki]
mechanism. Its aim is to provide a generic repository which neatly separates
concerns and allows one to get up and running with NixOS faster than ever, while
keeping your code clean and organized.
Some key advantages include:
* A single home for all your Nix expressions, easily sharable and portable!
2020-12-28 07:33:28 +03:00
* Skip the boilerplate, simply use the included [nix-shell ](./shell.nix ) or
2020-08-03 01:10:53 +03:00
[direnv][direnv] profile and get up and running with flakes right away.
* Thanks to flakes, the entire system is more [deterministic ](./flake.lock ).
* Systems defined under [hosts ](./hosts ) are automatically imported into
`nixosConfigurations` , ready to deploy.
* [Profiles ](./profiles/list.nix ) are a simple mechanism for using portable
code across machines, and are available to share via the
`nixosModules.profiles` output.
* Defined [packages ](./pkgs/default.nix ) and
[modules ](./modules/list.nix ), are automatically wired and available from
anywhere. They are _also_ sharable via their respective flake outputs.
* Easily [override ](./pkgs/override.nix ) packages from different nixpkgs versions.
* Keep [user ](./users ) configuration isolated and easily reusable by taking
advantage of [user profiles ](./users/profiles ) and [home-manager][home-manager].
* [Overlay ](./overlays ) files are automatically available and sharable.
2020-12-28 07:33:28 +03:00
* Automatic [NUR][nur] support.
2020-08-03 01:10:53 +03:00
For a more detailed explanation of the code structure, check out the
[docs ](./DOC.md ).
2020-01-12 05:51:23 +03:00
### ⚠ Advisory
2020-08-03 01:10:53 +03:00
Flakes are still new, so not everything works yet. However, it has been to
merged in [nixpkgs][nixpkgs] via [`pkgs.nixFlakes`][nixFlakes]. Thus, this
project should be considered _experimental_ , until flakes become the default.
2019-12-05 11:36:15 +03:00
2020-12-29 08:15:10 +03:00
Also, flakes are meant to deprecate nix-channels. It's recommended not to
install any. If your really want them, they should work if you hook them into
2020-08-03 01:10:53 +03:00
`NIX_PATH` .
2020-01-08 02:37:46 +03:00
2020-12-29 08:15:10 +03:00
# Sharing
One of the great benefits of flakes is the ability to easily share your user
defined packages, modules and other nix expressions without having to merge
anything upstream. In that spirit, everything defined in this flake is usable
from other flakes. So even if you don't want to use this project as a template,
you can still pull in any useful modules, packages or profiles defined here.
From the command line:
```sh
# to see what this flake exports
nix flake show "github:nrdxp/nixflk"
# run an app
nix run "github:nrdxp/nixflk#someApp"
# start a dev shell for a given derivation
nix develop "github:nrdxp/nixflk#somePackage"
# a nix shell with the package in scope
nix shell "github:nrdxp/nixflk#somePackage"
```
From within a flake:
```nix
{
inputs.nixflk.url = "github:nrdxp/nixflk";
outputs = { self, nixpkgs, nixflk, ... }:
{
nixosConfigurations.example = nixpkgs.lib.nixosSystem {
# ...
modules = [
nixflk.nixosModules.someModule
({
nixpkgs.overlays = [ nixflk.overlay nixflk.overlays.someOverlay ];
})
# ...
];
};
};
}
```
2020-01-08 02:37:46 +03:00
# Setup
2020-12-29 08:15:10 +03:00
There are a few ways to get up and running. You can fork this repo or use it as
2020-08-03 01:10:53 +03:00
a template. There is a [bare branch][bare] if you want to start with a
2020-12-29 08:15:10 +03:00
completely empty template and make your own profiles from scratch. The only
hard requirement is nix itself. The `shell.nix` will pull in everything else.
2020-01-04 03:47:17 +03:00
2020-12-29 08:15:10 +03:00
## Flake Templates
2020-08-03 01:10:53 +03:00
If you already have [nix-command][nix-command] setup you can:
2020-12-28 07:33:28 +03:00
```sh
2020-08-03 01:10:53 +03:00
# for standard template
nix flake new -t "github:nrdxp/nixflk" flk
2020-01-04 03:47:17 +03:00
2020-08-03 01:10:53 +03:00
# for bare template
nix flake new -t "github:nrdxp/nixflk/bare" flk
```
2020-01-07 02:57:35 +03:00
2020-12-29 08:15:10 +03:00
## Nix Only
Once you have this repo, you'll want to __move or symlink__ it to `/etc/nixos`
for ease of use. Once inside:
2020-12-28 07:33:28 +03:00
```sh
2020-12-29 08:15:10 +03:00
# This will setup nix-command and pull in the needed tools
2020-08-03 01:10:53 +03:00
nix-shell # or `direnv allow` if you prefer
2020-08-03 00:24:00 +03:00
2021-01-11 23:15:55 +03:00
# use nixos-generate-config to generate a basic config for your system
# edit hosts/up-$(hostname).nix to modify.
flk up
2019-12-05 11:36:15 +03:00
2020-12-29 08:15:10 +03:00
# The following should work fine for EFI systems.
# boot.loader.systemd-boot.enable = true;
# boot.loader.efi.canTouchEfiVariables = true;
# Set your locale
$EDITOR local/locale.nix
# install NixOS to bare metal
flk install yourConfig # deploys hosts/yourConfig.nix
# if you already have NixOS and just want to deploy your new setup
flk yourConfig switch
2020-01-12 05:51:23 +03:00
```
2019-12-05 11:36:15 +03:00
2021-01-12 03:32:58 +03:00
### Note on `flk up`:
While the `up` sub-command is provided as a convenience to quickly set up and
install a "fresh" NixOS system on current hardware, committing these files is
discouraged.
They are placed in the git staging area automatically because they would be
invisible to the flake otherwise, but it is best to move what you need from
them directly into your hosts file and commit that instead.
2020-08-03 01:10:53 +03:00
## Build an ISO
2020-01-04 03:47:17 +03:00
2020-12-29 08:15:10 +03:00
You can make an ISO and customize it by modifying the [niximg ](./hosts/niximg.nix )
file:
2020-12-28 07:33:28 +03:00
```sh
flk iso
```
2021-01-18 10:37:11 +03:00
## Hardware Specific Profile for a Single Host
Find out the fitting [nixos-hardware profile ](https://github.com/NixOS/nixos-hardware#list-of-profiles ) path for the hardware of your host and add it to the configuration.
For example for a Dell XPS 13 9370 the host configuration would contain:
```nix
{
imports = [ "${hardwareModulesPath}/dell/xps/13-9370" ... ];
...
}
```
2020-12-28 07:33:28 +03:00
## Use a Package from NUR
NUR is wired in from the start. For safety, nothing is added from it by default,
but you can easily pull packages from inside your configuration like so:
```nix
{ pkgs, ... }:
{
environment.systemPackages = with pkgs; [ nur.repos.< owner > .< package > ];
}
2020-01-05 13:43:28 +03:00
```
2020-12-29 01:27:32 +03:00
# Resources
## Links
* [Example Repo ](https://github.com/colemickens/nixos-flake-example )
* [Tweag.io _Flakes_ Blog Series ](https://www.tweag.io/blog/2020-05-25-flakes )
* [NixOS _Flakes_ Wiki ](https://nixos.wiki/wiki/Flakes )
* [Zimbatm's _Flakes_ Blog ](https://zimbatm.com/NixFlakes )
* [Original RFC ](https://github.com/tweag/rfcs/blob/flakes/rfcs/0049-flakes.md )
2020-01-02 09:17:50 +03:00
2020-08-03 01:10:53 +03:00
## Flake Talk:
[![Flake talk at NixConf][thumb]][video]
2020-12-29 01:27:32 +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-08-03 01:10:53 +03:00
[bare]: https://github.com/nrdxp/nixflk/tree/bare
2020-01-02 09:17:50 +03:00
[direnv]: https://direnv.net
2020-12-30 19:47:46 +03:00
[home-manager]: https://github.com/nix-community/home-manager
2020-08-03 01:10:53 +03:00
[nix-command]: https://nixos.wiki/wiki/Nix_command
[nixFlakes]: https://github.com/NixOS/nixpkgs/blob/master/pkgs/tools/package-management/nix/default.nix#L211
2019-12-03 08:18:30 +03:00
[NixOS]: https://nixos.org
2020-08-03 01:10:53 +03:00
[nixpkgs]: https://github.com/NixOS/nixpkgs
2020-01-11 09:49:18 +03:00
[nur]: https://github.com/nix-community/NUR
2020-08-03 01:10:53 +03:00
[wiki]: https://nixos.wiki/wiki/Flakes
2020-01-08 02:37:46 +03:00
[thumb]: https://img.youtube.com/vi/UeBX7Ide5a0/hqdefault.jpg
2020-08-03 01:10:53 +03:00
[video]: https://www.youtube.com/watch?v=UeBX7Ide5a0
2020-12-28 07:33:28 +03:00
[nur]: https://github.com/nix-community/NUR