nixin-krops/README.md

75 lines
2.9 KiB
Markdown
Raw Permalink Normal View History

2024-12-18 21:21:38 +00:00
# Nixin krops POC
2024-12-19 11:51:56 +00:00
This is a proof of concept of using krops to deploy nixos configurations generated by nixin
2024-12-19 23:17:42 +00:00
The configurations of the servers are stored in sub-directories of the config directory :
2024-12-19 11:51:56 +00:00
```
├── config
│   ├── server-01
│   │   ├── configuration.nix
│   │   └── hardware-configuration.nix
│   └── server-02
│   ├── configuration.nix
│   └── hardware-configuration.nix
```
2024-12-19 14:57:17 +00:00
These configurations can import shared modules stored in the modules directory
2024-12-19 11:51:56 +00:00
```
├── modules
2024-12-19 14:57:17 +00:00
│   ├── nixin.nix
2024-12-19 23:22:55 +00:00
│   ├── reverse-proxy.nix
2024-12-19 17:30:31 +00:00
│   ├── users.nix
│   └── wireguard-client.nix
2024-12-19 11:51:56 +00:00
```
The file `nixpkgs.json` contains the revision of nixpkgs to use. See the tips section for how to update it
The file `krops.nix` is the main deployment configuration that ties everything up. If new servers are added to the config directory, they must also be added in this file.
The servers mush be accessible with ssh as `root` or as a user with passwordless sudo capability, as defined in `krops.nix`
Secrets are stored in a sub directory of a separate git repository, managed with [passwordstore](https://www.passwordstore.org/)
2024-12-19 23:22:55 +00:00
This directory must be available at ` ~/.password-store/nixin-password-store/krops`. (This is also defined in `krops.nix`)
When deploying a configuration, the secrets files are decrypted and copied to server into the /var/srv/secret directory
2024-12-19 17:30:31 +00:00
Referencing a secret file path in the configuration is done like this :
```nix
privateKeyFile = toString <secrets/wg-private.key>;
```
2024-12-19 23:22:55 +00:00
If instead the content of a secret file needs to be substituted into the configuration, it can be done like this :
2024-12-19 17:30:31 +00:00
```nix
security.pki.certificates = [ (builtins.readFile toString <secrets/ca-bundle.crt>) ];
```
2024-12-19 11:51:56 +00:00
Sample `/var/src` on a server after configuration deployment :
```sh
[root@arachnide:~]# ls -l /var/src
total 20
drwxr-xr-x 2 root root 4096 18 déc. 19:07 config
drwxr-xr-x 2 root root 4096 18 déc. 21:39 modules
lrwxrwxrwx 1 root root 24 19 déc. 10:28 nixos-config -> config/configuration.nix
drwxr-xr-x 10 root root 4096 19 déc. 10:29 nixpkgs
drwx------ 2 root root 4096 19 déc. 10:30 secrets
```
2024-12-18 21:21:38 +00:00
2024-12-19 10:07:32 +00:00
## Tips
2024-12-19 11:51:56 +00:00
The file `/var/src/.populate` needs to be created on target servers to be able to deploy a configuration to them. This is a protection to avoid deploying to a machine that is not meant to be managed with krops
Deploying configuration of only one server :
2024-12-18 21:21:38 +00:00
nix-build ./krops.nix -A arachnide && ./result
2024-12-19 11:51:56 +00:00
Deploying configuration of all servers :
2024-12-18 21:21:38 +00:00
nix-build ./krops.nix -A all && ./result
2024-12-19 11:51:56 +00:00
Updating the nixpkgs revision that is used :
```sh
2024-12-19 10:07:32 +00:00
nix-prefetch-git --url https://github.com/NixOS/nixpkgs --rev "refs/heads/nixos-24.11" > nixpkgs.json
2024-12-19 11:51:56 +00:00
```
Rebuilding the system on the host itself :
```sh
nixos-rebuild switch -I /var/src
```
2024-12-19 10:07:32 +00:00
2024-12-18 21:21:38 +00:00
## References
- krops : https://github.com/krebs/krops