Unverified Commit f32e786e authored by Robert Hensing's avatar Robert Hensing Committed by GitHub
Browse files

Merge pull request #292099 from hercules-ci/update-nixops_unstable

nixops_unstable to nixops_unstable_minimal.withPlugins migration + update
parents 6431075d e63713d2
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -9,7 +9,7 @@ let
    #  - Alternatively, blocked on a NixOps 2 release
    #    https://github.com/NixOS/nixops/issues/1242
    # stable = testsLegacyNetwork { nixopsPkg = pkgs.nixops; };
    unstable = testsForPackage { nixopsPkg = pkgs.nixops_unstable; };
    unstable = testsForPackage { nixopsPkg = pkgs.nixops_unstable_minimal; };

    # inherit testsForPackage;
  };
@@ -32,6 +32,7 @@ let
          pkgs.hello
          pkgs.figlet
        ];
        virtualisation.memorySize = 2048;

        # TODO: make this efficient, https://github.com/NixOS/nixpkgs/issues/180529
        system.includeBuildDependencies = true;
+116 −51
Original line number Diff line number Diff line
{ python3 }:
{ lib, python3, emptyFile }:

let
  inherit (lib) extends;

  # 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;

  nixopsContextBase = this: {

    python = python3.override {
      packageOverrides = self: super: {
        nixops = self.callPackage ./unwrapped.nix { };
    } // (plugins self);
      } // (this.plugins self super);
    };

  plugins = ps: with ps; rec {
    plugins = ps: _super: 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 { };
@@ -25,25 +35,79 @@ let
      nixopsvbox = nixops-vbox;
    };

    # We should not reapply the overlay, but it tends to work out. (It's been this way since poetry2nix was dropped.)
    availablePlugins = this.plugins this.python.pkgs this.python.pkgs;

    selectedPlugins = [];

    # selector is a function mapping pythonPackages to a list of plugins
    # e.g. nixops_unstable.withPlugins (ps: with ps; [ nixops-aws ])
  withPlugins = selector: let
    selected = selector (plugins python.pkgs);
  in python.pkgs.toPythonApplication (python.pkgs.nixops.overridePythonAttrs (old: {
    propagatedBuildInputs = old.propagatedBuildInputs ++ selected;
    withPlugins = selector:
      this.extend (this: _old: {
        selectedPlugins = selector this.availablePlugins;
      });

    rawPackage = this.python.pkgs.toPythonApplication (this.python.pkgs.nixops.overridePythonAttrs (old: {
      propagatedBuildInputs = old.propagatedBuildInputs ++ this.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 // {
      plugins = plugins python.pkgs;
      inherit withPlugins python;
    # Extra package attributes that aren't derivation attributes, just like `mkDerivation`'s `passthru`.
    extraPackageAttrs = {
      inherit (this) selectedPlugins availablePlugins withPlugins python;
      tests = this.rawPackage.tests // {
        nixos = this.rawPackage.tests.nixos.passthru.override {
          nixopsPkg = this.rawPackage;
        };
  }));
in withPlugins (ps: [
        commutative_addAvailablePlugins_withPlugins =
          assert
            (this.public.addAvailablePlugins (self: super: { inherit emptyFile; })).withPlugins (ps: [ emptyFile ])
            ==
            # Note that this value proves that the package is not instantiated until the end, where it's valid again.
            (this.public.withPlugins (ps: [ emptyFile ])).addAvailablePlugins (self: super: { inherit emptyFile; });
          emptyFile;
      }
        # Make sure we also test with a configuration that's been extended with a plugin.
        // lib.optionalAttrs (this.selectedPlugins == [ ]) {
        withAPlugin =
          lib.recurseIntoAttrs
            (this.withPlugins (ps: with ps; [ nixops-encrypted-links ])).tests;
      };
      overrideAttrs = f: this.extend (this: oldThis: {
        rawPackage = oldThis.rawPackage.overrideAttrs f;
      });
      /**
       * nixops.addAvailablePlugins: Overlay -> Package
       *
       * Add available plugins to the package. You probably also want to enable
       * them with the `withPlugins` method.
       */
      addAvailablePlugins = newPlugins: this.extend (finalThis: oldThis: {
        plugins = lib.composeExtensions oldThis.plugins newPlugins;
      });

      # For those who need or dare.
      internals = this;
    };

    package = lib.lazyDerivation { outputs = [ "out" "dist" ]; derivation = this.rawPackage; } // this.extraPackageAttrs;

    public = this.package;
  };

  minimal = encapsulate nixopsContextBase;

in
{
  nixops_unstable_minimal = minimal;

  # Not recommended; too fragile.
  nixops_unstable_full = minimal.withPlugins (ps: [
    ps.nixops-aws
    ps.nixops-digitalocean
    ps.nixops-encrypted-links
@@ -53,4 +117,5 @@ in withPlugins (ps: [
    ps.nixops-hetznercloud
    ps.nixops-libvirtd
    ps.nixops-vbox
])
  ]);
}
+3 −3
Original line number Diff line number Diff line
@@ -12,14 +12,14 @@

buildPythonPackage {
  pname = "nixops-aws";
  version = "unstable-2023-08-09";
  version = "unstable-2024-02-29";
  pyproject = true;

  src = fetchFromGitHub {
    owner = "NixOS";
    repo = "nixops-aws";
    rev = "8802d1cda9004ec1362815292c2a8ab95e6d64e8";
    hash = "sha256-i0KjFrwpDHRch9jorccdVwnjAQiORClDUqm2R2xvwuU=";
    rev = "d173b2f14ec767d782ceab45fb22b32fe3b5a1f7";
    hash = "sha256-ocTtc7POt1bugb9Bki2ew2Eh5uc933GftNw1twoOJsc=";
  };

  postPatch = ''
+4 −4
Original line number Diff line number Diff line
@@ -13,14 +13,14 @@

buildPythonApplication rec {
  pname = "nixops";
  version = "unstable-2023-12-17";
  version = "unstable-2024-02-28";
  pyproject = true;

  src = fetchFromGitHub {
    owner = "NixOS";
    repo = "nixops";
    rev = "053668e849bb369973cf265b7e8f38e66ef70138";
    hash = "sha256-Kus1Ls1tT8fVGLX0NakRXmjuz5/J/tfqU4TLOkiZqvo=";
    rev = "08feccb14074c5434f3e483d19a7f7d9bfcdb669";
    hash = "sha256-yWeF5apQJdChjYVSOyH6LYjJYGa1RL68LRHrSgZ9l8U=";
  };

  postPatch = ''
@@ -50,7 +50,7 @@ buildPythonApplication rec {
  pythonImportsCheck = [ "nixops" ];

  passthru = {
    tests.nixops = nixosTests.nixops.unstable;
    tests.nixos = nixosTests.nixops.unstable;
    updateScript = unstableGitUpdater {};
  };

+5 −1
Original line number Diff line number Diff line
@@ -782,8 +782,12 @@ mapAliases ({
  nix_2_4 = nixVersions.nix_2_4;
  nix_2_5 = nixVersions.nix_2_5;
  nix_2_6 = nixVersions.nix_2_6;
  nixops = throw "'nixops' has been removed. Please use 'nixops_unstable' for the time being."; # Added 2023-10-26
  nixops = throw "'nixops' has been removed. Please use 'nixops_unstable_minimal' for the time being. E.g. nixops_unstable_minimal.withPlugins (ps: [ ps.nixops-gce ])"; # Added 2023-10-26
  nixopsUnstable = nixops_unstable; # Added 2022-03-03

  # When the nixops_unstable alias is removed, nixops_unstable_minimal can be renamed to nixops_unstable.
  nixops_unstable = throw "nixops_unstable has been replaced. Please use for example 'nixops_unstable_minimal.withPlugins (ps: [ ps.nixops-gce ps.nixops-encrypted-links ])' instead"; # Added 2024-02-28

  nixosTest = testers.nixosTest; # Added 2022-05-05
  nmap-unfree = nmap; # Added 2021-04-06
  nodejs_14 = throw "nodejs_14 has been removed as it is EOL."; # Added 2023-10-30
Loading