diff options
author | Robert Hensing <robert@roberthensing.nl> | 2024-02-28 22:33:48 +0100 |
---|---|---|
committer | Robert Hensing <robert@roberthensing.nl> | 2024-03-06 22:47:23 +0100 |
commit | 48150e79c52b4f212ddf608d85b242c0a957fc2b (patch) | |
tree | 7685c0df1342e9f60667c05702e69791e6325c8e | |
parent | 27b08a25ccef11709250163a5121ea3607115b2c (diff) |
nixops_unstable_*: Use explicit fixpoint with encapsulation
No change in behavior. Just explicit recursion that's not taken advantage of. (This is working towards a managable setup for adding a bunch of overriding methods that make life easier for external plugin packagers.)
-rw-r--r-- | pkgs/applications/networking/cluster/nixops/default.nix | 119 |
1 files changed, 67 insertions, 52 deletions
diff --git a/pkgs/applications/networking/cluster/nixops/default.nix b/pkgs/applications/networking/cluster/nixops/default.nix index ea0f2af2b4fcc..ad3caf0d9dbfd 100644 --- a/pkgs/applications/networking/cluster/nixops/default.nix +++ b/pkgs/applications/networking/cluster/nixops/default.nix @@ -1,71 +1,86 @@ { lib, python3 }: let - python = python3.override { - packageOverrides = self: super: { - nixops = self.callPackage ./unwrapped.nix { }; - } // (plugins self); - }; + inherit (lib) extends; - plugins = ps: with ps; rec { - nixops-aws = callPackage ./plugins/nixops-aws.nix { }; - nixops-digitalocean = callPackage ./plugins/nixops-digitalocean.nix { }; - nixops-encrypted-links = callPackage ./plugins/nixops-encrypted-links.nix { }; - nixops-gce = callPackage ./plugins/nixops-gce.nix { }; - nixops-hercules-ci = callPackage ./plugins/nixops-hercules-ci.nix { }; - nixops-hetzner = callPackage ./plugins/nixops-hetzner.nix { }; - nixops-hetznercloud = callPackage ./plugins/nixops-hetznercloud.nix { }; - nixops-libvirtd = callPackage ./plugins/nixops-libvirtd.nix { }; - nixops-vbox = callPackage ./plugins/nixops-vbox.nix { }; - nixos-modules-contrib = callPackage ./plugins/nixos-modules-contrib.nix { }; + # doc: https://github.com/NixOS/nixpkgs/pull/158781/files#diff-854251fa1fe071654921224671c8ba63c95feb2f96b2b3a9969c81676780053a + encapsulate = layerZero: + let + fixed = layerZero ({ extend = f: encapsulate (extends f layerZero); } // fixed); + in fixed.public; - # aliases for backwards compatibility - nixops-gcp = nixops-gce; - nixops-virtd = nixops-libvirtd; - nixopsvbox = nixops-vbox; - }; + nixopsContextBase = this: { - withPlugins = withPlugins' { availablePlugins = plugins python.pkgs; }; + python = python3.override { + packageOverrides = self: super: { + nixops = self.callPackage ./unwrapped.nix { }; + } // (this.plugins self); + }; - # selector is a function mapping pythonPackages to a list of plugins - # e.g. nixops_unstable.withPlugins (ps: with ps; [ nixops-aws ]) - withPlugins' = { availablePlugins }: selector: - let - selectedPlugins = selector availablePlugins; - r = python.pkgs.toPythonApplication (python.pkgs.nixops.overridePythonAttrs (old: { - propagatedBuildInputs = old.propagatedBuildInputs ++ selectedPlugins; + plugins = ps: with ps; rec { + nixops-aws = callPackage ./plugins/nixops-aws.nix { }; + nixops-digitalocean = callPackage ./plugins/nixops-digitalocean.nix { }; + nixops-encrypted-links = callPackage ./plugins/nixops-encrypted-links.nix { }; + nixops-gce = callPackage ./plugins/nixops-gce.nix { }; + nixops-hercules-ci = callPackage ./plugins/nixops-hercules-ci.nix { }; + nixops-hetzner = callPackage ./plugins/nixops-hetzner.nix { }; + nixops-hetznercloud = callPackage ./plugins/nixops-hetznercloud.nix { }; + nixops-libvirtd = callPackage ./plugins/nixops-libvirtd.nix { }; + nixops-vbox = callPackage ./plugins/nixops-vbox.nix { }; + nixos-modules-contrib = callPackage ./plugins/nixos-modules-contrib.nix { }; + + # aliases for backwards compatibility + nixops-gcp = nixops-gce; + nixops-virtd = nixops-libvirtd; + nixopsvbox = nixops-vbox; + }; - # Propagating dependencies leaks them through $PYTHONPATH which causes issues - # when used in nix-shell. - postFixup = '' - rm $out/nix-support/propagated-build-inputs - ''; + withPlugins = this.withPlugins' { availablePlugins = this.plugins this.python.pkgs; }; - passthru = old.passthru // { - inherit availablePlugins selectedPlugins; - inherit withPlugins python; - tests = old.passthru.tests // { - nixos = old.passthru.tests.nixos.passthru.override { - nixopsPkg = r; + # selector is a function mapping pythonPackages to a list of plugins + # e.g. nixops_unstable.withPlugins (ps: with ps; [ nixops-aws ]) + withPlugins' = { availablePlugins }: selector: + let + selectedPlugins = selector availablePlugins; + r = this.python.pkgs.toPythonApplication (this.python.pkgs.nixops.overridePythonAttrs (old: { + propagatedBuildInputs = old.propagatedBuildInputs ++ selectedPlugins; + + # Propagating dependencies leaks them through $PYTHONPATH which causes issues + # when used in nix-shell. + postFixup = '' + rm $out/nix-support/propagated-build-inputs + ''; + + passthru = old.passthru // { + inherit availablePlugins selectedPlugins; + inherit (this) withPlugins python; + tests = old.passthru.tests // { + nixos = old.passthru.tests.nixos.passthru.override { + nixopsPkg = r; + }; + } + # Make sure we also test with a configuration that's been extended with a plugin. + // lib.optionalAttrs (selectedPlugins == [ ]) { + withAPlugin = + lib.recurseIntoAttrs + (this.withPlugins (ps: with ps; [ nixops-encrypted-links ])).tests; }; - } - # Make sure we also test with a configuration that's been extended with a plugin. - // lib.optionalAttrs (selectedPlugins == [ ]) { - withAPlugin = - lib.recurseIntoAttrs - (withPlugins (ps: with ps; [ nixops-encrypted-links ])).tests; }; - }; - })); - in - r; + })); + in + r; + + public = this.withPlugins (ps: []); + }; + + minimal = encapsulate nixopsContextBase; in { - nixops_unstable_minimal = withPlugins (ps: [ ]); + nixops_unstable_minimal = minimal; # Not recommended; too fragile. - nixops_unstable_full = withPlugins (ps: [ + nixops_unstable_full = minimal.withPlugins (ps: [ ps.nixops-aws ps.nixops-digitalocean ps.nixops-encrypted-links |