Merge pull request #1 from KiaraGrouwstra/fix-initial-test

fix initial test
This commit is contained in:
lassulus 2025-05-28 23:19:15 +02:00 committed by GitHub
commit 437fd19b72
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 10 additions and 6 deletions

View file

@ -1,10 +1,12 @@
{ pkgs, nix_templater }: { pkgs, nix_templater }:
rec { {
# placeholder to be substituted with the content of a secret file
fileContents = file: { fileContents = file: {
outPath = "<${builtins.placeholder "nix_template"}${toString file}${builtins.placeholder "nix_template"}>"; outPath = "<${builtins.placeholder "nix_template"}${toString file}${builtins.placeholder "nix_template"}>";
file = file; file = file;
}; };
# make a template with placeholders
template_text = { name, text, outPath }: template_text = { name, text, outPath }:
pkgs.runCommand name { pkgs.runCommand name {
textBeforeTemplate = text; textBeforeTemplate = text;

View file

@ -1,7 +1,8 @@
# replace occurrences of a magic string in a template file
import sys import sys
from pathlib import Path from pathlib import Path
tempalte_file = sys.argv[1] template_file = sys.argv[1]
magic_string = sys.argv[2] magic_string = sys.argv[2]
outfile = sys.argv[3] outfile = sys.argv[3]
@ -9,7 +10,7 @@ if Path(outfile).exists():
print(f"{outfile} already exists, aborting") print(f"{outfile} already exists, aborting")
sys.exit(1) sys.exit(1)
template_bytes = Path(tempalte_file).read_bytes() template_bytes = Path(template_file).read_bytes()
loc = 0 loc = 0
output = b"" output = b""

View file

@ -1,3 +1,4 @@
# test injecting a secret into a template
{ legacyPackages, system, nixpkgs }: { legacyPackages, system, nixpkgs }:
let let
# this file would usually be outside of the store # this file would usually be outside of the store
@ -7,7 +8,7 @@ in (nixpkgs.lib.nixos.runTest {
hostPkgs = nixpkgs.legacyPackages.${system}; hostPkgs = nixpkgs.legacyPackages.${system};
name = "nix_templates"; name = "nix_templates";
nodes.machine = {config, pkgs, ...}: { nodes.machine = {pkgs, ...}: {
config = { config = {
systemd.services.testservice = { systemd.services.testservice = {
wantedBy = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ];
@ -33,7 +34,7 @@ in (nixpkgs.lib.nixos.runTest {
testScript = '' testScript = ''
start_all() start_all()
print(machine.execute("uname -a")) print(machine.execute("uname -a"))
machine.wait_for_unit("testservice.service") machine.wait_for_unit("multi-user.target")
print(machine.succeed("cat /root/test | grep -q secret")) print(machine.succeed("cat /test | grep -q secret"))
''; '';
}) })