flake

Francesco Saccone's Nix flake.
git clone https://git.francescosaccone.com/flake
Log | Files | Refs | README | LICENSE

scripts.nix (3643B)


      1 {
      2   config,
      3   pkgs,
      4   inputs,
      5 }:
      6 let
      7   stagit = {
      8     createIndex =
      9       { destDir, reposDir }:
     10       ''
     11         ${pkgs.sbase}/bin/mkdir -p ${destDir}
     12 
     13         ${pkgs.stagit}/bin/stagit-index ${reposDir}/*/ > ${destDir}/index.html
     14 
     15         # Copy favicon.png, logo.png and stagit.css from site
     16         ${pkgs.sbase}/bin/cp \
     17           ${inputs.site}/public/icon/256.png \
     18           ${destDir}/favicon.png
     19 
     20         ${pkgs.sbase}/bin/cp \
     21           ${inputs.site}/public/icon/32.png \
     22           ${destDir}/logo.png
     23 
     24         ${pkgs.sbase}/bin/cp \
     25           ${inputs.site}/public/stagit.css \
     26           ${destDir}/style.css
     27 
     28         ${pkgs.sbase}/bin/echo "Stagit index generated: ${destDir}/index.html".
     29       '';
     30 
     31     createRepository =
     32       {
     33         destDir,
     34         reposDir,
     35         name,
     36         httpBaseUrl,
     37       }:
     38       ''
     39         ${pkgs.sbase}/bin/mkdir -p ${destDir}/${name}
     40         cd ${destDir}/${name}
     41         ${pkgs.stagit}/bin/stagit \
     42           -l 100 \
     43           -u ${httpBaseUrl}/${name}/ \
     44           ${reposDir}/${name}
     45 
     46         # Make the log.html file the index page as well
     47         ${pkgs.sbase}/bin/cp \
     48           ${destDir}/${name}/log.html \
     49           ${destDir}/${name}/index.html
     50 
     51         # Symlink favicon.png, logo.png and style.css in repos from
     52         # index
     53         ${pkgs.sbase}/bin/cp \
     54           ${destDir}/favicon.png \
     55           ${destDir}/${name}/favicon.png
     56 
     57         ${pkgs.sbase}/bin/cp \
     58           ${destDir}/logo.png \
     59           ${destDir}/${name}/logo.png
     60 
     61         ${pkgs.sbase}/bin/cp \
     62           ${destDir}/style.css \
     63           ${destDir}/${name}/style.css
     64 
     65         ${pkgs.sbase}/bin/echo \
     66           "Stagit page generated for ${name}: ${destDir}/${name}".
     67       '';
     68   };
     69 in
     70 {
     71   stagitCreate =
     72     {
     73       destDir,
     74       reposDir,
     75       httpBaseUrl,
     76     }:
     77     let
     78       createIndex = stagit.createIndex {
     79         inherit destDir reposDir;
     80       };
     81       createRepositories =
     82         config.modules.git.repositories
     83         |> builtins.attrNames
     84         |> builtins.map (
     85           name:
     86           stagit.createRepository {
     87             inherit
     88               destDir
     89               reposDir
     90               name
     91               httpBaseUrl
     92               ;
     93           }
     94         )
     95         |> builtins.concatStringsSep "\n";
     96 
     97       script = pkgs.writeShellScriptBin "stagit-create" ''
     98         ${createIndex}
     99         ${createRepositories}
    100       '';
    101     in
    102     "${script}/bin/stagit-create";
    103 
    104   stagitPostReceive =
    105     {
    106       destDir,
    107       reposDir,
    108       name,
    109       httpBaseUrl,
    110     }:
    111     let
    112       createIndex = stagit.createIndex {
    113         inherit destDir reposDir;
    114       };
    115       createRepositories = stagit.createRepository {
    116         inherit
    117           destDir
    118           reposDir
    119           name
    120           httpBaseUrl
    121           ;
    122       };
    123 
    124       script = pkgs.writeShellScriptBin "stagit" ''
    125         # Define is_force=1 if 'git push -f' was used
    126         null_ref="0000000000000000000000000000000000000000"
    127         is_force=0
    128         while read -r old new ref; do
    129           ${pkgs.sbase}/bin/test "$old" = $null_ref && continue
    130           ${pkgs.sbase}/bin/test "$new" = $null_ref && continue
    131 
    132           has_revs=$(${pkgs.git}/bin/git rev-list "$old" "^$new" | \
    133             ${pkgs.sbase}/bin/sed 1q)
    134 
    135           if ${pkgs.sbase}/bin/test -n "$has_revs"; then
    136             is_force=1
    137             break
    138           fi
    139         done
    140 
    141         # If is_force = 1, delete commits
    142         if ${pkgs.sbase}/bin/test $is_force = "1"; then
    143           ${pkgs.sbase}/bin/rm -rf ${reposDir}/${name}/commit
    144         fi
    145 
    146         ${createIndex}
    147         ${createRepositories}
    148       '';
    149     in
    150     "${script}/bin/stagit";
    151 }