Compare commits

..

2 commits

8 changed files with 36 additions and 68 deletions

View file

@ -3,7 +3,10 @@
"hello" "hello"
"cowsay" "cowsay"
]; ];
pathToRoot = ../../..; pathToRoot = builtins.path {
path = ../../..;
name = "root";
};
pathFromRoot = "/deployment/check/data-model-ssh"; pathFromRoot = "/deployment/check/data-model-ssh";
useFlake = true; useFlake = true;
} }

View file

@ -5,7 +5,10 @@
"peertube" "peertube"
"pixelfed" "pixelfed"
]; ];
pathToRoot = ../../..; pathToRoot = builtins.path {
path = ../../..;
name = "root";
};
pathFromRoot = "/deployment/check/data-model-ssh"; pathFromRoot = "/deployment/check/data-model-ssh";
enableAcme = true; enableAcme = true;
useFlake = true; useFlake = true;

View file

@ -7,10 +7,7 @@
}@args: }@args:
let let
# self = ./data-model.nix;
self = "deployment/check/common/data-model.nix"; self = "deployment/check/common/data-model.nix";
# args = { inherit config system inputs sources; };
# self args
inherit (sources) nixpkgs; inherit (sources) nixpkgs;
pkgs = import nixpkgs { inherit system; }; pkgs = import nixpkgs { inherit system; };
inherit (pkgs) lib; inherit (pkgs) lib;
@ -145,7 +142,6 @@ let
}; };
module = self; module = self;
inherit args deployment-name root-path; inherit args deployment-name root-path;
# deployment-name = "";
}; };
}; };
}; };

View file

@ -2,7 +2,10 @@
targetMachines = [ targetMachines = [
"nixops4" "nixops4"
]; ];
pathToRoot = ../../..; pathToRoot = builtins.path {
path = ../../..;
name = "root";
};
pathFromRoot = "/deployment/check/data-model-ssh"; pathFromRoot = "/deployment/check/data-model-ssh";
enableAcme = true; enableAcme = true;
useFlake = true; useFlake = true;

View file

@ -2,7 +2,11 @@
targetMachines = [ targetMachines = [
"ssh" "ssh"
]; ];
pathToRoot = ../../..; # stablize path, as just the path would yield distinct paths when applied multiple times
pathToRoot = builtins.path {
path = ../../..;
name = "root";
};
pathFromRoot = "/deployment/check/data-model-ssh"; pathFromRoot = "/deployment/check/data-model-ssh";
enableAcme = true; enableAcme = true;
} }

View file

@ -5,7 +5,10 @@
"peertube" "peertube"
"pixelfed" "pixelfed"
]; ];
pathToRoot = ../../..; pathToRoot = builtins.path {
path = ../../..;
name = "root";
};
pathFromRoot = "/deployment/check/data-model-ssh"; pathFromRoot = "/deployment/check/data-model-ssh";
enableAcme = true; enableAcme = true;
useFlake = true; useFlake = true;

View file

