2019-07-25 21:35:59 +00:00
|
|
|
let
|
2019-07-26 15:31:26 +00:00
|
|
|
pkgs = import <nixpkgs> {};
|
2019-07-26 13:54:30 +00:00
|
|
|
inherit (import ../common/lib.nix) writeHaskellScript get-niv-path home-manager unstable niv;
|
2019-07-25 21:35:59 +00:00
|
|
|
haskellBody = commandline:
|
|
|
|
''
|
|
|
|
|
|
|
|
data Host = Host {
|
|
|
|
configDir :: String,
|
|
|
|
hostname :: String
|
|
|
|
} deriving (Show, Data, Typeable)
|
|
|
|
|
|
|
|
host = Host{
|
|
|
|
configDir = def &= argPos 0,
|
|
|
|
hostname = def &= argPos 1
|
|
|
|
}
|
|
|
|
|
|
|
|
getNivPath dir = readTrim . get_niv_path ([i|#{dir :: String}/nix/sources.nix|] :: String)
|
|
|
|
|
|
|
|
getNivAssign dir name = fmap process . getNivPath dir $ name
|
|
|
|
where process str = ["-I", [i|#{name :: String}=#{str :: LBS.ByteString}|]]
|
|
|
|
|
|
|
|
main :: IO ()
|
|
|
|
main = do
|
|
|
|
host <- cmdArgs host
|
|
|
|
paths <- (concat <$>) . mapM (getNivAssign $ configDir host) $ ["nixpkgs", "unstable", "home-manager"]
|
|
|
|
${commandline}
|
|
|
|
'';
|
2019-07-26 13:54:30 +00:00
|
|
|
bins = [ get-niv-path pkgs.nix ];
|
|
|
|
imports = ["System.Console.CmdArgs.Implicit"];
|
|
|
|
libraries = [ unstable.haskellPackages.cmdargs ];
|
2019-07-25 21:35:59 +00:00
|
|
|
|
|
|
|
test-system-config = writeHaskellScript {
|
|
|
|
name = "test-system-config";
|
2019-07-26 13:54:30 +00:00
|
|
|
inherit bins imports libraries;
|
2019-07-25 21:35:59 +00:00
|
|
|
} (haskellBody
|
|
|
|
''
|
|
|
|
nix $ ["build", "-f", "<nixpkgs/nixos>", "system"] ++ paths ++ ["-I", [i|nixos-config=#{configDir host}/hosts/#{hostname host}/configuration.nix|], "-o", [i|result-system-#{hostname host}|]]
|
|
|
|
'');
|
|
|
|
|
2019-07-26 13:54:30 +00:00
|
|
|
test-home-config = writeHaskellScript {
|
|
|
|
name = "test-home-config";
|
|
|
|
inherit bins imports libraries;
|
2019-07-25 21:35:59 +00:00
|
|
|
} (haskellBody
|
|
|
|
''
|
|
|
|
nix $ ["build", "-f", "<home-manager/home-manager/home-manager.nix>"] ++ paths ++ ["--argstr", "confPath", [i|#{configDir host}/hosts/#{hostname host}/home.nix|], "--argstr", "confAttr", "", "--out-link", [i|result-home-manager-#{hostname host}|], "activationPackage"]
|
|
|
|
'');
|
|
|
|
|
|
|
|
repoSrc = "git@hera.m-0.eu:nixos-config";
|
2019-07-26 17:10:53 +00:00
|
|
|
configPath = "/etc/nixos";
|
2019-07-26 13:54:30 +00:00
|
|
|
test-and-bump-config = writeHaskellScript {
|
|
|
|
name = "test-and-bump-config";
|
|
|
|
bins = [ test-system-config test-home-config pkgs.git pkgs.coreutils niv pkgs.git-crypt ];
|
2019-07-25 23:35:19 +00:00
|
|
|
imports = [ "Control.Exception (bracket)" "System.Directory (withCurrentDirectory)" "Control.Monad (when)"];
|
2019-07-25 21:35:59 +00:00
|
|
|
} ''
|
2019-07-26 15:31:26 +00:00
|
|
|
checkout :: IO FilePath
|
|
|
|
checkout = do
|
|
|
|
dir <- (LT.unpack . LTE.decodeUtf8 <$>) . readTrim $ mktemp "-d"
|
|
|
|
git "clone" "${repoSrc}" dir
|
|
|
|
return dir
|
|
|
|
|
|
|
|
cleanup :: String -> IO ()
|
|
|
|
cleanup = (rm "-rf")
|
|
|
|
|
|
|
|
unlock :: IO ()
|
|
|
|
unlock = mapM_ (\x -> git_crypt "unlock" ([i|${configPath}/.git/git-crypt/keys/#{x}|] :: String)) ["default", "apollo", "hera"]
|
|
|
|
|
|
|
|
update :: IO ()
|
|
|
|
update = niv "update"
|
|
|
|
|
|
|
|
testBuild :: FilePath -> IO ()
|
|
|
|
testBuild dir = do
|
|
|
|
mapM_ (test_system_config dir) ["apollo", "hera"]
|
|
|
|
mapM_ (test_home_config dir) ["apollo", "hera", "hephaistos"]
|
|
|
|
|
|
|
|
push :: FilePath -> IO()
|
|
|
|
push dir = do
|
|
|
|
changed <- ((mempty /=) <$>) . readTrim $ git "-C" dir "status" "--porcelain"
|
|
|
|
when changed $ git "-C" dir "commit" "-am" "Update dependencies with niv" >> git "-C" dir "push"
|
|
|
|
|
|
|
|
main :: IO ()
|
2019-07-25 21:35:59 +00:00
|
|
|
main = do
|
|
|
|
path <- readTrim pwd
|
2019-07-26 15:31:26 +00:00
|
|
|
bracket checkout cleanup $ \dir -> do
|
|
|
|
withCurrentDirectory dir $ unlock >> update
|
|
|
|
testBuild dir
|
|
|
|
push dir
|
2019-07-25 21:35:59 +00:00
|
|
|
'';
|
|
|
|
in
|
|
|
|
{
|
2019-07-26 15:31:26 +00:00
|
|
|
inherit test-system-config test-home-config test-and-bump-config;
|
2019-07-25 21:35:59 +00:00
|
|
|
}
|