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

32 lines
1,015 B
Nix
Raw Normal View History

2019-07-26 15:31:26 +00:00
nixos-rebuild:
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 gcRetentionDays;
2019-07-25 21:35:59 +00:00
configPath = "/etc/nixos";
update-system = writeHaskellScript {
name = "update-system";
2019-07-26 15:31:26 +00:00
bins = [ get-niv-path nixos-rebuild ];
2019-07-25 21:35:59 +00:00
}
''
2019-07-26 15:31:26 +00:00
getNivPath = readTrim . get_niv_path "${configPath}/nix/sources.nix"
2019-07-25 21:35:59 +00:00
2019-07-26 15:31:26 +00:00
getNivAssign name = tag <$> getNivPath name
where tag str = ["-I", [i|#{name}=#{str :: LBS.ByteString}|] ]
2019-07-25 21:35:59 +00:00
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 15:31:26 +00:00
inherit update-system system-maintenance;
2019-07-25 21:35:59 +00:00
}