liminix

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit b0098f1c8e05251695ec63707067dc0be321bd6b
parent 68ab6faeb3f9c1b9f63614372c2ca75355731974
Author: Daniel Barlow <dan@telent.net>
Date:   Sat, 20 May 2023 21:09:22 +0100

move min-list-garbage into min-collect-garbage pkg

we don't want it in the same package as min-copy-closure as
that depends on bash

Diffstat:
Mpkgs/default.nix | 1+
Apkgs/min-collect-garbage/default.nix | 17+++++++++++++++++
Apkgs/min-collect-garbage/min-collect-garbage.sh | 3+++
Apkgs/min-collect-garbage/min-list-garbage.c | 78++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mpkgs/min-copy-closure/default.nix | 2--
Dpkgs/min-copy-closure/min-list-garbage.c | 79-------------------------------------------------------------------------------
6 files changed, 99 insertions(+), 81 deletions(-)

diff --git a/pkgs/default.nix b/pkgs/default.nix @@ -46,6 +46,7 @@ openwrt = callPackage ./openwrt {}; initramfs-peek = callPackage ./initramfs-peek {}; + min-collect-garbage = callPackage ./min-collect-garbage {}; min-copy-closure = callPackage ./min-copy-closure {}; hi = callPackage ./hi {}; } diff --git a/pkgs/min-collect-garbage/default.nix b/pkgs/min-collect-garbage/default.nix @@ -0,0 +1,17 @@ +{ + stdenv +, nix +, cpio +, openssh +}: stdenv.mkDerivation { + name = "min-collect-garbage"; + buildInputs = [ ]; +# propagatedBuildInputs = [ openssh ]; + src = ./.; + makeFlags = [ "min-list-garbage" ]; + installPhase = '' + mkdir -p $out/bin + cp min-collect-garbage.sh $out/bin/min-collect-garbage + cp min-list-garbage $out/bin + ''; +} diff --git a/pkgs/min-collect-garbage/min-collect-garbage.sh b/pkgs/min-collect-garbage/min-collect-garbage.sh @@ -0,0 +1,3 @@ +#!/bin/sh +test -f /persist/nix-store-paths || exit 1 +(cd /nix/store && min-list-garbage /persist/nix-store-paths | xargs rm -r) diff --git a/pkgs/min-collect-garbage/min-list-garbage.c b/pkgs/min-collect-garbage/min-list-garbage.c @@ -0,0 +1,78 @@ +#include <dirent.h> +#include <stdio.h> +#include <stdlib.h> +#include <sys/types.h> +#include <string.h> +#include <unistd.h> + +typedef char hash_t[32]; +hash_t *hash_list = NULL; +int hash_list_entries = 0; +int hash_list_size = 0; + +int add_list_entry(char *name) +{ + name += strlen("/nix/store/"); + if(hash_list_entries >= hash_list_size) { + if(hash_list_size == 0) hash_list_size = 4; + hash_list_size = hash_list_size * 2; + hash_list = realloc(hash_list, hash_list_size * sizeof(hash_t)); + } + strncpy(hash_list[hash_list_entries++], name, 32); +} + +int read_list(char *filename) +{ + char s[1024]; + FILE *fp; + if(fp = fopen(filename, "r")) { + while(fgets(s, 1024, fp)) { + if(strrchr(s, '\n')) { + add_list_entry(s); + } else { + puts("hash list entry too long"); + exit(1); + } + } + } + fclose(fp); +} + +int on_list(char *name) +{ + int i; + for(i = 0; i < hash_list_entries; i++) { + if(!strncmp(hash_list[i], name, 32)) { + return 1; + } + } + return 0; +} + +int main(int argc, char * argv[]) +{ + struct dirent * de; + DIR * dirp; + char hash[32]; + + if(argc < 2) { + puts("Usage: min-list-garbage store-paths-file\n\nChecks all store paths against the list of expected paths in store-paths-file,\n and prints any which are present unexpectedly"); + exit(1); + } + + read_list(argv[1]); + + if((dirp = opendir("/nix/store")) == NULL) { + puts("can't open /nix/store"); + exit(1); + } + + while(de = readdir(dirp)) { + if(strlen(de->d_name) >= 32) { + strncpy(hash, de->d_name, 32); + if(!on_list(hash)) puts(de->d_name); + } + } + + closedir(dirp); +} diff --git a/pkgs/min-copy-closure/default.nix b/pkgs/min-copy-closure/default.nix @@ -8,13 +8,11 @@ buildInputs = [ ]; propagatedBuildInputs = [ cpio openssh nix ]; src = ./.; - makeFlags = [ "min-list-garbage" ]; installPhase = '' mkdir -p $out/bin for i in min-copy-closure liminix-rebuild; do echo $i cp ''${i}.sh $out/bin/$i done - cp min-list-garbage $out/bin ''; } diff --git a/pkgs/min-copy-closure/min-list-garbage.c b/pkgs/min-copy-closure/min-list-garbage.c @@ -1,79 +0,0 @@ -#include <dirent.h> -#include <stdio.h> -#include <stdlib.h> -#include <sys/types.h> -#include <string.h> -#include <unistd.h> - -typedef char hash_t[32]; -hash_t *hash_list = NULL; -int hash_list_entries = 0; -int hash_list_size = 0; - -int add_list_entry(char *name) -{ - name += strlen("/nix/store/"); - if(hash_list_entries >= hash_list_size) { - if(hash_list_size == 0) hash_list_size = 4; - hash_list_size = hash_list_size * 2; - hash_list = realloc(hash_list, hash_list_size * sizeof(hash_t)); - } - strncpy(hash_list[hash_list_entries++], name, 32); - printf("%d %d\n", hash_list_entries, hash_list_size); -} - -int read_list(char *filename) -{ - char s[1024]; - FILE *fp; - if(fp = fopen(filename, "r")) { - while(fgets(s, 1024, fp)) { - if(strrchr(s, '\n')) { - add_list_entry(s); - } else { - puts("hash list entry too long"); - exit(1); - } - } - } - fclose(fp); -} - -int on_list(char *name) -{ - int i; - for(i = 0; i < hash_list_entries; i++) { - if(!strncmp(hash_list[i], name, 32)) { - return 1; - } - } - return 0; -} - -int main(int argc, char * argv[]) -{ - struct dirent * de; - DIR * dirp; - char hash[32]; - - if(argc < 2) { - puts("Usage: min-list-garbage store-paths-file\n\nChecks all store paths against the list of expected paths in store-paths-file,\n and prints any which are present unexpectedly"); - exit(1); - } - - read_list(argv[1]); - - if((dirp = opendir("/nix/store")) == NULL) { - puts("can't open /nix/store"); - exit(1); - } - - while(de = readdir(dirp)) { - if(strlen(de->d_name) >= 32) { - strncpy(hash, de->d_name, 32); - if(!on_list(hash)) puts(de->d_name); - } - } - - closedir(dirp); -}