DBCDK / morph

NixOS deployment tool
MIT License
839 stars 63 forks source link

Flake support #124

Open bqv opened 4 years ago

bqv commented 4 years ago

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.

shmish111 commented 3 years ago

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.

tomprince commented 3 years ago

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

wmertens commented 2 years ago

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

wmertens commented 2 years ago

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
      ];
    };
  };
}
buckley310 commented 2 years ago

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.

solomon-b commented 2 years ago

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

mmahut commented 1 year ago

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

wmertens commented 1 year ago

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.

tshakah commented 1 week ago

What's the status of this? I noticed morph introduced flakes internally recently