NixOS / nixops

NixOps is a tool for deploying to NixOS machines in a network or cloud.
https://nixos.org/nixops
GNU Lesser General Public License v3.0
1.84k stars 363 forks source link

Documentation: How to specify nixopsConfiguration.default? #1553

Open tartavull opened 1 year ago

tartavull commented 1 year ago

Hello, I'm new to nixops and couldn't find how to set up a flake. Is there any documentation explaining so?

nixops create                                                                                                                                                                ~/code/genetic-intelligence
error: attribute 'default' missing

       at /nix/store/6ax7j3zyv010j3093m73fxsppc5b3hfr-python3-3.10.10-env/lib/python3.10/site-packages/nix/eval-machine-info.nix:20:15:

           19|
           20|   flakeExpr = (builtins.getFlake flakeUri).outputs.nixopsConfigurations.default;
             |               ^
           21|

       … while evaluating the attribute 'outputs.nixopsConfigurations.default'

       at /nix/store/fy3x5qk811q1kjilcv1416p311pfh1a5-source/default.nix:136:17:

          135|               {
          136|                 ${key} = (attrs.${key} or { })
             |                 ^
          137|                   // (appendSystem key system ret);

       … while calling 'call'

       at /nix/store/6ax7j3zyv010j3093m73fxsppc5b3hfr-python3-3.10.10-env/lib/python3.10/site-packages/nix/eval-machine-info.nix:12:10:

           11| let
           12|   call = x: if builtins.isFunction x then x args else x;
             |          ^
           13|

       … from call site

       at /nix/store/6ax7j3zyv010j3093m73fxsppc5b3hfr-python3-3.10.10-env/lib/python3.10/site-packages/nix/eval-machine-info.nix:36:11:

           35|       ++ optional (flakeUri != null)
           36|         ((call flakeExpr) // { _file = "<${flakeUri}>"; });
             |           ^
           37|

       … while calling 'zipAttrs'

       at /nix/store/6ax7j3zyv010j3093m73fxsppc5b3hfr-python3-3.10.10-env/lib/python3.10/site-packages/nix/eval-machine-info.nix:17:14:

           16|
           17|   zipAttrs = set: builtins.listToAttrs (
             |              ^
           18|     map (name: { inherit name; value = builtins.catAttrs name set; }) (builtins.concatMap builtins.attrNames set));

       … from call site

       at /nix/store/6ax7j3zyv010j3093m73fxsppc5b3hfr-python3-3.10.10-env/lib/python3.10/site-packages/nix/eval-machine-info.nix:38:13:

           37|
           38|   network = zipAttrs networks;
             |             ^
           39|
error: evaluation of the deployment specification failed
ldicarlo commented 1 year ago

Hi, can you provide your flake.nix if any ?

akavel commented 1 year ago

@tartavull Sooo, based on https://github.com/NixOS/nixops/blob/fc9b55c55da62f949028143b974f67fdc7f40c8b/nix/eval-machine-info.nix#L20 and some other lines in that file, as well as some rough understanding of flakes in general, I seem to believe a minimal flake.nix for nixopsUnstable would look like below:

{
  description = "NixOps config of my servers";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/release-22.11";
  };

  outputs = { self, ... }@inputs: {
    nixopsConfigurations.default = {
      inherit (inputs) nixpkgs;

      network.description = "my servers";
      network.storage.legacy = {};
      #network.storage.memory = {};  # what's the difference with above?
      #network.enableRollback = true;  # uncomment if you like/know what this even does

      ### Machines ###

      #my-machine-1 = { pkgs, ... }: {
      #  deployment.targetHost = "1.2.3.4";
      #  services.nginx.enable = true;
      #};
    };
  };
}