morph icon indicating copy to clipboard operation
morph copied to clipboard

Flake support

Open bqv opened this issue 3 years ago • 8 comments

This will be vague, because I'm not entirely sure what form it would ideally take, but I would be interested in using this if it supported my flake-based systems.

The issue with tools such of this supporting flakes is that flakes are already a toplevel combination of configs, so there is not much room for configs "above" the flake. The result being that the ideal model is probably something that actually sits inside flake.nix and can be invoked via nix, rather than the other way around.

At a guess.

bqv avatar Jul 27 '20 09:07 bqv

Please don't do this until flakes are in the official nix release, not the unstable binary. I was unable to use nixops because I needed features in the latest version but it uses flakes but we don't use bleeding edge nix. We had a problem with fetchgit for it, some things need to be ironed out still.

shmish111 avatar Jan 27 '21 12:01 shmish111

It seems reasonable to add optional support for flakes, before they stop being experimental, as long as it doesn't become required.. Personally, I'm interested in some form of support, since I'd like to be able to take advantage of the pinning support that flakes provided

tomprince avatar Oct 09 '21 04:10 tomprince

flakes are in Nix 2.4 stable now, but you have to enable them. Requiring v2.4 seems ok, no?

wmertens avatar Dec 14 '21 11:12 wmertens

As for how to use it, I think flake support in NixOS is already halfway there, the output requires the attrset nixosConfigurations with an attribute per system. So you can already specify a multi-system configuration in a NixOS flake config.

So morph would only need the deployment parameters, and those could be either in a separate deployments attrset with the same name as the system or a generic one if missing, or perhaps in the system config itself via a morph module that you need to add via a flake input.

Something like

{
  description = "Morph NixOS configuration with flakes";
  inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-21.11";
  inputs.morph.url = "github:DBCDK/morph/v1";

  outputs = { self, nixpkgs, morph }: {
    nixosConfigurations.wmertens-nixos = nixpkgs.lib.nixosSystem {
      system = "x86_64-linux";
      modules = [
        # morph support
        morph.module
        { deployment = { targetHost = "wmertens-nixos"; }; }

        # Use the flake path for the nix path
        { nix.nixPath = [ "nixpkgs=${nixpkgs.outPath}" ]; }

        ./configuration.nix
      ];
    };
  };
}

wmertens avatar Dec 14 '21 11:12 wmertens

I like the above solution of adding the deployment options into the host configuration itself. This is basically how I am already using morph today. I add deployment settings directly to the hosts in my flake, along with a small module I wrote that defines the settings. I then have a stub morph configuration that just pulls my hosts out of my flake and presents them to morph. It's been working well for me. Would be neat to be able to use it natively without the stub to shim it together.

buckley310 avatar Dec 24 '21 05:12 buckley310

Whats the status on flake support in morph? I've been holding off on migrating from nixops until this was ironed out.

solomon-b avatar Aug 22 '22 17:08 solomon-b

Is this something that is planned? If not, we would like to know to make sure to move away from morph.

mmahut avatar Jul 20 '23 12:07 mmahut

I migrated to deploy-rs, which does have flake support, and sops-nix for secrets. Morph was great but switching to flakes gave me many benefits: choosing netdata from unstable, inspecting the generated config with the repl, etc.

wmertens avatar Jul 21 '23 07:07 wmertens