@ -92,12 +92,10 @@ let
type = types.path; type = types.path;
}; };
run = mkOption { run = mkOption {
# type = types.path;
type = types.str; type = types.str;
# readOnly = true; # readOnly = true;
default = default =
let let
# inherit (ssh-host.config) ssh nixos-configuration;
inherit (ssh-host.config) inherit (ssh-host.config)
ssh ssh
module module
@ -105,69 +103,37 @@ let
deployment-name deployment-name
root-path root-path
; ;
# inherit (ssh-host.config) ssh module args;
inherit (ssh) host username key-file; inherit (ssh) host username key-file;
# inherit (import ./nixos.nix {
# # inherit system;
# system = pkgs.system; # XXX recheck this is the right one
# configuration = nixos-configuration;
# # commandFn = outPath: '''';
# }) drv_path;
# command
environment = { environment = {
# inherit (ssh-host) host username key-file;
# inherit host username drv_path;
key_file = key-file; key_file = key-file;
deployment_name = deployment-name; deployment_name = deployment-name;
root_path = root-path; root_path = root-path;
system = pkgs.system; # XXX recheck this is the right one system = pkgs.system; # XXX recheck this is the right one
# config_nix = nixos-configuration;
# config_tf = {};
# inherit host username;
inherit inherit
host host
username username
module module
args args
# root_path
; ;
deployment_type = "ssh-host"; deployment_type = "ssh-host";
# module = ;
# args = ;
# deployment_name = ;
# deployment_type = ;
# root_path = builtins.toString ./..;
# root_path = ;
}; };
in in
# error: cannot coerce a function to a string: «lambda mkNixosConfiguration @ /nix/store/ifj5ykvb5hv05m9qcr4r1aah4s4f9pdi-source/deployment/check/common/data-model.nix:106:15» ''
# ''
# env ${toString (lib.mapAttrsToList (k: v: lib.trace (if k == "config_nix" then v {} else k) "${k}='${v}'") environment)} ${./run/ssh-single-host/run.sh}";
# '';
# ''
# env ${toString (lib.mapAttrsToList (k: v: lib.trace k "${k}=${lib.strings.toJSON v}") environment)} ${./run/ssh-single-host/run.sh}";
# '';
# if v == null then toString v else
# lib.traceVal
# ''
# env ${toString (lib.mapAttrsToList (k: v: lib.trace k "${k}='${v}'") (lib.filterAttrs (_: v: v != null) environment))} ${./run/ssh-single-host/run.sh}
# '';
lib.traceVal ''
env ${ env ${
toString ( toString (
lib.mapAttrsToList ( lib.mapAttrsToList (
k: v: k: v:
lib.trace k "${k}=\"${ "${k}=\"${
lib.replaceStrings [ "\"" ] [ "\\\\\"" ] ( lib.replaceStrings [ "\"" ] [ "\\\\\"" ] (
if lib.isAttrs v then if lib.isPath v || builtins.isNull v then
lib.strings.toJSON v
else if lib.isPath v then
toString v toString v
else else if lib.isString v then
v v
else
lib.strings.toJSON v
) )
}\"" }\""
) (lib.filterAttrs (_: v: v != null) environment) ) environment
) )
} bash ./deployment/run/ssh-single-host/run.sh } bash ./deployment/run/ssh-single-host/run.sh
''; '';

View file

@ -1,35 +1,26 @@
#! /usr/bin/env bash #! /usr/bin/env bash
set -xeuo pipefail set -xeuo pipefail
declare username host system module args deployment_name deployment_type args #key_file root_path declare username host system module args deployment_name deployment_type args key_file root_path
# DEPLOY # DEPLOY
sshOpts=( sshOpts=(
-o BatchMode=yes -o BatchMode=yes
-o StrictHostKeyChecking=no -o StrictHostKeyChecking=no
# TODO set key for production
# ${if key-file == null then "" else "-i ${key-file}"}
# NOTE the below options are for tests # NOTE the below options are for tests
-o ConnectTimeout=1 -o ConnectTimeout=1
-o ServerAliveInterval=1 -o ServerAliveInterval=1
) )
if [[ -n "$key_file" ]]; then
sshOpts+=(
-i "$key_file"
)
fi
destination="$username@$host" destination="$username@$host"
# echo "$cwd/deployment"
# ls "$cwd/deployment"
# echo "$args"
root=$(echo "$args" | jq -r '.config.pathToRoot')
# echo "$root/deployment/nixos.nix"
# ls "$root/deployment/nixos.nix"
# FIXME: ensure [[ $root_path == $root ]] so i could just rely on stuff from /deployment/data-model.nix
# cwd=$root_path
cwd=$root
command=(nix-instantiate --show-trace --expr " command=(nix-instantiate --show-trace --expr "
import $cwd/deployment/nixos.nix { import $root_path/deployment/nixos.nix {
system = \"$system\"; system = \"$system\";
configuration = (import \"$cwd/$module\" (builtins.fromJSON ''$args'')).$deployment_name.$deployment_type.nixos-configuration; configuration = (import \"$root_path/$module\" (builtins.fromJSON ''$args'')).$deployment_name.$deployment_type.nixos-configuration;
} }
") ")
@ -38,7 +29,6 @@ command=(nix-instantiate --show-trace --expr "
"${command[@]}" -A out_path "${command[@]}" -A out_path
# get the realized derivation to deploy # get the realized derivation to deploy
# "${command[@]}" --show-trace --eval --strict --json | jq -r '.command')"
outPath=$(nix-store --realize "$("${command[@]}" --show-trace --eval --strict --json | jq -r '.drv_path')") outPath=$(nix-store --realize "$("${command[@]}" --show-trace --eval --strict --json | jq -r '.drv_path')")
# deploy the config by nix-copy-closure # deploy the config by nix-copy-closure
NIX_SSHOPTS="${sshOpts[*]}" nix-copy-closure --to "$destination" "$outPath" --gzip --use-substitutes NIX_SSHOPTS="${sshOpts[*]}" nix-copy-closure --to "$destination" "$outPath" --gzip --use-substitutes