1
0
Fork 0
nixos-config/system/update-script.nix

37 lines
1.1 KiB
Nix
Raw Normal View History

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 gcRetentionDays;
2019-07-25 21:35:59 +00:00
configPath = "/etc/nixos";
update-system = writeHaskellScript {
name = "update-system";
imports = [ "qualified Data.ByteString.Lazy.Char8 as C" "qualified Data.List as L" ];
2019-07-26 13:54:30 +00:00
bins = [ get-niv-path config.system.build.nixos-rebuild ];
2019-07-25 21:35:59 +00:00
}
''
getNivPath = fmap C.unpack . readTrim . get_niv_path "${configPath}/nix/sources.nix"
getNivAssign name = fmap process . getNivPath $ name
where process str = ["-I", name ++ "=" ++ str]
main = do
paths <- fmap concat . mapM getNivAssign $ ["nixpkgs", "unstable", "home-manager"]
nixos_rebuild (paths ++ ["switch"])
'';
2019-07-26 13:54:30 +00:00
system-maintenance = writeHaskellScript
{ name = "system-maintenance"; bins = [ pkgs.nix pkgs.git update-system ];} ''
main = do
git "-C" "${configPath}" "pull"
update_system
nix_collect_garbage "--delete-older-than" "${toString gcRetentionDays}d"
nix "optimise-store"
'';
2019-07-25 21:35:59 +00:00
in
{
2019-07-26 13:54:30 +00:00
environment = {
systemPackages = [
update-system
system-maintenance
];
2019-07-25 21:35:59 +00:00
};
}