2019-07-25 21:35:59 +00:00
|
|
|
let
|
2019-08-02 03:17:00 +00:00
|
|
|
inherit (import ../lib)
|
2019-08-02 17:13:19 +00:00
|
|
|
pkgs writeHaskellScript get-niv-path home-manager unstable haskellList;
|
2019-08-02 03:17:00 +00:00
|
|
|
in rec {
|
2019-08-02 17:13:19 +00:00
|
|
|
haskellBody = name: commandline: ''
|
2019-08-13 22:24:38 +00:00
|
|
|
getNivPath dir name = get_niv_path ([i|#{dir :: String}/nix/sources.nix|] :: String) name |> captureTrim
|
2019-07-25 21:35:59 +00:00
|
|
|
|
2019-08-13 22:24:38 +00:00
|
|
|
getNivAssign dir name = process <$> getNivPath dir name
|
2020-01-19 16:40:02 +00:00
|
|
|
where process str = ["-I" :: String, [i|#{name :: String}=#{str :: LByteString}|]]
|
2019-07-25 21:35:59 +00:00
|
|
|
|
|
|
|
main = do
|
2019-07-28 22:51:10 +00:00
|
|
|
(configDir:hostname:args) <- getArgs
|
2020-01-19 16:40:02 +00:00
|
|
|
paths <- concat <$> mapM (getNivAssign $ toString configDir) ["nixpkgs", "unstable", "home-manager"]
|
2019-08-02 18:41:58 +00:00
|
|
|
putStrLn [i|Trying to build ${name} config for #{hostname}|]
|
2019-07-25 21:35:59 +00:00
|
|
|
${commandline}
|
2019-07-31 21:56:52 +00:00
|
|
|
'';
|
2019-07-26 13:54:30 +00:00
|
|
|
bins = [ get-niv-path pkgs.nix ];
|
2019-07-25 21:35:59 +00:00
|
|
|
|
|
|
|
test-system-config = writeHaskellScript {
|
|
|
|
name = "test-system-config";
|
2019-07-28 22:51:10 +00:00
|
|
|
inherit bins;
|
2019-08-02 17:13:19 +00:00
|
|
|
} (haskellBody "system" ''
|
2020-01-19 16:40:02 +00:00
|
|
|
nix $ ["build", "-f", "<nixpkgs/nixos>", "system"] ++ paths ++ ["-I", [i|nixos-config=#{configDir}/hosts/#{hostname}/configuration.nix|], "-o", [i|result-system-#{hostname}|]] ++ fmap toString args
|
2019-07-31 21:56:52 +00:00
|
|
|
'');
|
2019-07-25 21:35:59 +00:00
|
|
|
|
2019-07-26 13:54:30 +00:00
|
|
|
test-home-config = writeHaskellScript {
|
|
|
|
name = "test-home-config";
|
2019-07-28 22:51:10 +00:00
|
|
|
inherit bins;
|
2019-08-02 17:13:19 +00:00
|
|
|
} (haskellBody "home" ''
|
2020-05-07 13:30:49 +00:00
|
|
|
nix $ ["build", "-f", "<home-manager/home-manager/home-manager.nix>"] ++ paths ++ ["--argstr", "confPath", [i|#{configDir}/home.nix|], "--argstr", "confAttr", hostname, "--out-link", [i|result-home-manager-#{hostname}|], "activationPackage"] ++ fmap toString args
|
2019-07-31 21:56:52 +00:00
|
|
|
'');
|
2019-07-25 21:35:59 +00:00
|
|
|
|
|
|
|
repoSrc = "git@hera.m-0.eu:nixos-config";
|
2019-07-26 17:10:53 +00:00
|
|
|
configPath = "/etc/nixos";
|
2019-07-31 21:56:52 +00:00
|
|
|
systems = [ "apollo" "hera" ];
|
2020-05-07 14:08:32 +00:00
|
|
|
homes = pkgs.lib.attrNames (import ../home.nix);
|
2019-07-31 21:56:52 +00:00
|
|
|
keys = [ "default" "apollo" "hera" ];
|
2019-08-02 03:17:00 +00:00
|
|
|
test-config = writeHaskellScript {
|
2019-08-02 04:07:54 +00:00
|
|
|
name = "test-config";
|
2020-04-26 13:29:23 +00:00
|
|
|
bins =
|
|
|
|
[ test-system-config test-home-config pkgs.git pkgs.niv pkgs.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
|
|
|
|
(decodeUtf8 -> dir) <- mktemp "-d" |> captureTrim
|
|
|
|
git "clone" "${repoSrc}" dir
|
|
|
|
pure dir
|
2019-07-26 15:31:26 +00:00
|
|
|
|
2019-07-31 21:56:52 +00:00
|
|
|
main = do
|
2019-08-13 22:24:38 +00:00
|
|
|
path <- pwd |> captureTrim
|
2020-01-19 16:40:02 +00:00
|
|
|
bump <- (maybe False (== "bump") . listToMaybe) <$> getArgs
|
2019-07-31 21:56:52 +00:00
|
|
|
bracket checkout (rm "-rf") $ \dir -> do
|
|
|
|
withCurrentDirectory dir $ do
|
|
|
|
mapM_ (\x -> git_crypt "unlock" ([i|${configPath}/.git/git-crypt/keys/#{x}|] :: String)) ${
|
2019-08-13 22:24:38 +00:00
|
|
|
haskellList keys
|
2019-07-31 21:56:52 +00:00
|
|
|
}
|
2019-08-02 03:17:00 +00:00
|
|
|
when bump $ ignoreFailure $ niv "update"
|
2019-08-13 22:24:38 +00:00
|
|
|
changed <- (mempty /=) <$> (git "-C" dir "status" "--porcelain" |> captureTrim)
|
2019-07-31 21:56:52 +00:00
|
|
|
when changed $ do
|
|
|
|
git "-C" dir "config" "user.email" "maralorn@maralorn.de"
|
|
|
|
git "-C" dir "config" "user.name" "maralorn (nix-auto-updater)"
|
|
|
|
git "-C" dir "commit" "-am" "Update dependencies with niv"
|
2019-08-18 09:18:51 +00:00
|
|
|
git "-C" dir "push" "-f" "origin" "master:version-bump"
|
|
|
|
mapM_ (test_system_config dir) ${haskellList systems}
|
|
|
|
mapM_ (test_home_config dir) ${haskellList homes}
|
|
|
|
when changed $ do
|
|
|
|
git "-C" dir "push" "origin" "master:master"
|
2019-07-31 21:56:52 +00:00
|
|
|
'';
|
2019-08-02 03:17:00 +00:00
|
|
|
}
|