oizys/README.md

70 lines
2.4 KiB
Markdown
Raw Normal View History

2020-10-24 22:55:15 -05:00
# nixos-flake-example
This shows how to build the same config, with and without flakes.
It also shows that `flake.nix` is basically just some syntax.
You can run `./check.sh` to show that this builds the same system config
with/without flakes.
2020-10-24 23:28:56 -05:00
## flake fundamentals
Nix is in flakes mode when:
1. `nixos-rebuild <cmd> --flake '.#'` is used
2. `nix build '.#something'` the hash-tag syntax is used
2020-10-24 23:37:56 -05:00
**This automatically loads from a `flake.nix` in the specified dir. See these examples:**
2020-10-24 23:28:56 -05:00
2020-10-24 23:37:56 -05:00
These three examples, for me, are all the same source, but accessed in different ways:
2020-10-24 23:28:56 -05:00
2020-10-24 23:37:56 -05:00
* `nix build '.#nixosConfigurations.mysystem'`
2020-10-24 23:35:21 -05:00
2020-10-24 23:37:56 -05:00
(loads `flake.nix` from `.` (current dir))
2020-10-24 23:35:21 -05:00
2020-10-24 23:37:56 -05:00
* `nix build '/home/cole/code/nixos-flake-example#nixosConfigurations.mysystem'`
2020-10-24 23:28:56 -05:00
2020-10-24 23:37:56 -05:00
(loads `flake.nix` from `/home/cole/code/nixos-flake-example`)
* `nix build 'github.com:colemickens/nixos-flake-example#nixosConfigurations.mysystem'`
(nix will clone my github repo, then load `flake.nix` from `flake.nix` in the root of that repo checkout)
2020-10-24 23:28:56 -05:00
2020-10-24 23:35:21 -05:00
## more tips
1. `nixos-rebuild build --flake '.#'` will automatically try to find and build the attribute: `.#nixosConfigurations.your_hostname` (assuming your machines hostname is `your_hostname`)
2020-10-24 22:55:15 -05:00
## overview
The `./check.sh` script proves they give the same exact system toplevel outputs:
2020-10-24 22:55:15 -05:00
```console
cole@slynux ~/code/nixos-flake-example master* 7s
./check.sh
2020-10-24 22:55:15 -05:00
:: Updating the 'nixpkgs' input in flake.nix
+ nix flake update --update-input nixpkgs
+ set +x
2020-10-24 22:55:15 -05:00
:: Using 'nixos-rebuild' to build the 'mysystem' toplevel
+ nixos-rebuild build --flake .#mysystem
warning: Git tree '/home/cole/code/nixos-flake-example' is dirty
building the system configuration...
warning: Git tree '/home/cole/code/nixos-flake-example' is dirty
+ set +x
2020-10-24 22:55:15 -05:00
:: Using rev=007126eef72271480cb7670e19e501a1ad2c1ff2 for <nixpkgs> (extracted from flake.nix)
2020-10-24 22:55:15 -05:00
:: Setting NIX_PATH to the same values flakes is using
+ NIX_PATH=nixpkgs=https://github.com/nixos/nixpkgs/archive/007126eef72271480cb7670e19e501a1ad2c1ff2.tar.gz:nixos-config=/home/cole/code/nixos-flake-example/configuration.nix
+ nix-build '<nixpkgs/nixos>' -A config.system.build.toplevel
/nix/store/gg1jhmzqndqa0rfnwfdbnzrn8f74ckr6-nixos-system-mysystem-21.03pre-git
+ set +x
2020-10-24 22:55:15 -05:00
flake: /nix/store/gg1jhmzqndqa0rfnwfdbnzrn8f74ckr6-nixos-system-mysystem-21.03pre-git
clssc: /nix/store/gg1jhmzqndqa0rfnwfdbnzrn8f74ckr6-nixos-system-mysystem-21.03pre-git
2020-10-24 22:55:15 -05:00
```
2020-10-24 22:55:15 -05:00