lol

angrr: init at 0.1.1 (#439121)

authored by

Sandro and committed by
GitHub
dc85fea6 568573b1

+245
+2
nixos/doc/manual/release-notes/rl-2511.section.md
··· 84 84 85 85 - [dwl](https://codeberg.org/dwl/dwl), a compact, hackable compositor for Wayland based on wlroots. Available as [programs.dwl](#opt-programs.dwl.enable). 86 86 87 + - [angrr](https://github.com/linyinfeng/angrr), a service that automatically cleans up old auto GC roots. Available as [services.angrr](#opt-services.angrr.enable). 88 + 87 89 - [Sharkey](https://joinsharkey.org), a Sharkish microblogging platform. Available as [services.sharkey](#opt-services.sharkey.enable). 88 90 89 91 - [fw-fanctrl](https://github.com/TamtamHero/fw-fanctrl), a simple systemd service to better control Framework Laptop's fan(s). Available as [hardware.fw-fanctrl](#opt-hardware.fw-fanctrl.enable).
+1
nixos/modules/module-list.nix
··· 788 788 ./services/misc/airsonic.nix 789 789 ./services/misc/amazon-ssm-agent.nix 790 790 ./services/misc/ananicy.nix 791 + ./services/misc/angrr.nix 791 792 ./services/misc/anki-sync-server.nix 792 793 ./services/misc/apache-kafka.nix 793 794 ./services/misc/atuin.nix
+128
nixos/modules/services/misc/angrr.nix
··· 1 + { 2 + config, 3 + lib, 4 + pkgs, 5 + ... 6 + }: 7 + 8 + let 9 + cfg = config.services.angrr; 10 + in 11 + { 12 + meta.maintainers = pkgs.angrr.meta.maintainers; 13 + options = { 14 + services.angrr = { 15 + enable = lib.mkEnableOption "angrr"; 16 + package = lib.mkPackageOption pkgs "angrr" { }; 17 + period = lib.mkOption { 18 + type = lib.types.str; 19 + default = "7d"; 20 + example = "2weeks"; 21 + description = '' 22 + The retention period of auto GC roots. 23 + ''; 24 + }; 25 + removeRoot = lib.mkOption { 26 + type = lib.types.bool; 27 + default = false; 28 + description = '' 29 + Whether to pass the `--remove-root` option to angrr. 30 + ''; 31 + }; 32 + ownedOnly = lib.mkOption { 33 + type = lib.types.bool; 34 + default = false; 35 + description = '' 36 + Control the `--remove-root=<true|false>` option of angrr. 37 + ''; 38 + apply = b: if b then "true" else "false"; 39 + }; 40 + logLevel = lib.mkOption { 41 + type = 42 + with lib.types; 43 + enum [ 44 + "off" 45 + "error" 46 + "warn" 47 + "info" 48 + "debug" 49 + "trace" 50 + ]; 51 + default = "info"; 52 + description = '' 53 + Set the log level of angrr. 54 + ''; 55 + }; 56 + extraArgs = lib.mkOption { 57 + type = with lib.types; listOf str; 58 + default = [ ]; 59 + description = '' 60 + Extra command-line arguments pass to angrr. 61 + ''; 62 + }; 63 + enableNixGcIntegration = lib.mkOption { 64 + type = lib.types.bool; 65 + description = '' 66 + Whether to enable nix-gc.service integration 67 + ''; 68 + }; 69 + timer = { 70 + enable = lib.mkEnableOption "angrr timer"; 71 + dates = lib.mkOption { 72 + type = lib.types.str; 73 + default = "03:00"; 74 + description = '' 75 + How often or when the retention policy is performed. 76 + ''; 77 + }; 78 + }; 79 + }; 80 + }; 81 + 82 + config = lib.mkIf cfg.enable ( 83 + lib.mkMerge [ 84 + { 85 + assertions = [ 86 + { 87 + assertion = cfg.enableNixGcIntegration -> config.nix.gc.automatic; 88 + message = "angrr nix-gc.service integration requires `nix.gc.automatic = true`"; 89 + } 90 + ]; 91 + services.angrr.enableNixGcIntegration = lib.mkDefault config.nix.gc.automatic; 92 + } 93 + 94 + { 95 + systemd.services.angrr = { 96 + description = "Auto Nix GC Roots Retention"; 97 + script = '' 98 + ${lib.getExe cfg.package} run \ 99 + --log-level "${cfg.logLevel}" \ 100 + --period "${cfg.period}" \ 101 + ${lib.optionalString cfg.removeRoot "--remove-root"} \ 102 + --owned-only="${cfg.ownedOnly}" \ 103 + --no-prompt ${lib.escapeShellArgs cfg.extraArgs} 104 + ''; 105 + serviceConfig = { 106 + Type = "oneshot"; 107 + }; 108 + }; 109 + } 110 + 111 + (lib.mkIf cfg.timer.enable { 112 + systemd.timers.angrr = { 113 + timerConfig = { 114 + OnCalendar = cfg.timer.dates; 115 + }; 116 + wantedBy = [ "timers.target" ]; 117 + }; 118 + }) 119 + 120 + (lib.mkIf cfg.enableNixGcIntegration { 121 + systemd.services.angrr = { 122 + wantedBy = [ "nix-gc.service" ]; 123 + before = [ "nix-gc.service" ]; 124 + }; 125 + }) 126 + ] 127 + ); 128 + }
+1
nixos/tests/all-tests.nix
··· 210 210 amd-sev = runTest ./amd-sev.nix; 211 211 android-translation-layer = runTest ./android-translation-layer.nix; 212 212 angie-api = runTest ./angie-api.nix; 213 + angrr = runTest ./angrr.nix; 213 214 anki-sync-server = runTest ./anki-sync-server.nix; 214 215 anubis = runTest ./anubis.nix; 215 216 anuko-time-tracker = runTest ./anuko-time-tracker.nix;
+63
nixos/tests/angrr.nix
··· 1 + { ... }: 2 + { 3 + name = "angrr"; 4 + nodes = { 5 + machine = { 6 + services.angrr = { 7 + enable = true; 8 + period = "7d"; 9 + }; 10 + # `angrr.service` integrates to `nix-gc.service` by default 11 + nix.gc.automatic = true; 12 + 13 + # Create a normal nix user for test 14 + users.users.normal.isNormalUser = true; 15 + # For `nix build /run/current-system --out-link`, 16 + # `nix-build` does not support this use case. 17 + nix.settings.experimental-features = [ "nix-command" ]; 18 + }; 19 + }; 20 + 21 + testScript = '' 22 + start_all() 23 + 24 + machine.wait_for_unit("default.target") 25 + 26 + machine.systemctl("stop nix-gc.timer") 27 + 28 + # Creates some auto gc roots 29 + # Use /run/current-system so that we do not need to build anything new 30 + machine.succeed("nix build /run/current-system --out-link /tmp/root-auto-gc-root-1") 31 + machine.succeed("nix build /run/current-system --out-link /tmp/root-auto-gc-root-2") 32 + machine.succeed("su normal --command 'nix build /run/current-system --out-link /tmp/user-auto-gc-root-1'") 33 + machine.succeed("su normal --command 'nix build /run/current-system --out-link /tmp/user-auto-gc-root-2'") 34 + 35 + machine.systemctl("start nix-gc.service") 36 + # Not auto gc root will be removed 37 + machine.succeed("readlink /tmp/root-auto-gc-root-1") 38 + machine.succeed("readlink /tmp/root-auto-gc-root-2") 39 + machine.succeed("readlink /tmp/user-auto-gc-root-1") 40 + machine.succeed("readlink /tmp/user-auto-gc-root-2") 41 + 42 + # Change time to 8 days after (greater than 7d) 43 + machine.succeed("date -s '8 days'") 44 + 45 + # Touch GC roots `-2` 46 + machine.succeed("touch /tmp/root-auto-gc-root-2 --no-dereference") 47 + machine.succeed("touch /tmp/user-auto-gc-root-2 --no-dereference") 48 + 49 + machine.systemctl("start nix-gc.service") 50 + # Only GC roots `-1` are removed 51 + machine.succeed("test ! -f /tmp/root-auto-gc-root-1") 52 + machine.succeed("readlink /tmp/root-auto-gc-root-2") 53 + machine.succeed("test ! -f /tmp/user-auto-gc-root-1") 54 + machine.succeed("readlink /tmp/user-auto-gc-root-2") 55 + 56 + # Change time again 57 + machine.succeed("date -s '8 days'") 58 + machine.systemctl("start nix-gc.service") 59 + # All auto GC roots are removed 60 + machine.succeed("test ! -f /tmp/root-auto-gc-root-2") 61 + machine.succeed("test ! -f /tmp/user-auto-gc-root-2") 62 + ''; 63 + }
+50
pkgs/by-name/an/angrr/package.nix
··· 1 + { 2 + lib, 3 + rustPlatform, 4 + fetchFromGitHub, 5 + installShellFiles, 6 + nixosTests, 7 + testers, 8 + nix-update-script, 9 + }: 10 + 11 + rustPlatform.buildRustPackage (finalAttrs: { 12 + pname = "angrr"; 13 + version = "0.1.1"; 14 + 15 + src = fetchFromGitHub { 16 + owner = "linyinfeng"; 17 + repo = "angrr"; 18 + tag = "v${finalAttrs.version}"; 19 + hash = "sha256-SL4UBDoD0pvpCKokQvKLAcS9cQJaFiA+IjswFARswdM="; 20 + }; 21 + 22 + cargoHash = "sha256-lo9JpsHkvyrEqFnIiGlU2o4rREeQeqWpe9WMwisvw+4="; 23 + 24 + nativeBuildInputs = [ installShellFiles ]; 25 + postInstall = '' 26 + installShellCompletion --cmd angrr \ 27 + --bash <($out/bin/angrr completion bash) \ 28 + --fish <($out/bin/angrr completion fish) \ 29 + --zsh <($out/bin/angrr completion zsh) 30 + ''; 31 + 32 + passthru = { 33 + tests = { 34 + module = nixosTests.angrr; 35 + version = testers.testVersion { 36 + package = finalAttrs.finalPackage; 37 + }; 38 + }; 39 + updateScript = nix-update-script { }; 40 + }; 41 + 42 + meta = { 43 + description = "Tool for auto Nix GC roots retention"; 44 + homepage = "https://github.com/linyinfeng/angrr"; 45 + license = [ lib.licenses.mit ]; 46 + maintainers = with lib.maintainers; [ yinfeng ]; 47 + platforms = with lib.platforms; linux ++ darwin; 48 + mainProgram = "angrr"; 49 + }; 50 + })