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

nixops_unstable to nixops_unstable_minimal.withPlugins migration + update

authored by Robert Hensing and committed by GitHub f32e786e 6431075d

+135 -58
+2 -1
nixos/tests/nixops/default.nix
··· 9 9 # - Alternatively, blocked on a NixOps 2 release 10 10 # https://github.com/NixOS/nixops/issues/1242 11 11 # stable = testsLegacyNetwork { nixopsPkg = pkgs.nixops; }; 12 - unstable = testsForPackage { nixopsPkg = pkgs.nixops_unstable; }; 12 + unstable = testsForPackage { nixopsPkg = pkgs.nixops_unstable_minimal; }; 13 13 14 14 # inherit testsForPackage; 15 15 }; ··· 32 32 pkgs.hello 33 33 pkgs.figlet 34 34 ]; 35 + virtualisation.memorySize = 2048; 35 36 36 37 # TODO: make this efficient, https://github.com/NixOS/nixpkgs/issues/180529 37 38 system.includeBuildDependencies = true;
+113 -48
pkgs/applications/networking/cluster/nixops/default.nix
··· 1 - { python3 }: 1 + { lib, python3, emptyFile }: 2 2 3 3 let 4 - python = python3.override { 5 - packageOverrides = self: super: { 6 - nixops = self.callPackage ./unwrapped.nix { }; 7 - } // (plugins self); 8 - }; 4 + inherit (lib) extends; 5 + 6 + # doc: https://github.com/NixOS/nixpkgs/pull/158781/files#diff-854251fa1fe071654921224671c8ba63c95feb2f96b2b3a9969c81676780053a 7 + encapsulate = layerZero: 8 + let 9 + fixed = layerZero ({ extend = f: encapsulate (extends f layerZero); } // fixed); 10 + in fixed.public; 11 + 12 + nixopsContextBase = this: { 13 + 14 + python = python3.override { 15 + packageOverrides = self: super: { 16 + nixops = self.callPackage ./unwrapped.nix { }; 17 + } // (this.plugins self super); 18 + }; 19 + 20 + plugins = ps: _super: with ps; rec { 21 + nixops-aws = callPackage ./plugins/nixops-aws.nix { }; 22 + nixops-digitalocean = callPackage ./plugins/nixops-digitalocean.nix { }; 23 + nixops-encrypted-links = callPackage ./plugins/nixops-encrypted-links.nix { }; 24 + nixops-gce = callPackage ./plugins/nixops-gce.nix { }; 25 + nixops-hercules-ci = callPackage ./plugins/nixops-hercules-ci.nix { }; 26 + nixops-hetzner = callPackage ./plugins/nixops-hetzner.nix { }; 27 + nixops-hetznercloud = callPackage ./plugins/nixops-hetznercloud.nix { }; 28 + nixops-libvirtd = callPackage ./plugins/nixops-libvirtd.nix { }; 29 + nixops-vbox = callPackage ./plugins/nixops-vbox.nix { }; 30 + nixos-modules-contrib = callPackage ./plugins/nixos-modules-contrib.nix { }; 31 + 32 + # aliases for backwards compatibility 33 + nixops-gcp = nixops-gce; 34 + nixops-virtd = nixops-libvirtd; 35 + nixopsvbox = nixops-vbox; 36 + }; 37 + 38 + # We should not reapply the overlay, but it tends to work out. (It's been this way since poetry2nix was dropped.) 39 + availablePlugins = this.plugins this.python.pkgs this.python.pkgs; 40 + 41 + selectedPlugins = []; 42 + 43 + # selector is a function mapping pythonPackages to a list of plugins 44 + # e.g. nixops_unstable.withPlugins (ps: with ps; [ nixops-aws ]) 45 + withPlugins = selector: 46 + this.extend (this: _old: { 47 + selectedPlugins = selector this.availablePlugins; 48 + }); 49 + 50 + rawPackage = this.python.pkgs.toPythonApplication (this.python.pkgs.nixops.overridePythonAttrs (old: { 51 + propagatedBuildInputs = old.propagatedBuildInputs ++ this.selectedPlugins; 52 + 53 + # Propagating dependencies leaks them through $PYTHONPATH which causes issues 54 + # when used in nix-shell. 55 + postFixup = '' 56 + rm $out/nix-support/propagated-build-inputs 57 + ''; 58 + })); 59 + 60 + # Extra package attributes that aren't derivation attributes, just like `mkDerivation`'s `passthru`. 61 + extraPackageAttrs = { 62 + inherit (this) selectedPlugins availablePlugins withPlugins python; 63 + tests = this.rawPackage.tests // { 64 + nixos = this.rawPackage.tests.nixos.passthru.override { 65 + nixopsPkg = this.rawPackage; 66 + }; 67 + commutative_addAvailablePlugins_withPlugins = 68 + assert 69 + (this.public.addAvailablePlugins (self: super: { inherit emptyFile; })).withPlugins (ps: [ emptyFile ]) 70 + == 71 + # Note that this value proves that the package is not instantiated until the end, where it's valid again. 72 + (this.public.withPlugins (ps: [ emptyFile ])).addAvailablePlugins (self: super: { inherit emptyFile; }); 73 + emptyFile; 74 + } 75 + # Make sure we also test with a configuration that's been extended with a plugin. 76 + // lib.optionalAttrs (this.selectedPlugins == [ ]) { 77 + withAPlugin = 78 + lib.recurseIntoAttrs 79 + (this.withPlugins (ps: with ps; [ nixops-encrypted-links ])).tests; 80 + }; 81 + overrideAttrs = f: this.extend (this: oldThis: { 82 + rawPackage = oldThis.rawPackage.overrideAttrs f; 83 + }); 84 + /** 85 + * nixops.addAvailablePlugins: Overlay -> Package 86 + * 87 + * Add available plugins to the package. You probably also want to enable 88 + * them with the `withPlugins` method. 89 + */ 90 + addAvailablePlugins = newPlugins: this.extend (finalThis: oldThis: { 91 + plugins = lib.composeExtensions oldThis.plugins newPlugins; 92 + }); 9 93 10 - plugins = ps: with ps; rec { 11 - nixops-aws = callPackage ./plugins/nixops-aws.nix { }; 12 - nixops-digitalocean = callPackage ./plugins/nixops-digitalocean.nix { }; 13 - nixops-encrypted-links = callPackage ./plugins/nixops-encrypted-links.nix { }; 14 - nixops-gce = callPackage ./plugins/nixops-gce.nix { }; 15 - nixops-hercules-ci = callPackage ./plugins/nixops-hercules-ci.nix { }; 16 - nixops-hetzner = callPackage ./plugins/nixops-hetzner.nix { }; 17 - nixops-hetznercloud = callPackage ./plugins/nixops-hetznercloud.nix { }; 18 - nixops-libvirtd = callPackage ./plugins/nixops-libvirtd.nix { }; 19 - nixops-vbox = callPackage ./plugins/nixops-vbox.nix { }; 20 - nixos-modules-contrib = callPackage ./plugins/nixos-modules-contrib.nix { }; 94 + # For those who need or dare. 95 + internals = this; 96 + }; 21 97 22 - # aliases for backwards compatibility 23 - nixops-gcp = nixops-gce; 24 - nixops-virtd = nixops-libvirtd; 25 - nixopsvbox = nixops-vbox; 98 + package = lib.lazyDerivation { outputs = [ "out" "dist" ]; derivation = this.rawPackage; } // this.extraPackageAttrs; 99 + 100 + public = this.package; 26 101 }; 27 102 28 - # selector is a function mapping pythonPackages to a list of plugins 29 - # e.g. nixops_unstable.withPlugins (ps: with ps; [ nixops-aws ]) 30 - withPlugins = selector: let 31 - selected = selector (plugins python.pkgs); 32 - in python.pkgs.toPythonApplication (python.pkgs.nixops.overridePythonAttrs (old: { 33 - propagatedBuildInputs = old.propagatedBuildInputs ++ selected; 103 + minimal = encapsulate nixopsContextBase; 34 104 35 - # Propagating dependencies leaks them through $PYTHONPATH which causes issues 36 - # when used in nix-shell. 37 - postFixup = '' 38 - rm $out/nix-support/propagated-build-inputs 39 - ''; 105 + in 106 + { 107 + nixops_unstable_minimal = minimal; 40 108 41 - passthru = old.passthru // { 42 - plugins = plugins python.pkgs; 43 - inherit withPlugins python; 44 - }; 45 - })); 46 - in withPlugins (ps: [ 47 - ps.nixops-aws 48 - ps.nixops-digitalocean 49 - ps.nixops-encrypted-links 50 - ps.nixops-gce 51 - ps.nixops-hercules-ci 52 - ps.nixops-hetzner 53 - ps.nixops-hetznercloud 54 - ps.nixops-libvirtd 55 - ps.nixops-vbox 56 - ]) 109 + # Not recommended; too fragile. 110 + nixops_unstable_full = minimal.withPlugins (ps: [ 111 + ps.nixops-aws 112 + ps.nixops-digitalocean 113 + ps.nixops-encrypted-links 114 + ps.nixops-gce 115 + ps.nixops-hercules-ci 116 + ps.nixops-hetzner 117 + ps.nixops-hetznercloud 118 + ps.nixops-libvirtd 119 + ps.nixops-vbox 120 + ]); 121 + }
+3 -3
pkgs/applications/networking/cluster/nixops/plugins/nixops-aws.nix
··· 12 12 13 13 buildPythonPackage { 14 14 pname = "nixops-aws"; 15 - version = "unstable-2023-08-09"; 15 + version = "unstable-2024-02-29"; 16 16 pyproject = true; 17 17 18 18 src = fetchFromGitHub { 19 19 owner = "NixOS"; 20 20 repo = "nixops-aws"; 21 - rev = "8802d1cda9004ec1362815292c2a8ab95e6d64e8"; 22 - hash = "sha256-i0KjFrwpDHRch9jorccdVwnjAQiORClDUqm2R2xvwuU="; 21 + rev = "d173b2f14ec767d782ceab45fb22b32fe3b5a1f7"; 22 + hash = "sha256-ocTtc7POt1bugb9Bki2ew2Eh5uc933GftNw1twoOJsc="; 23 23 }; 24 24 25 25 postPatch = ''
+4 -4
pkgs/applications/networking/cluster/nixops/unwrapped.nix
··· 13 13 14 14 buildPythonApplication rec { 15 15 pname = "nixops"; 16 - version = "unstable-2023-12-17"; 16 + version = "unstable-2024-02-28"; 17 17 pyproject = true; 18 18 19 19 src = fetchFromGitHub { 20 20 owner = "NixOS"; 21 21 repo = "nixops"; 22 - rev = "053668e849bb369973cf265b7e8f38e66ef70138"; 23 - hash = "sha256-Kus1Ls1tT8fVGLX0NakRXmjuz5/J/tfqU4TLOkiZqvo="; 22 + rev = "08feccb14074c5434f3e483d19a7f7d9bfcdb669"; 23 + hash = "sha256-yWeF5apQJdChjYVSOyH6LYjJYGa1RL68LRHrSgZ9l8U="; 24 24 }; 25 25 26 26 postPatch = '' ··· 50 50 pythonImportsCheck = [ "nixops" ]; 51 51 52 52 passthru = { 53 - tests.nixops = nixosTests.nixops.unstable; 53 + tests.nixos = nixosTests.nixops.unstable; 54 54 updateScript = unstableGitUpdater {}; 55 55 }; 56 56
+5 -1
pkgs/top-level/aliases.nix
··· 782 782 nix_2_4 = nixVersions.nix_2_4; 783 783 nix_2_5 = nixVersions.nix_2_5; 784 784 nix_2_6 = nixVersions.nix_2_6; 785 - nixops = throw "'nixops' has been removed. Please use 'nixops_unstable' for the time being."; # Added 2023-10-26 785 + 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 786 786 nixopsUnstable = nixops_unstable; # Added 2022-03-03 787 + 788 + # When the nixops_unstable alias is removed, nixops_unstable_minimal can be renamed to nixops_unstable. 789 + 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 790 + 787 791 nixosTest = testers.nixosTest; # Added 2022-05-05 788 792 nmap-unfree = nmap; # Added 2021-04-06 789 793 nodejs_14 = throw "nodejs_14 has been removed as it is EOL."; # Added 2023-10-30
+8 -1
pkgs/top-level/all-packages.nix
··· 40203 40203 40204 40204 nixStatic = pkgsStatic.nix; 40205 40205 40206 - nixops_unstable = callPackage ../applications/networking/cluster/nixops { }; 40206 + inherit (callPackages ../applications/networking/cluster/nixops { }) 40207 + nixops_unstable_minimal 40208 + 40209 + # Not recommended; too fragile 40210 + nixops_unstable_full; 40211 + 40212 + # Useful with ofborg, e.g. commit prefix `nixops_unstablePlugins.nixops-aws: ...` to trigger automatically. 40213 + nixops_unstablePlugins = recurseIntoAttrs nixops_unstable_minimal.availablePlugins; 40207 40214 40208 40215 /* 40209 40216 Evaluate a NixOS configuration using this evaluation of Nixpkgs.