This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

superconfig / tools / name-generator / flake-module.nix
1.9 kB 59 lines
1{ ... }: 2{ 3 perSystem = 4 { pkgs, ... }: 5 let 6 dataFiles = pkgs.stdenv.mkDerivation { 7 name = "name-generator-data"; 8 src = ./.; 9 installPhase = '' 10 mkdir -p $out 11 cp adjectives.txt nouns.txt $out/ 12 ''; 13 }; 14 in 15 { 16 packages.name-generator = 17 (pkgs.writeShellApplication { 18 name = "name-generator"; 19 runtimeInputs = [ pkgs.bash ]; 20 text = '' 21 # Data files location 22 DATA_DIR="${dataFiles}" 23 # Default separator 24 SEPARATOR="-" 25 # Parse command line options 26 while [[ $# -gt 0 ]]; do 27 case $1 in 28 -s|--separator) 29 SEPARATOR="$2" 30 shift 2 31 ;; 32 -h|--help) 33 echo "Usage: $0 [OPTIONS]" 34 echo "Generate a random name in the format: adjective-noun" 35 echo "" 36 echo "Options:" 37 echo " -s, --separator CHAR Use CHAR as separator (default: -)" 38 echo " -h, --help Show this help message" 39 exit 0 40 ;; 41 *) 42 echo "Unknown option: $1" 43 exit 1 44 ;; 45 esac 46 done 47 # Read adjectives and nouns 48 mapfile -t ADJECTIVES < "$DATA_DIR/adjectives.txt" 49 mapfile -t NOUNS < "$DATA_DIR/nouns.txt" 50 # Select random adjective and noun 51 ADJ_INDEX=$((RANDOM % ''${#ADJECTIVES[@]})) 52 NOUN_INDEX=$((RANDOM % ''${#NOUNS[@]})) 53 # Output the generated name 54 echo "''${ADJECTIVES[$ADJ_INDEX]}''${SEPARATOR}''${NOUNS[$NOUN_INDEX]}" 55 ''; 56 }).overrideAttrs 57 { passthru.usage = builtins.readFile ./usage.kdl; }; 58 }; 59}