aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Bantyev2021-06-23 22:45:59 +0300
committerGitHub2021-06-23 22:45:59 +0300
commit0964acc95051bd2b2d3ea0c9ab691e7be6eda7c0 (patch)
treece3b0e80de62230f95382679b7b594bb8c307145
parent0fc8dea27a70f07e0dec37037603bb24bcba64ba (diff)
parent6424e7519f450f962ccdcc60bf652c00393bd6d6 (diff)
Merge pull request #95 from serokell/balsoft/refactor-as-overlay
flake.nix: refactor as overlay
-rw-r--r--flake.nix94
1 files changed, 54 insertions, 40 deletions
diff --git a/flake.nix b/flake.nix
index d985db3..80b5568 100644
--- a/flake.nix
+++ b/flake.nix
@@ -20,38 +20,25 @@
};
outputs = { self, nixpkgs, utils, naersk, ... }:
- utils.lib.eachDefaultSystem (system:
- let
- pkgs = import nixpkgs { inherit system; };
- naersk-lib = pkgs.callPackage naersk { };
- isDarwin = pkgs.lib.strings.hasSuffix "-darwin" system;
- darwinOptions = pkgs.lib.optionalAttrs isDarwin {
- nativeBuildInputs = [
- pkgs.darwin.apple_sdk.frameworks.SystemConfiguration
- ];
- };
- in
- {
- defaultPackage = self.packages."${system}".deploy-rs;
- packages.deploy-rs = naersk-lib.buildPackage (darwinOptions // {
+ {
+ overlay = final: prev:
+ let
+ naersk-lib = final.callPackage naersk { };
+ system = final.system;
+ isDarwin = final.lib.strings.hasSuffix "-darwin" system;
+ darwinOptions = final.lib.optionalAttrs isDarwin {
+ nativeBuildInputs = [
+ final.darwin.apple_sdk.frameworks.SystemConfiguration
+ ];
+ };
+ in
+ {
+ deploy-rs = {
+
+ deploy-rs = naersk-lib.buildPackage (darwinOptions // {
root = ./.;
});
- defaultApp = self.apps."${system}".deploy-rs;
- apps.deploy-rs = {
- type = "app";
- program = "${self.defaultPackage."${system}"}/bin/deploy";
- };
-
- devShell = pkgs.mkShell {
- inputsFrom = [ self.packages.${system}.deploy-rs ];
- buildInputs = [ pkgs.nixUnstable ];
- };
-
- checks = {
- deploy-rs = self.defaultPackage.${system}.overrideAttrs (super: { doCheck = true; });
- };
-
lib = rec {
setActivate = builtins.trace
@@ -62,20 +49,20 @@
custom =
{
__functor = customSelf: base: activate:
- pkgs.buildEnv {
+ final.buildEnv {
name = ("activatable-" + base.name);
paths =
[
base
- (pkgs.writeTextFile {
+ (final.writeTextFile {
name = base.name + "-activate-path";
text = ''
- #!${pkgs.runtimeShell}
+ #!${final.runtimeShell}
set -euo pipefail
if [[ "''${DRY_ACTIVATE:-}" == "1" ]]
then
- ${customSelf.dryActivate or "echo ${pkgs.writeScript "activate" activate}"}
+ ${customSelf.dryActivate or "echo ${final.writeScript "activate" activate}"}
else
${activate}
fi
@@ -83,10 +70,10 @@
executable = true;
destination = "/deploy-rs-activate";
})
- (pkgs.writeTextFile {
+ (final.writeTextFile {
name = base.name + "-activate-rs";
text = ''
- #!${pkgs.runtimeShell}
+ #!${final.runtimeShell}
exec ${self.defaultPackage.${system}}/bin/activate "$@"
'';
executable = true;
@@ -104,7 +91,7 @@
# https://github.com/serokell/deploy-rs/issues/31
${with base.config.boot.loader;
- pkgs.lib.optionalString systemd-boot.enable
+ final.lib.optionalString systemd-boot.enable
"sed -i '/^default /d' ${efi.efiSysMountPoint}/loader/loader.conf"}
'';
@@ -114,15 +101,15 @@
};
deployChecks = deploy: builtins.mapAttrs (_: check: check deploy) {
- schema = deploy: pkgs.runCommandNoCC "jsonschema-deploy-system" { } ''
- ${pkgs.python3.pkgs.jsonschema}/bin/jsonschema -i ${pkgs.writeText "deploy.json" (builtins.toJSON deploy)} ${./interface.json} && touch $out
+ schema = deploy: final.runCommandNoCC "jsonschema-deploy-system" { } ''
+ ${final.python3.pkgs.jsonschema}/bin/jsonschema -i ${final.writeText "deploy.json" (builtins.toJSON deploy)} ${./interface.json} && touch $out
'';
activate = deploy:
let
- profiles = builtins.concatLists (pkgs.lib.mapAttrsToList (nodeName: node: pkgs.lib.mapAttrsToList (profileName: profile: [ (toString profile.path) nodeName profileName ]) node.profiles) deploy.nodes);
+ profiles = builtins.concatLists (final.lib.mapAttrsToList (nodeName: node: final.lib.mapAttrsToList (profileName: profile: [ (toString profile.path) nodeName profileName ]) node.profiles) deploy.nodes);
in
- pkgs.runCommandNoCC "deploy-rs-check-activate" { } ''
+ final.runCommandNoCC "deploy-rs-check-activate" { } ''
for x in ${builtins.concatStringsSep " " (map (p: builtins.concatStringsSep ":" p) profiles)}; do
profile_path=$(echo $x | cut -f1 -d:)
node_name=$(echo $x | cut -f2 -d:)
@@ -137,5 +124,32 @@
'';
};
};
+ };
+ };
+ } //
+ utils.lib.eachDefaultSystem (system:
+ let
+ pkgs = import nixpkgs { inherit system; overlays = [ self.overlay ]; };
+ in
+ {
+ defaultPackage = self.packages."${system}".deploy-rs;
+ packages.deploy-rs = pkgs.deploy-rs.deploy-rs;
+
+ defaultApp = self.apps."${system}".deploy-rs;
+ apps.deploy-rs = {
+ type = "app";
+ program = "${self.defaultPackage."${system}"}/bin/deploy";
+ };
+
+ devShell = pkgs.mkShell {
+ inputsFrom = [ self.packages.${system}.deploy-rs ];
+ buildInputs = [ pkgs.nixUnstable ];
+ };
+
+ checks = {
+ deploy-rs = self.defaultPackage.${system}.overrideAttrs (super: { doCheck = true; });
+ };
+
+ lib = pkgs.deploy-rs.lib;
});
}