Fix update script
This commit is contained in:
parent
8f1baa9f12
commit
03b56d1b8d
|
@ -69,6 +69,6 @@
|
|||
]
|
||||
++ import ../overlays {inherit lib;};
|
||||
};
|
||||
nixosConfigurations = lib.genAttrs ["zeus" "apollo" "hera" "fluffy"] makeSystem;
|
||||
nixosConfigurations = lib.genAttrs (builtins.attrNames (builtins.readDir ./machines)) makeSystem;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ import Say
|
|||
import Shh
|
||||
import System.Environment
|
||||
|
||||
load Absolute ["git", "niv"]
|
||||
load Absolute ["git", "nix"]
|
||||
paths :: [Text]
|
||||
paths =
|
||||
$$( bindCode (runIO pathBinsAbs) \rawPaths ->
|
||||
|
@ -32,11 +32,11 @@ repo = "git@hera.m-0.eu:nixos-config"
|
|||
main = do
|
||||
git "clone" repo "."
|
||||
setEnv "PATH" . toString $ Text.intercalate ":" paths
|
||||
ignoreFailure $ niv "update"
|
||||
ignoreFailure $ nix "flake" "update"
|
||||
changed <- (mempty /=) <$> (git "status" "--porcelain" |> captureTrim)
|
||||
when changed $ do
|
||||
git "config" "user.email" "maralorn@maralorn.de"
|
||||
git "config" "user.name" "maralorn (nix-auto-updater)"
|
||||
git "commit" "-am" "Update dependencies with niv"
|
||||
git "commit" "-am" "Update flake dependencies"
|
||||
git "push" "-f" "origin" "HEAD:niv-bump"
|
||||
unless changed $ say "No updates in any niv source. Doing nothing."
|
||||
unless changed $ say "No flake updates. Doing nothing."
|
||||
|
|
|
@ -33,6 +33,7 @@ main = do
|
|||
git "checkout" (toString branch)
|
||||
say "Running checks"
|
||||
nix "flake" "check"
|
||||
nix ["build", ".#checks.x86_64-linux.system-checks", "-o", "/var/cache/gc-links/test-config"]
|
||||
say "Checks succeeded"
|
||||
when (branch == "main") $ do
|
||||
say [i|Deploying new config to localhost.|]
|
||||
|
|
|
@ -4,119 +4,48 @@
|
|||
config,
|
||||
...
|
||||
}: let
|
||||
bins = lib.attrValues {inherit (pkgs) git nix niv gnutar xz gzip openssh laminar;};
|
||||
bins = lib.attrValues {inherit (pkgs) git nix gnutar xz gzip openssh laminar;};
|
||||
standardPath = lib.makeBinPath bins;
|
||||
imports = ["Control.Exception (onException)"];
|
||||
haskellBody = name: drv: ''
|
||||
myTrim = Text.dropAround ('"' ==) . decodeUtf8 . trim
|
||||
|
||||
main = do
|
||||
(configDir:hostname:remote:_) <- getArgs
|
||||
let flags = if remote == "remote" then ["--builders", "@/etc/nix/machines"] else []
|
||||
(myTrim -> homeManagerChannel) <- nix_instantiate "--show-trace" "--eval" "-E" ([i|(import #{configDir}/channels.nix).#{hostname}.home-manager-channel|] :: String) |> captureTrim
|
||||
(myTrim -> nixpkgsChannel) <- nix_instantiate "--show-trace" "--eval" "-E" ([i|(import #{configDir}/channels.nix).#{hostname}.nixpkgs-channel|] :: String) |> captureTrim
|
||||
paths <- aNixPath homeManagerChannel nixpkgsChannel (toText configDir)
|
||||
say [i|Trying to build ${name} config for #{hostname}.|]
|
||||
nix_build $ ["--show-trace", "-o", [i|/var/cache/gc-links/${name}-config-#{hostname}|]] ++ flags ++ ${drv}
|
||||
say [i|Build of ${name} config for #{hostname} was successful.|]
|
||||
'';
|
||||
test-system-config =
|
||||
pkgs.writeHaskellScript
|
||||
{
|
||||
name = "test-system-config";
|
||||
inherit bins;
|
||||
inherit imports;
|
||||
}
|
||||
(
|
||||
haskellBody "system" ''
|
||||
buildSystemParams ++ paths ++ ["-I", [i|nixos-config=#{configDir}/nixos/machines/#{hostname}/configuration.nix|]]''
|
||||
);
|
||||
|
||||
test-home-config =
|
||||
pkgs.writeHaskellScript
|
||||
{
|
||||
name = "test-home-config";
|
||||
inherit bins;
|
||||
inherit imports;
|
||||
}
|
||||
(
|
||||
haskellBody "home"
|
||||
''paths ++ [[i|#{configDir}/home-manager/target.nix|], "-A", hostname]''
|
||||
);
|
||||
common = ''
|
||||
set -e
|
||||
export PATH=${standardPath}:$PATH
|
||||
export NIX_PATH="/etc/nix-path:nixos-config=/etc/nixos/configuration.nix"
|
||||
'';
|
||||
checkout = ''
|
||||
git clone git@hera.m-0.eu:nixos-config . --config advice.detachedHead=false
|
||||
git checkout origin/$BRANCH
|
||||
git show -q
|
||||
REPODIR=.
|
||||
'';
|
||||
systems = builtins.attrNames (builtins.readDir ../../machines);
|
||||
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}
|
||||
${test-home-config}/bin/test-home-config $REPODIR ${host} "remote"
|
||||
git -C $REPODIR submodule update --init
|
||||
${test-home-config}/bin/test-home-config $REPODIR ${host} ""
|
||||
'';
|
||||
};
|
||||
mkSystemJob = host: {
|
||||
name = "system-config-${host}.run";
|
||||
value = pkgs.writeShellScript "test-${host}-system-config.run" ''
|
||||
${common}
|
||||
${checkout}
|
||||
${test-system-config}/bin/test-system-config $REPODIR ${host} "remote"
|
||||
git -C $REPODIR submodule update --init
|
||||
${test-system-config}/bin/test-system-config $REPODIR ${host} ""
|
||||
'';
|
||||
};
|
||||
deployCommand = "${
|
||||
pkgs.writeShellScript "deploy-system-config"
|
||||
"${pkgs.systemd}/bin/systemctl start --no-block update-config"
|
||||
}";
|
||||
in {
|
||||
services.laminar.cfgFiles.jobs =
|
||||
{
|
||||
"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 = "${standardPath}:$PATH";
|
||||
};
|
||||
ghcArgs = ["-threaded"];
|
||||
}
|
||||
(builtins.readFile ./test-config.hs);
|
||||
in
|
||||
pkgs.writeShellScript "test-config" ''
|
||||
FLAGS="" PATH=${standardPath}:$PATH ${test-config}
|
||||
'';
|
||||
"bump-config.run" = let
|
||||
bump-config =
|
||||
pkgs.writeHaskell "bump-config"
|
||||
{
|
||||
libraries = builtins.attrValues pkgs.myHaskellScriptPackages;
|
||||
ghcEnv.PATH = "${standardPath}:$PATH";
|
||||
ghcArgs = ["-threaded"];
|
||||
}
|
||||
(builtins.readFile ./bump-config.hs);
|
||||
in
|
||||
pkgs.writeShellScript "bump-config" ''
|
||||
PATH=${standardPath}:$PATH ${bump-config}
|
||||
'';
|
||||
}
|
||||
// lib.listToAttrs (map mkHomeJob homes)
|
||||
// lib.listToAttrs (map mkSystemJob homes);
|
||||
services.laminar.cfgFiles.jobs = {
|
||||
"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 = "${standardPath}:$PATH";
|
||||
};
|
||||
ghcArgs = ["-threaded"];
|
||||
}
|
||||
(builtins.readFile ./test-config.hs);
|
||||
in
|
||||
pkgs.writeShellScript "test-config" ''
|
||||
FLAGS="" PATH=${standardPath}:$PATH ${test-config}
|
||||
'';
|
||||
"bump-config.run" = let
|
||||
bump-config =
|
||||
pkgs.writeHaskell "bump-config"
|
||||
{
|
||||
libraries = builtins.attrValues pkgs.myHaskellScriptPackages;
|
||||
ghcEnv.PATH = "${standardPath}:$PATH";
|
||||
ghcArgs = ["-threaded"];
|
||||
}
|
||||
(builtins.readFile ./bump-config.hs);
|
||||
in
|
||||
pkgs.writeShellScript "bump-config" ''
|
||||
PATH=${standardPath}:$PATH ${bump-config}
|
||||
'';
|
||||
};
|
||||
security.sudo.extraRules = let
|
||||
allowedCommands = [deployCommand];
|
||||
in [
|
||||
|
|
Loading…
Reference in a new issue