1
0
Fork 0
nixos-config/overlays/testing.nix

69 lines
3 KiB
Nix
Raw Normal View History

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-06-26 17:19:42 +00:00
imports = [ "Control.Exception (onException)" ];
2021-01-09 02:31:25 +00:00
haskellBody = name: drv: target: ''
2019-07-25 21:35:59 +00:00
main = do
2021-01-09 02:31:25 +00:00
(configDir:hostname:_) <- getArgs
2020-12-07 03:24:18 +00:00
(Text.dropAround ('"' ==) . decodeUtf8 . trim -> homeManagerChannel) <- nix_instantiate "--eval" "-E" ([i|(import #{configDir}/channels.nix).#{hostname}.home-manager-channel|] :: String) |> captureTrim
(Text.dropAround ('"' ==) . decodeUtf8 . trim -> nixpkgsChannel) <- nix_instantiate "--eval" "-E" ([i|(import #{configDir}/channels.nix).#{hostname}.nixpkgs-channel|] :: String) |> captureTrim
2020-12-07 03:12:07 +00:00
paths <- aNixPath homeManagerChannel nixpkgsChannel (toText configDir)
2021-01-07 03:45:37 +00:00
say [i|Trying to build ${name} config for #{hostname}.|]
2021-01-09 02:31:25 +00:00
(Text.dropAround ('"' ==) . decodeUtf8 . trim -> derivationName) <- (nix_instantiate $ ${drv}) |> captureTrim
exe "nix-jobs" ["realise", toString derivationName]
nix_store ["-r", toString derivationName, "--indirect", "--add-root", ${target}]
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;
2021-01-09 02:31:25 +00:00
} (haskellBody "system" ''buildSystemParams ++ paths ++ ["-I", [i|nixos-config=#{configDir}/nixos/machines/#{hostname}/configuration.nix|]]'' "[i|result-system-#{hostname}|]");
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;
2021-01-09 02:31:25 +00:00
} (haskellBody "home" ''paths ++ [[i|#{configDir}/home-manager/target.nix|], "-A", hostname]'' "[i|result-home-manager-#{hostname}|]");
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
2020-12-15 10:58:08 +00:00
self.niv.bin
2020-06-02 02:55:49 +00:00
self.git-crypt
2021-01-07 03:45:37 +00:00
self.laminar
2020-06-02 02:55:49 +00:00
];
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
main = do
2021-01-07 03:45:37 +00:00
bump <- maybe False (== "bump") . listToMaybe <$> getArgs
git "clone" "${repoSrc}" "config"
withCurrentDirectory "config" $ do
when bump $ ignoreFailure $ niv "update"
changed <- (mempty /=) <$> (git "status" "--porcelain" |> captureTrim)
2019-07-31 21:56:52 +00:00
when changed $ do
2021-01-07 03:45:37 +00:00
git "config" "user.email" "maralorn@maralorn.de"
git "config" "user.name" "maralorn (nix-auto-updater)"
git "commit" "-am" "Update dependencies with niv"
2021-01-07 04:17:25 +00:00
git "push" "-f" "origin" "HEAD:niv-bump"
2021-01-07 03:45:37 +00:00
let branch = if bump then "niv-bump" else "master"
2020-06-26 17:05:42 +00:00
concurrently_
2021-01-07 03:45:37 +00:00
(mapConcurrently_ (\x -> laminarc ["run", [i|system-config-#{x}|], [i|BRANCH=#{branch}|]]) ${
self.haskellList systems
})
(mapConcurrently_ (\x -> laminarc ["run", [i|home-config-#{x}|], [i|BRANCH=#{branch}|]]) ${
self.haskellList homes
})
2021-01-07 05:01:30 +00:00
when changed $ git "push" "origin" "master:master"
2019-07-31 21:56:52 +00:00
'';
2019-08-02 03:17:00 +00:00
}