add non working test for now
This commit is contained in:
parent
81e0aadf20
commit
7bea82788d
4 changed files with 52 additions and 14 deletions
12
flake.nix
12
flake.nix
|
@ -1,16 +1,22 @@
|
|||
{
|
||||
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
|
||||
outputs = { nixpkgs, ... }: let
|
||||
outputs = { nixpkgs, ... }@self: let
|
||||
supportedArchitectures = [
|
||||
"aarch64-darwin"
|
||||
"aarch64-linux"
|
||||
"x86_64-darwin"
|
||||
"x86_64-linux"
|
||||
];
|
||||
in {
|
||||
in rec {
|
||||
packages = nixpkgs.lib.genAttrs supportedArchitectures (system: {
|
||||
nix_templater = nixpkgs.legacyPackages.${system}.callPackage ./pkgs/nix_templater {};
|
||||
});
|
||||
legacyPackages = nixpkgs.lib.genAttrs supportedArchitectures (system: import ./lib.nix { pkgs = nixpkgs.legacyPackages.${system}; });
|
||||
legacyPackages = nixpkgs.lib.genAttrs supportedArchitectures (system: import ./lib.nix {
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
nix_templater = packages.${system}.nix_templater;
|
||||
});
|
||||
checks = nixpkgs.lib.genAttrs supportedArchitectures (system: {
|
||||
template = import ./tests/template.nix { inherit legacyPackages system nixpkgs; };
|
||||
});
|
||||
};
|
||||
}
|
||||
|
|
13
lib.nix
13
lib.nix
|
@ -1,4 +1,4 @@
|
|||
{ pkgs, text_templater }:
|
||||
{ pkgs, nix_templater }:
|
||||
rec {
|
||||
fileContents = file: {
|
||||
outPath = "<${builtins.placeholder "nix_template"}${toString file}${builtins.placeholder "nix_template"}>";
|
||||
|
@ -9,7 +9,8 @@ rec {
|
|||
pkgs.runCommand name {
|
||||
textBeforeTemplate = text;
|
||||
script = ''
|
||||
${text_templater}/bin/text_templater ${builtins.placeholder "out"}/template ${builtins.placeholder "nix_template"} "${outPath}"
|
||||
#!/bin/sh
|
||||
${nix_templater}/bin/nix_templater ${builtins.placeholder "out"}/template ${builtins.placeholder "nix_template"} "${outPath}"
|
||||
'';
|
||||
passAsFile = [ "script" "textBeforeTemplate" ];
|
||||
} ''
|
||||
|
@ -18,12 +19,4 @@ rec {
|
|||
cp $scriptPath $out/bin/${name}
|
||||
chmod +x $out/bin/${name}
|
||||
'';
|
||||
|
||||
test = template_text {
|
||||
name = "test";
|
||||
text = ''
|
||||
blablabla ${fileContents (pkgs.writeText "lol" "lol")}
|
||||
'';
|
||||
outPath = "./test";
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{ writeShellApplication, python3 }:
|
||||
writeShellApplication {
|
||||
name = "text_templater";
|
||||
name = "nix_templater";
|
||||
runtimeInputs = [
|
||||
python3
|
||||
];
|
||||
|
|
39
tests/template.nix
Normal file
39
tests/template.nix
Normal file
|
@ -0,0 +1,39 @@
|
|||
{ legacyPackages, system, nixpkgs }:
|
||||
let
|
||||
# this file would usually be outside of the store
|
||||
# but in this test it isn't, because setting it up in other ways is hard :)
|
||||
secret_file = (nixpkgs.legacyPackages.${system}.writeText "secret" "secret");
|
||||
in (nixpkgs.lib.nixos.runTest {
|
||||
hostPkgs = nixpkgs.legacyPackages.${system};
|
||||
name = "nix_templates";
|
||||
|
||||
nodes.machine = {config, pkgs, ...}: {
|
||||
config = {
|
||||
systemd.services.testservice = {
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
ExecStartPre = "${legacyPackages.${system}.template_text {
|
||||
name = "test";
|
||||
text = ''
|
||||
public text
|
||||
${legacyPackages.${system}.fileContents secret_file}
|
||||
'';
|
||||
outPath = "./test";
|
||||
}}/bin/test";
|
||||
ExecStart = pkgs.writeScript "test_file_got_templates" ''
|
||||
#!/bin/sh
|
||||
cat ./test | grep -q 'secret'
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
testScript = ''
|
||||
start_all()
|
||||
print(machine.execute("uname -a"))
|
||||
machine.wait_for_unit("testservice.service")
|
||||
print(machine.succeed("cat /root/test | grep -q secret"))
|
||||
'';
|
||||
})
|
Loading…
Add table
Reference in a new issue