diff options
| author | tv <tv@krebsco.de> | 2026-11-12 01:21:34 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-12 01:21:34 +0000 |
| commit | 0c72a6e05f5912e70a8579ed59f089f7f43353c6 (patch) | |
| tree | fdaa0fbf3090bdb8fe533e10a38cb6504da1e9d1 | |
| parent | 9fbc2ee11f47810a58ce2c96ae51c2969f974fa1 (diff) | |
flake: pass populate to krops, describe using krops from a flake
pkgs/krops takes populate as an argument, which nixpkgs doesn't provide,
so evaluating any of the flake's lib attributes from pkgs/krops fails.
The flake passes its own populate.
The README describes using krops from a flake: writeDeploy and the other
functions from lib.<system>, evalSource and mkTarget from krops' lib
directory, and deploying with nix run --impure, because krops' lib
evaluates <nixpkgs/lib>, environment variables, and /etc/hostname.
| -rw-r--r-- | README.md | 34 | ||||
| -rw-r--r-- | flake.nix | 2 |
2 files changed, 35 insertions, 1 deletions
@@ -53,6 +53,40 @@ in ``` and run `$(nix-build --no-out-link krops.nix)` to deploy the target machine. + + +## Using krops from a flake + +krops' flake provides `populate`, `writeDeploy`, and the other functions +described below as `lib.<system>`, and its `lib` directory provides +`evalSource` and `mkTarget`: + +```nix +{ + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + inputs.krops.url = "git+https://cgit.krebsco.de/krops"; + inputs.krops.inputs.nixpkgs.follows = "nixpkgs"; + + outputs = { self, krops, ... }: let + system = "x86_64-linux"; + lib = import "${krops}/lib"; + in { + apps.${system}.deploy = { + type = "app"; + program = toString (krops.lib.${system}.writeDeploy "deploy" { + source = lib.evalSource [{ + nixos-config.file = toString ./configuration.nix; + nixpkgs.flake-input = { flake = toString self; name = "nixpkgs"; }; + }]; + target = "root@YOUR_IP_ADDRESS_OR_HOST_NAME_HERE"; + }); + }; + }; +} +``` + +krops evaluates `<nixpkgs/lib>`, environment variables, and `/etc/hostname`, +which pure evaluation doesn't allow, so deploy with `nix run --impure .#deploy`. krops exports some funtions under `krops.` namely: ## writeDeploy @@ -19,7 +19,7 @@ lib = forAllSystems (system: let pkgs = nixpkgs.legacyPackages.${system}; - krops = pkgs.callPackage ./pkgs/krops {}; + krops = pkgs.callPackage ./pkgs/krops { inherit populate; }; populate = pkgs.callPackage ./pkgs/populate {}; in { inherit populate; |
