1
0
Fork 0

Try fixing test-config.run

This commit is contained in:
Malte Brandy 2021-05-18 18:28:49 +02:00
parent 4f3e831ba2
commit 7728e8280c

View file

@ -20,8 +20,10 @@ let
inherit bins;
inherit imports;
}
(haskellBody "system" ''
buildSystemParams ++ paths ++ ["-I", [i|nixos-config=#{configDir}/nixos/machines/#{hostname}/configuration.nix|]]'');
(
haskellBody "system" ''
buildSystemParams ++ paths ++ ["-I", [i|nixos-config=#{configDir}/nixos/machines/#{hostname}/configuration.nix|]]''
);
test-home-config = pkgs.writeHaskellScript
{
@ -29,8 +31,10 @@ let
inherit bins;
inherit imports;
}
(haskellBody "home"
''paths ++ [[i|#{configDir}/home-manager/target.nix|], "-A", hostname]'');
(
haskellBody "home"
''paths ++ [[i|#{configDir}/home-manager/target.nix|], "-A", hostname]''
);
path = [ pkgs.git pkgs.nix pkgs.gnutar pkgs.gzip pkgs.openssh pkgs.laminar ];
common = ''
set -e
@ -46,49 +50,59 @@ let
remoteFlags = "--builders @/etc/nix/machines --max-jobs 0";
systems = [ "apollo" "hera" ];
homes = lib.attrNames (import ../../../home-manager/machines.nix);
mkHomeJob = (host: {
name = "home-config-${host}.run";
value = pkgs.writeShellScript "test-${host}-home-config.run" ''
${common}
${checkout}
export FLAGS='${remoteFlags}'
${test-home-config}/bin/test-home-config $REPODIR ${host}
git -C $REPODIR submodule update --init
export FLAGS=""
${test-home-config}/bin/test-home-config $REPODIR ${host}
laminarc set "RESULTDRV=$(cat ./derivation)"
'';
});
mkSystemJob = (host: {
name = "system-config-${host}.run";
value = pkgs.writeShellScript "test-${host}-system-config.run" ''
${common}
${checkout}
export FLAGS='${remoteFlags}'
${test-system-config}/bin/test-system-config $REPODIR ${host}
git -C $REPODIR submodule update --init
export FLAGS=""
${test-system-config}/bin/test-system-config $REPODIR ${host}
laminarc set "RESULTDRV=$(cat ./derivation)"
'';
});
mkHomeJob = (
host: {
name = "home-config-${host}.run";
value = pkgs.writeShellScript "test-${host}-home-config.run" ''
${common}
${checkout}
export FLAGS='${remoteFlags}'
${test-home-config}/bin/test-home-config $REPODIR ${host}
git -C $REPODIR submodule update --init
export FLAGS=""
${test-home-config}/bin/test-home-config $REPODIR ${host}
laminarc set "RESULTDRV=$(cat ./derivation)"
'';
}
);
mkSystemJob = (
host: {
name = "system-config-${host}.run";
value = pkgs.writeShellScript "test-${host}-system-config.run" ''
${common}
${checkout}
export FLAGS='${remoteFlags}'
${test-system-config}/bin/test-system-config $REPODIR ${host}
git -C $REPODIR submodule update --init
export FLAGS=""
${test-system-config}/bin/test-system-config $REPODIR ${host}
laminarc set "RESULTDRV=$(cat ./derivation)"
'';
}
);
deployCommand = "${pkgs.writeShellScript "deploy-system-config"
"${pkgs.systemd}/bin/systemctl start --no-block update-config"}";
in
{
services.laminar.cfgFiles.jobs = {
"test-config.run" = pkgs.writeHaskell "test-config"
{
libraries = builtins.attrValues pkgs.myHaskellScriptPackages;
ghcEnv = {
HOMES = lib.concatStringsSep " " homes;
SYSTEMS = lib.concatStringsSep " " systems;
DEPLOY = deployCommand;
PATH = "${lib.makeBinPath [ pkgs.laminar pkgs.git pkgs.nix ]}:$PATH";
};
ghcArgs = [ "-threaded" ];
}
(builtins.readFile ./test-config.hs);
"test-config.run" =
let
test-config = pkgs.writeHaskell "test-config"
{
libraries = builtins.attrValues pkgs.myHaskellScriptPackages;
ghcEnv = {
HOMES = lib.concatStringsSep " " homes;
SYSTEMS = lib.concatStringsSep " " systems;
DEPLOY = deployCommand;
PATH = "${lib.makeBinPath [ pkgs.laminar pkgs.git pkgs.nix pkgs.gnutar ]}:$PATH";
};
ghcArgs = [ "-threaded" ];
}
(builtins.readFile ./test-config.hs);
in
pkgs.writeShellScript "test-config" ''
PATH=${pkgs.gnutar}/bin:$PATH ${test-config}
'';
"bump-config.run" = pkgs.writeHaskell "bump-config"
{
libraries = builtins.attrValues pkgs.myHaskellScriptPackages;
@ -99,17 +113,22 @@ in
} // lib.listToAttrs (map mkHomeJob homes)
// lib.listToAttrs (map mkSystemJob homes);
security.sudo.extraRules =
let allowedCommands = [ deployCommand ];
let
allowedCommands = [ deployCommand ];
in
[{
commands = map
(command: {
inherit command;
options = [ "NOPASSWD" ];
})
allowedCommands;
users = [ "laminar" ];
}];
[
{
commands = map
(
command: {
inherit command;
options = [ "NOPASSWD" ];
}
)
allowedCommands;
users = [ "laminar" ];
}
];
systemd.services = {
update-config = {
path = [ pkgs.git pkgs.nix ];
@ -125,7 +144,8 @@ in
StartLimitBurst = 3;
};
script =
let user = "maralorn";
let
user = "maralorn";
in
''
/run/wrappers/bin/sudo -u ${user} git -C /etc/nixos pull --ff-only