From b68e324c4c86e6f03f60c126d4ebc84c04f08915 Mon Sep 17 00:00:00 2001 From: hexchen Date: Sun, 10 Jan 2021 23:56:49 +0000 Subject: [PATCH] restructure: remove redundant file --- lib/deploy.nix | 76 -------------------------------------------------- 1 file changed, 76 deletions(-) delete mode 100644 lib/deploy.nix diff --git a/lib/deploy.nix b/lib/deploy.nix deleted file mode 100644 index aa730eb..0000000 --- a/lib/deploy.nix +++ /dev/null @@ -1,76 +0,0 @@ -let - pkgs = import {}; - lib = pkgs.lib; - - hosts = import ../configuration/hosts; - nixosHosts = lib.filterAttrs (name: host: host ? ssh) hosts; - - allGroups = lib.unique ( - lib.flatten ( - lib.mapAttrsToList ( - name: host: host.groups - ) hosts - ) - ); - - hostsInGroup = group: - lib.filterAttrs ( - k: v: builtins.elem group v.groups - ) hosts; - - hostsInAllGroups = lib.listToAttrs ( - map ( - group: lib.nameValuePair group ( - lib.attrNames (hostsInGroup group) - ) - ) allGroups ); - - mkDeploy = hostnames: pkgs.writeScript "deploy-${lib.concatStringsSep "-" hostnames}" '' - #!${pkgs.stdenv.shell} - set -e -o pipefail - export PATH=/run/wrappers/bin/:${with pkgs; lib.makeBinPath [ - coreutils - openssh - nix - gnutar - findutils - nettools - gzip - git - ]} - - MODE=$1 - shift || true - ARGS=$@ - - [ "$MODE" == "" ] && MODE="switch" - - ${lib.concatMapStrings (hostname: let - hostAttrs = nixosHosts.${hostname}; - nixosSystem = (import { - modules = [ - "${toString ../configuration}/hosts/${hostname}/configuration.nix" - ]; - system = if hostAttrs ? system then hostAttrs.system else "x86_64-linux"; - }).config.system.build.toplevel; - in '' - ( - echo "deploying ${hostname}..." - nix copy --no-check-sigs -s --to ssh://${hostAttrs.ssh.host} ${nixosSystem} - ssh $NIX_SSHOPTS ${hostAttrs.ssh.host} "sudo nix-env -p /nix/var/nix/profiles/system -i ${nixosSystem}" - ssh $NIX_SSHOPTS ${hostAttrs.ssh.host} "sudo /nix/var/nix/profiles/system/bin/switch-to-configuration $MODE $ARGS" - ) & - PID_LIST+=" $!" - '') hostnames} - - echo "deploys started, waiting for them to finish..." - - trap "kill $PID_LIST" SIGINT - wait $PID_LIST - ''; - -in { - deploy = (lib.mapAttrs (hostname: hostAttrs: mkDeploy [ hostname ]) nixosHosts) - // (lib.mapAttrs (group: hosts: mkDeploy hosts) hostsInAllGroups) - // { all = mkDeploy (lib.attrNames nixosHosts); }; -}