diff options
author | Alexander Bantyev | 2021-06-22 00:46:08 +0300 |
---|---|---|
committer | Alexander Bantyev | 2021-06-22 00:46:08 +0300 |
commit | 6424e7519f450f962ccdcc60bf652c00393bd6d6 (patch) | |
tree | b4cbdec7b2243a7f7f8d23de3063dcf56fb52bd3 | |
parent | 70d71b3027b1793b780f1e2435bdbbe1b0cb9ac6 (diff) |
flake.nix: refactor as overlay
-rw-r--r-- | flake.nix | 94 |
1 files changed, 54 insertions, 40 deletions
@@ -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; }); } |