Skip to content

Commit 0964acc

Browse files
authored
Merge pull request #95 from serokell/balsoft/refactor-as-overlay
flake.nix: refactor as overlay
2 parents 0fc8dea + 6424e75 commit 0964acc

File tree

1 file changed

+54
-40
lines changed

1 file changed

+54
-40
lines changed

flake.nix

Lines changed: 54 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -20,38 +20,25 @@
2020
};
2121

2222
outputs = { self, nixpkgs, utils, naersk, ... }:
23-
utils.lib.eachDefaultSystem (system:
24-
let
25-
pkgs = import nixpkgs { inherit system; };
26-
naersk-lib = pkgs.callPackage naersk { };
27-
isDarwin = pkgs.lib.strings.hasSuffix "-darwin" system;
28-
darwinOptions = pkgs.lib.optionalAttrs isDarwin {
29-
nativeBuildInputs = [
30-
pkgs.darwin.apple_sdk.frameworks.SystemConfiguration
31-
];
32-
};
33-
in
34-
{
35-
defaultPackage = self.packages."${system}".deploy-rs;
36-
packages.deploy-rs = naersk-lib.buildPackage (darwinOptions // {
23+
{
24+
overlay = final: prev:
25+
let
26+
naersk-lib = final.callPackage naersk { };
27+
system = final.system;
28+
isDarwin = final.lib.strings.hasSuffix "-darwin" system;
29+
darwinOptions = final.lib.optionalAttrs isDarwin {
30+
nativeBuildInputs = [
31+
final.darwin.apple_sdk.frameworks.SystemConfiguration
32+
];
33+
};
34+
in
35+
{
36+
deploy-rs = {
37+
38+
deploy-rs = naersk-lib.buildPackage (darwinOptions // {
3739
root = ./.;
3840
});
3941

40-
defaultApp = self.apps."${system}".deploy-rs;
41-
apps.deploy-rs = {
42-
type = "app";
43-
program = "${self.defaultPackage."${system}"}/bin/deploy";
44-
};
45-
46-
devShell = pkgs.mkShell {
47-
inputsFrom = [ self.packages.${system}.deploy-rs ];
48-
buildInputs = [ pkgs.nixUnstable ];
49-
};
50-
51-
checks = {
52-
deploy-rs = self.defaultPackage.${system}.overrideAttrs (super: { doCheck = true; });
53-
};
54-
5542
lib = rec {
5643

5744
setActivate = builtins.trace
@@ -62,31 +49,31 @@
6249
custom =
6350
{
6451
__functor = customSelf: base: activate:
65-
pkgs.buildEnv {
52+
final.buildEnv {
6653
name = ("activatable-" + base.name);
6754
paths =
6855
[
6956
base
70-
(pkgs.writeTextFile {
57+
(final.writeTextFile {
7158
name = base.name + "-activate-path";
7259
text = ''
73-
#!${pkgs.runtimeShell}
60+
#!${final.runtimeShell}
7461
set -euo pipefail
7562
7663
if [[ "''${DRY_ACTIVATE:-}" == "1" ]]
7764
then
78-
${customSelf.dryActivate or "echo ${pkgs.writeScript "activate" activate}"}
65+
${customSelf.dryActivate or "echo ${final.writeScript "activate" activate}"}
7966
else
8067
${activate}
8168
fi
8269
'';
8370
executable = true;
8471
destination = "/deploy-rs-activate";
8572
})
86-
(pkgs.writeTextFile {
73+
(final.writeTextFile {
8774
name = base.name + "-activate-rs";
8875
text = ''
89-
#!${pkgs.runtimeShell}
76+
#!${final.runtimeShell}
9077
exec ${self.defaultPackage.${system}}/bin/activate "$@"
9178
'';
9279
executable = true;
@@ -104,7 +91,7 @@
10491
10592
# https://github.com/serokell/deploy-rs/issues/31
10693
${with base.config.boot.loader;
107-
pkgs.lib.optionalString systemd-boot.enable
94+
final.lib.optionalString systemd-boot.enable
10895
"sed -i '/^default /d' ${efi.efiSysMountPoint}/loader/loader.conf"}
10996
'';
11097

@@ -114,15 +101,15 @@
114101
};
115102

116103
deployChecks = deploy: builtins.mapAttrs (_: check: check deploy) {
117-
schema = deploy: pkgs.runCommandNoCC "jsonschema-deploy-system" { } ''
118-
${pkgs.python3.pkgs.jsonschema}/bin/jsonschema -i ${pkgs.writeText "deploy.json" (builtins.toJSON deploy)} ${./interface.json} && touch $out
104+
schema = deploy: final.runCommandNoCC "jsonschema-deploy-system" { } ''
105+
${final.python3.pkgs.jsonschema}/bin/jsonschema -i ${final.writeText "deploy.json" (builtins.toJSON deploy)} ${./interface.json} && touch $out
119106
'';
120107

121108
activate = deploy:
122109
let
123-
profiles = builtins.concatLists (pkgs.lib.mapAttrsToList (nodeName: node: pkgs.lib.mapAttrsToList (profileName: profile: [ (toString profile.path) nodeName profileName ]) node.profiles) deploy.nodes);
110+
profiles = builtins.concatLists (final.lib.mapAttrsToList (nodeName: node: final.lib.mapAttrsToList (profileName: profile: [ (toString profile.path) nodeName profileName ]) node.profiles) deploy.nodes);
124111
in
125-
pkgs.runCommandNoCC "deploy-rs-check-activate" { } ''
112+
final.runCommandNoCC "deploy-rs-check-activate" { } ''
126113
for x in ${builtins.concatStringsSep " " (map (p: builtins.concatStringsSep ":" p) profiles)}; do
127114
profile_path=$(echo $x | cut -f1 -d:)
128115
node_name=$(echo $x | cut -f2 -d:)
@@ -137,5 +124,32 @@
137124
'';
138125
};
139126
};
127+
};
128+
};
129+
} //
130+
utils.lib.eachDefaultSystem (system:
131+
let
132+
pkgs = import nixpkgs { inherit system; overlays = [ self.overlay ]; };
133+
in
134+
{
135+
defaultPackage = self.packages."${system}".deploy-rs;
136+
packages.deploy-rs = pkgs.deploy-rs.deploy-rs;
137+
138+
defaultApp = self.apps."${system}".deploy-rs;
139+
apps.deploy-rs = {
140+
type = "app";
141+
program = "${self.defaultPackage."${system}"}/bin/deploy";
142+
};
143+
144+
devShell = pkgs.mkShell {
145+
inputsFrom = [ self.packages.${system}.deploy-rs ];
146+
buildInputs = [ pkgs.nixUnstable ];
147+
};
148+
149+
checks = {
150+
deploy-rs = self.defaultPackage.${system}.overrideAttrs (super: { doCheck = true; });
151+
};
152+
153+
lib = pkgs.deploy-rs.lib;
140154
});
141155
}

0 commit comments

Comments
 (0)