2019-07-25 21:35:59 +00:00
|
|
|
{ pkgs, config, lib, ... }:
|
|
|
|
let
|
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 13:54:30 +00:00
|
|
|
configPath = "/home/${config.home.username}/git/nixos/config";
|
|
|
|
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
|
|
|
} ''
|
|
|
|
main = do
|
|
|
|
path <- readTrim pwd
|
|
|
|
bracket (do
|
|
|
|
dir <- (LT.unpack . LTE.decodeUtf8 <$>) . readTrim $ mktemp "-d"
|
|
|
|
git "clone" "${repoSrc}" dir
|
|
|
|
return dir)
|
2019-07-25 23:35:19 +00:00
|
|
|
(rm "-rf") $
|
2019-07-25 22:50:20 +00:00
|
|
|
\dir -> do
|
2019-07-26 13:54:30 +00:00
|
|
|
cp "-r" "${configPath}/.git/git-crypt" ([i|#{dir}/.git|] :: String)
|
|
|
|
mapM_ (git "-C" dir "checkout") ["common/secret", "hosts/apollo/secret", "hosts/hera/secret"]
|
|
|
|
--withCurrentDirectory dir $ niv "update"
|
2019-07-25 21:35:59 +00:00
|
|
|
mapM_ (test_system_config dir) ["apollo", "hera"]
|
2019-07-26 13:54:30 +00:00
|
|
|
mapM_ (test_home_config dir) ["apollo", "hera", "hephaistos"]
|
2019-07-25 22:50:20 +00:00
|
|
|
changed <- ((mempty /=) <$>) . readTrim $ git "-C" dir "status" "--porcelain"
|
|
|
|
when changed $ git "-C" dir "commit" "-am" "Update dependencies with niv" >> git "-C" dir "push"
|
2019-07-25 21:35:59 +00:00
|
|
|
'';
|
|
|
|
in
|
|
|
|
{
|
|
|
|
home.packages = [
|
|
|
|
test-system-config
|
2019-07-26 13:54:30 +00:00
|
|
|
test-home-config
|
|
|
|
test-and-bump-config
|
2019-07-25 21:35:59 +00:00
|
|
|
];
|
|
|
|
}
|