stockholm/krebs/krops.nix

85 lines
2.5 KiB
Nix
Raw Normal View History

2019-07-08 01:10:56 +02:00
{ name, target ? name }: rec {
2018-04-05 19:31:39 +02:00
2018-10-07 17:08:01 +02:00
krops = ../submodules/krops;
2018-04-05 19:31:39 +02:00
2018-06-04 12:55:49 +02:00
lib = import "${krops}/lib";
2018-04-05 19:31:39 +02:00
# TODO document why pkgs should be used like this
2018-06-04 12:55:49 +02:00
pkgs = import "${krops}/pkgs" {};
2018-04-05 19:31:39 +02:00
krebs-source = { test ? false }: rec {
nixpkgs = if test then {
2019-01-28 23:05:38 +01:00
derivation = let
2023-12-12 11:39:52 +01:00
rev = (lib.importJSON ../flake.lock).nodes.nixpkgs.locked.rev;
2023-12-12 12:38:50 +01:00
sha256 = (lib.importJSON ../flake.lock).nodes.nixpkgs.locked.narHash;
2019-01-28 23:05:38 +01:00
in ''
with import (builtins.fetchTarball {
url = "https://github.com/nixos/nixpkgs/archive/${rev}.tar.gz";
sha256 = "${sha256}";
}) {};
2019-01-03 21:32:23 +01:00
pkgs.fetchFromGitHub {
owner = "nixos";
repo = "nixpkgs";
2019-01-28 23:05:38 +01:00
rev = "${rev}";
sha256 = "${sha256}";
2019-01-03 21:32:23 +01:00
}
'';
} else {
git = {
2023-12-12 11:39:52 +01:00
ref = (lib.importJSON ../flake.lock).nodes.nixpkgs.locked.rev;
url = "https://github.com/NixOS/nixpkgs";
2021-01-24 15:58:14 +01:00
shallow = true;
};
2018-04-05 19:31:39 +02:00
};
stockholm.file = toString ../.;
2020-02-18 14:57:16 +01:00
stockholm-version.pipe =
toString (pkgs.writers.writeDash "${name}-version" ''
set -efu
cd ${lib.escapeShellArg stockholm.file}
V=$(${pkgs.coreutils}/bin/date +%y.%m)
if test -d .git; then
V=$V.git.$(${pkgs.git}/bin/git describe --always --dirty)
case $V in (*-dirty)
V=$V@''${HOSTNAME-$(${pkgs.nettools}/bin/hostname)}
esac
fi
printf %s "$V"
'');
2018-04-05 19:31:39 +02:00
};
source ={ test }: lib.evalSource [
(krebs-source { test = test; })
2018-04-05 19:31:39 +02:00
{
nixos-config.symlink = "stockholm/krebs/1systems/${name}/config.nix";
2018-11-27 21:14:40 +01:00
secrets = if test then {
2019-06-13 23:30:54 +02:00
file = toString ./0tests/data/secrets;
2018-11-27 21:14:40 +01:00
} else {
pass = {
dir = "${lib.getEnv "HOME"}/brain";
name = "krebs-secrets/${name}";
};
};
2018-04-05 19:31:39 +02:00
}
];
# usage: $(nix-build --no-out-link --argstr name HOSTNAME -A deploy)
2018-06-04 12:55:49 +02:00
deploy = pkgs.krops.writeDeploy "${name}-deploy" {
2018-04-05 19:31:39 +02:00
source = source { test = false; };
2019-07-08 01:10:56 +02:00
target = "root@${target}/var/src";
2018-04-05 19:31:39 +02:00
};
2021-01-24 15:58:25 +01:00
# usage: $(nix-build --no-out-link --argstr name HOSTNAME --argstr target PATH -A populate)
populate = { target, force ? false }: pkgs.populate {
inherit force;
source = source { test = false; };
target = lib.mkTarget target;
};
# usage: $(nix-build --no-out-link --argstr name HOSTNAME --argstr target PATH -A test)
test = { target }: pkgs.krops.writeTest "${name}-test" {
2018-10-09 13:48:52 +02:00
force = true;
inherit target;
2018-04-05 19:31:39 +02:00
source = source { test = true; };
2018-09-07 19:46:20 +02:00
};
2018-04-05 19:31:39 +02:00
}