|
16 | 16 | fenix.url = "github:nix-community/fenix";
|
17 | 17 | };
|
18 | 18 |
|
19 |
| - outputs = { self, nixpkgs, utils, fenix, ... }: let |
20 |
| - toolchain = "stable"; |
21 |
| - in |
22 |
| - { |
23 |
| - overlay = final: prev: |
24 |
| - let |
25 |
| - system = final.system; |
26 |
| - darwinOptions = final.lib.optionalAttrs final.stdenv.isDarwin { |
27 |
| - buildInputs = with final.darwin.apple_sdk.frameworks; [ |
28 |
| - SystemConfiguration |
29 |
| - CoreServices |
30 |
| - ]; |
31 |
| - }; |
32 |
| - in |
33 |
| - { |
34 |
| - deploy-rs = { |
35 |
| - |
36 |
| - deploy-rs = (final.makeRustPlatform { |
37 |
| - inherit (final.fenix.${toolchain}) cargo rustc; |
38 |
| - }).buildRustPackage (darwinOptions // { |
39 |
| - pname = "deploy-rs"; |
40 |
| - version = "0.1.0"; |
41 |
| - |
42 |
| - src = nixpkgs.lib.cleanSource ./.; |
43 |
| - |
44 |
| - cargoLock.lockFile = ./Cargo.lock; |
45 |
| - }) // { meta.description = "A Simple multi-profile Nix-flake deploy tool"; }; |
46 |
| - |
47 |
| - lib = rec { |
48 |
| - |
49 |
| - setActivate = builtins.trace |
50 |
| - "deploy-rs#lib.setActivate is deprecated, use activate.noop, activate.nixos or activate.custom instead" |
51 |
| - activate.custom; |
52 |
| - |
53 |
| - activate = rec { |
54 |
| - custom = |
55 |
| - { |
56 |
| - __functor = customSelf: base: activate: |
57 |
| - (final.buildEnv { |
58 |
| - name = ("activatable-" + base.name); |
59 |
| - paths = |
60 |
| - [ |
| 19 | + outputs = { self, nixpkgs, utils, fenix, ... }: |
| 20 | + let toolchain = "stable"; |
| 21 | + in { |
| 22 | + overlay = final: prev: |
| 23 | + let |
| 24 | + system = final.system; |
| 25 | + darwinOptions = final.lib.optionalAttrs final.stdenv.isDarwin { |
| 26 | + buildInputs = with final.darwin.apple_sdk.frameworks; [ |
| 27 | + SystemConfiguration |
| 28 | + CoreServices |
| 29 | + ]; |
| 30 | + }; |
| 31 | + in { |
| 32 | + deploy-rs = { |
| 33 | + |
| 34 | + deploy-rs = (final.makeRustPlatform { |
| 35 | + inherit (final.fenix.${toolchain}) cargo rustc; |
| 36 | + }).buildRustPackage (darwinOptions // { |
| 37 | + pname = "deploy-rs"; |
| 38 | + version = "0.1.0"; |
| 39 | + |
| 40 | + src = nixpkgs.lib.cleanSource ./.; |
| 41 | + |
| 42 | + cargoLock.lockFile = ./Cargo.lock; |
| 43 | + }) // { |
| 44 | + meta.description = "A Simple multi-profile Nix-flake deploy tool"; |
| 45 | + }; |
| 46 | + |
| 47 | + lib = rec { |
| 48 | + |
| 49 | + setActivate = builtins.trace |
| 50 | + "deploy-rs#lib.setActivate is deprecated, use activate.noop, activate.nixos or activate.custom instead" |
| 51 | + activate.custom; |
| 52 | + |
| 53 | + activate = rec { |
| 54 | + custom = { |
| 55 | + __functor = customSelf: base: activate: |
| 56 | + (final.buildEnv { |
| 57 | + name = ("activatable-" + base.name); |
| 58 | + paths = [ |
61 | 59 | base
|
62 | 60 | (final.writeTextFile {
|
63 | 61 | name = base.name + "-activate-path";
|
|
67 | 65 |
|
68 | 66 | if [[ "''${DRY_ACTIVATE:-}" == "1" ]]
|
69 | 67 | then
|
70 |
| - ${customSelf.dryActivate or "echo ${final.writeScript "activate" activate}"} |
| 68 | + ${ |
| 69 | + customSelf.dryActivate or "echo ${ |
| 70 | + final.writeScript "activate" activate |
| 71 | + }" |
| 72 | + } |
71 | 73 | else
|
72 | 74 | ${activate}
|
73 | 75 | fi
|
|
79 | 81 | name = base.name + "-activate-rs";
|
80 | 82 | text = ''
|
81 | 83 | #!${final.runtimeShell}
|
82 |
| - exec ${self.defaultPackage.${system}}/bin/activate "$@" |
| 84 | + exec ${ |
| 85 | + self.defaultPackage.${system} |
| 86 | + }/bin/activate "$@" |
83 | 87 | '';
|
84 | 88 | executable = true;
|
85 | 89 | destination = "/activate-rs";
|
|
88 | 92 | } // customSelf);
|
89 | 93 | };
|
90 | 94 |
|
91 |
| - nixos = base: (custom // { inherit base; dryActivate = "$PROFILE/bin/switch-to-configuration dry-activate"; }) base.config.system.build.toplevel '' |
92 |
| - # work around https://github.com/NixOS/nixpkgs/issues/73404 |
93 |
| - cd /tmp |
94 |
| -
|
95 |
| - $PROFILE/bin/switch-to-configuration switch |
96 |
| -
|
97 |
| - # https://github.com/serokell/deploy-rs/issues/31 |
98 |
| - ${with base.config.boot.loader; |
99 |
| - final.lib.optionalString systemd-boot.enable |
100 |
| - "sed -i '/^default /d' ${efi.efiSysMountPoint}/loader/loader.conf"} |
101 |
| - ''; |
102 |
| - |
103 |
| - home-manager = base: custom base.activationPackage "$PROFILE/activate"; |
104 |
| - |
105 |
| - noop = base: custom base ":"; |
106 |
| - }; |
107 |
| - |
108 |
| - deployChecks = deploy: builtins.mapAttrs (_: check: check deploy) { |
109 |
| - schema = deploy: final.runCommandNoCC "jsonschema-deploy-system" { } '' |
110 |
| - ${final.python3.pkgs.jsonschema}/bin/jsonschema -i ${final.writeText "deploy.json" (builtins.toJSON deploy)} ${self}/interface.json && touch $out |
111 |
| - ''; |
112 |
| - |
113 |
| - activate = deploy: |
114 |
| - let |
115 |
| - profiles = builtins.concatLists (final.lib.mapAttrsToList (nodeName: node: final.lib.mapAttrsToList (profileName: profile: [ (toString profile.path) nodeName profileName ]) node.profiles) deploy.nodes); |
116 |
| - in |
117 |
| - final.runCommandNoCC "deploy-rs-check-activate" { } '' |
118 |
| - for x in ${builtins.concatStringsSep " " (map (p: builtins.concatStringsSep ":" p) profiles)}; do |
119 |
| - profile_path=$(echo $x | cut -f1 -d:) |
120 |
| - node_name=$(echo $x | cut -f2 -d:) |
121 |
| - profile_name=$(echo $x | cut -f3 -d:) |
122 |
| -
|
123 |
| - test -f "$profile_path/deploy-rs-activate" || (echo "#$node_name.$profile_name is missing the deploy-rs-activate activation script" && exit 1); |
124 |
| -
|
125 |
| - test -f "$profile_path/activate-rs" || (echo "#$node_name.$profile_name is missing the activate-rs activation script" && exit 1); |
126 |
| - done |
127 |
| -
|
128 |
| - touch $out |
129 |
| - ''; |
| 95 | + nixos = base: |
| 96 | + (custom // { |
| 97 | + inherit base; |
| 98 | + dryActivate = |
| 99 | + "$PROFILE/bin/switch-to-configuration dry-activate"; |
| 100 | + }) base.config.system.build.toplevel '' |
| 101 | + # work around https://github.com/NixOS/nixpkgs/issues/73404 |
| 102 | + cd /tmp |
| 103 | +
|
| 104 | + $PROFILE/bin/switch-to-configuration switch |
| 105 | +
|
| 106 | + # https://github.com/serokell/deploy-rs/issues/31 |
| 107 | + ${with base.config.boot.loader; |
| 108 | + final.lib.optionalString systemd-boot.enable |
| 109 | + "sed -i '/^default /d' ${efi.efiSysMountPoint}/loader/loader.conf"} |
| 110 | + ''; |
| 111 | + |
| 112 | + home-manager = base: |
| 113 | + custom base.activationPackage "$PROFILE/activate"; |
| 114 | + |
| 115 | + noop = base: custom base ":"; |
| 116 | + }; |
| 117 | + |
| 118 | + deployChecks = deploy: |
| 119 | + builtins.mapAttrs (_: check: check deploy) { |
| 120 | + schema = deploy: |
| 121 | + final.runCommandNoCC "jsonschema-deploy-system" { } '' |
| 122 | + ${final.python3.pkgs.jsonschema}/bin/jsonschema -i ${ |
| 123 | + final.writeText "deploy.json" (builtins.toJSON deploy) |
| 124 | + } ${self}/interface.json && touch $out |
| 125 | + ''; |
| 126 | + |
| 127 | + activate = deploy: |
| 128 | + let |
| 129 | + profiles = builtins.concatLists (final.lib.mapAttrsToList |
| 130 | + (nodeName: node: |
| 131 | + final.lib.mapAttrsToList (profileName: profile: [ |
| 132 | + (toString profile.path) |
| 133 | + nodeName |
| 134 | + profileName |
| 135 | + ]) node.profiles) deploy.nodes); |
| 136 | + in final.runCommandNoCC "deploy-rs-check-activate" { } '' |
| 137 | + for x in ${ |
| 138 | + builtins.concatStringsSep " " |
| 139 | + (map (p: builtins.concatStringsSep ":" p) profiles) |
| 140 | + }; do |
| 141 | + profile_path=$(echo $x | cut -f1 -d:) |
| 142 | + node_name=$(echo $x | cut -f2 -d:) |
| 143 | + profile_name=$(echo $x | cut -f3 -d:) |
| 144 | +
|
| 145 | + test -f "$profile_path/deploy-rs-activate" || (echo "#$node_name.$profile_name is missing the deploy-rs-activate activation script" && exit 1); |
| 146 | +
|
| 147 | + test -f "$profile_path/activate-rs" || (echo "#$node_name.$profile_name is missing the activate-rs activation script" && exit 1); |
| 148 | + done |
| 149 | +
|
| 150 | + touch $out |
| 151 | + ''; |
| 152 | + }; |
130 | 153 | };
|
131 | 154 | };
|
132 | 155 | };
|
133 |
| - }; |
134 |
| - } // |
135 |
| - utils.lib.eachSystem (utils.lib.defaultSystems ++ ["aarch64-darwin"]) (system: |
| 156 | + } // utils.lib.eachSystem (utils.lib.defaultSystems ++ [ "aarch64-darwin" ]) |
| 157 | + (system: |
136 | 158 | let
|
137 |
| - pkgs = import nixpkgs { inherit system; overlays = [ self.overlay fenix.overlay ]; }; |
| 159 | + pkgs = import nixpkgs { |
| 160 | + inherit system; |
| 161 | + overlays = [ self.overlay fenix.overlay ]; |
| 162 | + }; |
138 | 163 | rustPkg = pkgs.fenix.${toolchain}.withComponents [
|
139 | 164 | "cargo"
|
140 | 165 | "clippy"
|
|
154 | 179 |
|
155 | 180 | devShell = pkgs.mkShell {
|
156 | 181 | RUST_SRC_PATH = "${rustPkg}/lib/rustlib/src/rust/library";
|
157 |
| - buildInputs = with pkgs; [ |
158 |
| - rust-analyzer-nightly |
159 |
| - reuse |
160 |
| - rustPkg |
161 |
| - ]; |
| 182 | + buildInputs = with pkgs; [ rust-analyzer-nightly reuse rustPkg ]; |
162 | 183 | };
|
163 | 184 |
|
164 | 185 | checks = {
|
165 |
| - deploy-rs = self.defaultPackage.${system}.overrideAttrs (super: { doCheck = true; }); |
| 186 | + deploy-rs = self.defaultPackage.${system}.overrideAttrs |
| 187 | + (super: { doCheck = true; }); |
166 | 188 | };
|
167 | 189 |
|
168 | 190 | lib = pkgs.deploy-rs.lib;
|
|
0 commit comments