nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at devShellTools-shell 164 lines 5.1 kB view raw
1{ 2 lib, 3 config, 4 python3, 5 emptyFile, 6}: 7 8let 9 inherit (lib) extends; 10 11 # doc: https://github.com/NixOS/nixpkgs/pull/158781/files#diff-854251fa1fe071654921224671c8ba63c95feb2f96b2b3a9969c81676780053a 12 encapsulate = 13 layerZero: 14 let 15 fixed = layerZero ({ extend = f: encapsulate (extends f layerZero); } // fixed); 16 in 17 fixed.public; 18 19 nixopsContextBase = this: { 20 21 python = python3.override { 22 self = this.python; 23 packageOverrides = 24 self: super: 25 { 26 nixops = self.callPackage ./unwrapped.nix { }; 27 } 28 // (this.plugins self super); 29 }; 30 31 plugins = 32 ps: _super: 33 with ps; 34 ( 35 rec { 36 nixops-digitalocean = callPackage ./plugins/nixops-digitalocean.nix { }; 37 nixops-encrypted-links = callPackage ./plugins/nixops-encrypted-links.nix { }; 38 nixops-hercules-ci = callPackage ./plugins/nixops-hercules-ci.nix { }; 39 nixops-vbox = callPackage ./plugins/nixops-vbox.nix { }; 40 nixos-modules-contrib = callPackage ./plugins/nixos-modules-contrib.nix { }; 41 42 # aliases for backwards compatibility 43 nixopsvbox = nixops-vbox; 44 } 45 // lib.optionalAttrs config.allowAliases rec { 46 nixops-aws = throw "nixops-aws was broken and was removed from nixpkgs"; 47 nixops-gce = throw "nixops-gce was broken and was removed from nixpkgs"; 48 nixops-libvirtd = throw "nixops-libvirtd was broken and was removed from nixpkgs"; 49 nixops-hetzner = throw "nixops-hetzner was broken and was removed from nixpkgs"; 50 nixops-hetznercloud = throw "nixops-hetznercloud was broken and was removed from nixpkgs"; 51 nixops-virtd = nixops-libvirtd; 52 } 53 ); 54 55 # We should not reapply the overlay, but it tends to work out. (It's been this way since poetry2nix was dropped.) 56 availablePlugins = this.plugins this.python.pkgs this.python.pkgs; 57 58 selectedPlugins = [ ]; 59 60 # selector is a function mapping pythonPackages to a list of plugins 61 # e.g. nixops_unstable.withPlugins (ps: with ps; [ nixops-digitalocean ]) 62 withPlugins = 63 selector: 64 this.extend ( 65 this: _old: { 66 selectedPlugins = selector this.availablePlugins; 67 } 68 ); 69 70 rawPackage = this.python.pkgs.toPythonApplication ( 71 this.python.pkgs.nixops.overridePythonAttrs (old: { 72 propagatedBuildInputs = old.propagatedBuildInputs ++ this.selectedPlugins; 73 74 # Propagating dependencies leaks them through $PYTHONPATH which causes issues 75 # when used in nix-shell. 76 postFixup = '' 77 rm $out/nix-support/propagated-build-inputs 78 ''; 79 }) 80 ); 81 82 # Extra package attributes that aren't derivation attributes, just like `mkDerivation`'s `passthru`. 83 extraPackageAttrs = { 84 inherit (this) 85 selectedPlugins 86 availablePlugins 87 withPlugins 88 python 89 ; 90 tests = 91 this.rawPackage.tests 92 // { 93 nixos = this.rawPackage.tests.nixos.passthru.override { 94 nixopsPkg = this.rawPackage; 95 }; 96 commutative_addAvailablePlugins_withPlugins = 97 assert 98 (this.public.addAvailablePlugins (self: super: { inherit emptyFile; })).withPlugins (ps: [ 99 emptyFile 100 ]) == 101 # Note that this value proves that the package is not instantiated until the end, where it's valid again. 102 (this.public.withPlugins (ps: [ emptyFile ])).addAvailablePlugins ( 103 self: super: { inherit emptyFile; } 104 ); 105 emptyFile; 106 } 107 # Make sure we also test with a configuration that's been extended with a plugin. 108 // lib.optionalAttrs (this.selectedPlugins == [ ]) { 109 withAPlugin = 110 lib.recurseIntoAttrs 111 (this.withPlugins (ps: with ps; [ nixops-encrypted-links ])).tests; 112 }; 113 overrideAttrs = 114 f: 115 this.extend ( 116 this: oldThis: { 117 rawPackage = oldThis.rawPackage.overrideAttrs f; 118 } 119 ); 120 /** 121 nixops.addAvailablePlugins: Overlay -> Package 122 123 Add available plugins to the package. You probably also want to enable 124 them with the `withPlugins` method. 125 */ 126 addAvailablePlugins = 127 newPlugins: 128 this.extend ( 129 finalThis: oldThis: { 130 plugins = lib.composeExtensions oldThis.plugins newPlugins; 131 } 132 ); 133 134 # For those who need or dare. 135 internals = this; 136 }; 137 138 package = 139 lib.lazyDerivation { 140 outputs = [ 141 "out" 142 "dist" 143 ]; 144 derivation = this.rawPackage; 145 } 146 // this.extraPackageAttrs; 147 148 public = this.package; 149 }; 150 151 minimal = encapsulate nixopsContextBase; 152 153in 154{ 155 nixops_unstable_minimal = minimal; 156 157 # Not recommended; too fragile. 158 nixops_unstable_full = minimal.withPlugins (ps: [ 159 ps.nixops-digitalocean 160 ps.nixops-encrypted-links 161 ps.nixops-hercules-ci 162 ps.nixops-vbox 163 ]); 164}