Skip to content

Commit 1c60c23

Browse files
committed
nix: ran nixfmt across flake.nix
1 parent 7267eab commit 1c60c23

File tree

1 file changed

+115
-93
lines changed

1 file changed

+115
-93
lines changed

flake.nix

+115-93
Original file line numberDiff line numberDiff line change
@@ -16,48 +16,46 @@
1616
fenix.url = "github:nix-community/fenix";
1717
};
1818

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 = [
6159
base
6260
(final.writeTextFile {
6361
name = base.name + "-activate-path";
@@ -67,7 +65,11 @@
6765
6866
if [[ "''${DRY_ACTIVATE:-}" == "1" ]]
6967
then
70-
${customSelf.dryActivate or "echo ${final.writeScript "activate" activate}"}
68+
${
69+
customSelf.dryActivate or "echo ${
70+
final.writeScript "activate" activate
71+
}"
72+
}
7173
else
7274
${activate}
7375
fi
@@ -79,7 +81,9 @@
7981
name = base.name + "-activate-rs";
8082
text = ''
8183
#!${final.runtimeShell}
82-
exec ${self.defaultPackage.${system}}/bin/activate "$@"
84+
exec ${
85+
self.defaultPackage.${system}
86+
}/bin/activate "$@"
8387
'';
8488
executable = true;
8589
destination = "/activate-rs";
@@ -88,53 +92,74 @@
8892
} // customSelf);
8993
};
9094

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+
};
130153
};
131154
};
132155
};
133-
};
134-
} //
135-
utils.lib.eachSystem (utils.lib.defaultSystems ++ ["aarch64-darwin"]) (system:
156+
} // utils.lib.eachSystem (utils.lib.defaultSystems ++ [ "aarch64-darwin" ])
157+
(system:
136158
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+
};
138163
rustPkg = pkgs.fenix.${toolchain}.withComponents [
139164
"cargo"
140165
"clippy"
@@ -154,15 +179,12 @@
154179

155180
devShell = pkgs.mkShell {
156181
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 ];
162183
};
163184

164185
checks = {
165-
deploy-rs = self.defaultPackage.${system}.overrideAttrs (super: { doCheck = true; });
186+
deploy-rs = self.defaultPackage.${system}.overrideAttrs
187+
(super: { doCheck = true; });
166188
};
167189

168190
lib = pkgs.deploy-rs.lib;

0 commit comments

Comments
 (0)