2020-05-27 13:20:08 +00:00
|
|
|
self: super:
|
2019-07-25 21:35:59 +00:00
|
|
|
let
|
2020-05-27 13:20:08 +00:00
|
|
|
bins = [ self.nix ];
|
|
|
|
repoSrc = "git@hera.m-0.eu:nixos-config";
|
|
|
|
configPath = "/etc/nixos";
|
|
|
|
systems = [ "apollo" "hera" ];
|
2020-06-27 19:54:32 +00:00
|
|
|
homes = self.lib.attrNames (import ../home-manager/machines.nix);
|
2020-05-27 13:20:08 +00:00
|
|
|
keys = [ "default" "apollo" "hera" ];
|
2020-06-26 17:19:42 +00:00
|
|
|
imports = [ "Control.Exception (onException)" ];
|
2019-08-02 17:13:19 +00:00
|
|
|
haskellBody = name: commandline: ''
|
2019-07-25 21:35:59 +00:00
|
|
|
main = do
|
2020-05-16 13:59:02 +00:00
|
|
|
(configDir:hostname:args) <- getArgs
|
|
|
|
paths <- myNixPath $ toText configDir
|
2020-06-26 17:42:57 +00:00
|
|
|
logFile <- mktemp |> captureTrim
|
2020-06-26 17:45:59 +00:00
|
|
|
let command = (${commandline}) &!> StdOut &> Append logFile
|
|
|
|
failHandler = do
|
|
|
|
say [i|### Build failure for ${name} config for #{hostname} ###|]
|
|
|
|
cat logFile
|
|
|
|
say [i|Trying to build ${name} config for #{hostname}. Logging to #{logFile}.|]
|
|
|
|
onException command failHandler
|
2020-05-17 20:23:27 +00:00
|
|
|
say [i|Build of ${name} config for #{hostname} was successful.|]
|
2019-07-31 21:56:52 +00:00
|
|
|
'';
|
2020-05-27 13:20:08 +00:00
|
|
|
in {
|
2019-07-25 21:35:59 +00:00
|
|
|
|
2020-05-27 13:20:08 +00:00
|
|
|
test-system-config = self.writeHaskellScript {
|
2019-07-25 21:35:59 +00:00
|
|
|
name = "test-system-config";
|
2019-07-28 22:51:10 +00:00
|
|
|
inherit bins;
|
2020-06-26 17:19:42 +00:00
|
|
|
inherit imports;
|
2020-07-02 19:36:42 +00:00
|
|
|
} (haskellBody "system" ''nix_build $ ["<nixpkgs/nixos>", "-A", "system"] ++ paths ++ ["-I", [i|nixos-config=#{configDir}nixos/machines#{hostname}/configuration.nix|], "-o", [i|result-system-#{hostname}|]] ++ fmap toString args'');
|
2019-07-25 21:35:59 +00:00
|
|
|
|
2020-05-27 13:20:08 +00:00
|
|
|
test-home-config = self.writeHaskellScript {
|
2019-07-26 13:54:30 +00:00
|
|
|
name = "test-home-config";
|
2019-07-28 22:51:10 +00:00
|
|
|
inherit bins;
|
2020-06-26 17:19:42 +00:00
|
|
|
inherit imports;
|
2020-06-27 19:54:32 +00:00
|
|
|
} (haskellBody "home" ''nix_build $ paths ++ [[i|#{configDir}/home-manager/target.nix|], "-A", hostname, "-o", [i|result-home-manager-#{hostname}|]] ++ fmap toString args'');
|
2019-07-25 21:35:59 +00:00
|
|
|
|
2020-05-27 13:20:08 +00:00
|
|
|
test-config = self.writeHaskellScript {
|
2019-08-02 04:07:54 +00:00
|
|
|
name = "test-config";
|
2020-06-02 02:55:49 +00:00
|
|
|
bins = [
|
|
|
|
self.test-system-config
|
|
|
|
self.test-home-config
|
|
|
|
self.git
|
|
|
|
self.niv
|
|
|
|
self.git-crypt
|
|
|
|
];
|
2020-01-19 16:40:02 +00:00
|
|
|
imports = [ "System.Directory (withCurrentDirectory)" ];
|
2019-07-25 21:35:59 +00:00
|
|
|
} ''
|
2019-07-31 21:56:52 +00:00
|
|
|
checkout :: IO FilePath
|
2020-01-19 16:40:02 +00:00
|
|
|
checkout = do
|
2020-05-16 15:39:04 +00:00
|
|
|
(decodeUtf8 -> repoDir) <- mktemp "-d" |> captureTrim
|
|
|
|
git "clone" "${repoSrc}" repoDir
|
|
|
|
pure repoDir
|
2019-07-26 15:31:26 +00:00
|
|
|
|
2019-07-31 21:56:52 +00:00
|
|
|
main = do
|
2020-01-19 16:40:02 +00:00
|
|
|
bump <- (maybe False (== "bump") . listToMaybe) <$> getArgs
|
2020-05-16 15:39:04 +00:00
|
|
|
bracket checkout (rm "-rf") $ \repoDir -> do
|
|
|
|
withCurrentDirectory repoDir $ do
|
2019-07-31 21:56:52 +00:00
|
|
|
mapM_ (\x -> git_crypt "unlock" ([i|${configPath}/.git/git-crypt/keys/#{x}|] :: String)) ${
|
2020-05-27 13:20:08 +00:00
|
|
|
self.haskellList keys
|
2019-07-31 21:56:52 +00:00
|
|
|
}
|
2019-08-02 03:17:00 +00:00
|
|
|
when bump $ ignoreFailure $ niv "update"
|
2020-05-16 15:39:04 +00:00
|
|
|
changed <- (mempty /=) <$> (git "-C" repoDir "status" "--porcelain" |> captureTrim)
|
2019-07-31 21:56:52 +00:00
|
|
|
when changed $ do
|
2020-05-16 16:00:14 +00:00
|
|
|
git "-C" repoDir "config" "user.email" "maralorn@maralorn.de"
|
|
|
|
git "-C" repoDir "config" "user.name" "maralorn (nix-auto-updater)"
|
|
|
|
git "-C" repoDir "commit" "-am" "Update dependencies with niv"
|
2020-06-26 17:05:42 +00:00
|
|
|
concurrently_
|
2020-06-26 17:04:24 +00:00
|
|
|
(mapConcurrently_ (test_system_config repoDir) ${self.haskellList systems})
|
|
|
|
(mapConcurrently_ (test_home_config repoDir) ${self.haskellList homes})
|
2019-08-18 09:18:51 +00:00
|
|
|
when changed $ do
|
2020-05-16 16:00:14 +00:00
|
|
|
git "-C" repoDir "push" "origin" "master:master"
|
2019-07-31 21:56:52 +00:00
|
|
|
'';
|
2019-08-02 03:17:00 +00:00
|
|
|
}
|