Created
January 5, 2026 15:37
-
-
Save kuuote/7caeca1f29f7e44c34efba4ac704d125 to your computer and use it in GitHub Desktop.
Nixのprofileを5件残して後は14日過ぎてたら掃除するやつ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Data.Function ((&)) | |
| import Data.Functor ((<&>)) | |
| import Data.List | |
| import Foreign.C.Types | |
| import System.Directory (getDirectoryContents, removeFile) | |
| import qualified System.Posix.Files as F | |
| import System.Posix.Time | |
| main = do | |
| let root = "/nix/var/nix/profiles/" | |
| paths <- getDirectoryContents root | |
| let oldpaths = paths & filter (isPrefixOf "system-") & sortBy (flip compare) & drop 5 | |
| oldpaths' <- oldpaths & map (\n -> let p = root ++ n in (F.getSymbolicLinkStatus p <&> \s -> (p, (F.modificationTime s)))) & sequence | |
| ago14 <- epochTime <&> \now -> now - 14 * 24 * 60 * 60 | |
| let targets = oldpaths' & filter (\(_, m) -> m < ago14) & map (\(p, _) -> p) | |
| mapM_ (\p -> removeFile p >>= \_ -> putStrLn p) targets |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment