nix fmt
This commit is contained in:
@@ -13,62 +13,63 @@
|
||||
util-linux ? null,
|
||||
}:
|
||||
assert syslogSupport -> util-linux != null;
|
||||
stdenv.mkDerivation rec {
|
||||
version = "2.0.4";
|
||||
pname = "btrfs-auto-snapshot";
|
||||
stdenv.mkDerivation rec {
|
||||
version = "2.0.4";
|
||||
pname = "btrfs-auto-snapshot";
|
||||
|
||||
src = fetchFromGitHub {
|
||||
owner = "hunleyd";
|
||||
repo = pname;
|
||||
rev = "v${version}";
|
||||
hash = "sha256-QpuwkGaYAkpu5hYyb360Mr5tHsZc2LzMlKtpS8CyyhI=";
|
||||
};
|
||||
src = fetchFromGitHub {
|
||||
owner = "hunleyd";
|
||||
repo = pname;
|
||||
rev = "v${version}";
|
||||
hash = "sha256-QpuwkGaYAkpu5hYyb360Mr5tHsZc2LzMlKtpS8CyyhI=";
|
||||
};
|
||||
|
||||
dontBuild = true;
|
||||
dontBuild = true;
|
||||
|
||||
nativeBuildInputs = [makeWrapper];
|
||||
nativeBuildInputs = [ makeWrapper ];
|
||||
|
||||
installPhase = ''
|
||||
install -Dm755 btrfs-auto-snapshot $out/bin/btrfs-auto-snapshot
|
||||
installPhase = ''
|
||||
install -Dm755 btrfs-auto-snapshot $out/bin/btrfs-auto-snapshot
|
||||
'';
|
||||
|
||||
wrapperPath =
|
||||
with lib;
|
||||
makeBinPath (
|
||||
[
|
||||
coreutils
|
||||
getopt
|
||||
gnugrep
|
||||
gnused
|
||||
gawk
|
||||
btrfs-progs
|
||||
]
|
||||
++ optional syslogSupport util-linux
|
||||
);
|
||||
|
||||
postFixup = ''
|
||||
wrapProgram $out/bin/btrfs-auto-snapshot \
|
||||
--prefix PATH : "${wrapperPath}"
|
||||
'';
|
||||
|
||||
meta = with lib; {
|
||||
description = "BTRFS Automatic Snapshot Service for Linux";
|
||||
homepage = "https://github.com/hunleyd/btrfs-auto-snapshot";
|
||||
license = licenses.gpl2;
|
||||
mainProgram = "btrfs-auto-snapshot";
|
||||
maintainers = with maintainers; [ motiejus ];
|
||||
platforms = platforms.linux;
|
||||
|
||||
longDescription = ''
|
||||
btrfs-auto-snapshot is a Bash script designed to bring as much of the
|
||||
functionality of the wonderful ZFS snapshot tool zfs-auto-snapshot to
|
||||
BTRFS as possible. Designed to run from cron (using
|
||||
/etc/cron.{daily,hourly,weekly}) it automatically creates a snapshot of
|
||||
the specified BTRFS filesystem (or, optionally, all of them) and then
|
||||
automatically purges the oldest snapshots of that type (hourly, daily, et
|
||||
al) based on a user-defined retention policy.
|
||||
|
||||
Snapshots are stored in a '.btrfs' directory at the root of the BTRFS
|
||||
filesystem being snapped and are read-only by default.
|
||||
'';
|
||||
|
||||
wrapperPath = with lib;
|
||||
makeBinPath (
|
||||
[
|
||||
coreutils
|
||||
getopt
|
||||
gnugrep
|
||||
gnused
|
||||
gawk
|
||||
btrfs-progs
|
||||
]
|
||||
++ optional syslogSupport util-linux
|
||||
);
|
||||
|
||||
postFixup = ''
|
||||
wrapProgram $out/bin/btrfs-auto-snapshot \
|
||||
--prefix PATH : "${wrapperPath}"
|
||||
'';
|
||||
|
||||
meta = with lib; {
|
||||
description = "BTRFS Automatic Snapshot Service for Linux";
|
||||
homepage = "https://github.com/hunleyd/btrfs-auto-snapshot";
|
||||
license = licenses.gpl2;
|
||||
mainProgram = "btrfs-auto-snapshot";
|
||||
maintainers = with maintainers; [motiejus];
|
||||
platforms = platforms.linux;
|
||||
|
||||
longDescription = ''
|
||||
btrfs-auto-snapshot is a Bash script designed to bring as much of the
|
||||
functionality of the wonderful ZFS snapshot tool zfs-auto-snapshot to
|
||||
BTRFS as possible. Designed to run from cron (using
|
||||
/etc/cron.{daily,hourly,weekly}) it automatically creates a snapshot of
|
||||
the specified BTRFS filesystem (or, optionally, all of them) and then
|
||||
automatically purges the oldest snapshots of that type (hourly, daily, et
|
||||
al) based on a user-defined retention policy.
|
||||
|
||||
Snapshots are stored in a '.btrfs' directory at the root of the BTRFS
|
||||
filesystem being snapped and are read-only by default.
|
||||
'';
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,64 +1,63 @@
|
||||
/*
|
||||
compressDrv compresses files in a given derivation.
|
||||
compressDrv compresses files in a given derivation.
|
||||
|
||||
Inputs:
|
||||
Inputs:
|
||||
|
||||
- formats :: [String]
|
||||
- formats :: [String]
|
||||
|
||||
List of file extensions to compress.
|
||||
List of file extensions to compress.
|
||||
|
||||
Example: ["txt" "svg" "xml"]
|
||||
Example: ["txt" "svg" "xml"]
|
||||
|
||||
- compressors :: {String -> String}
|
||||
- compressors :: {String -> String}
|
||||
|
||||
Map a desired extension (e.g. `gz`) to a compress program.
|
||||
Map a desired extension (e.g. `gz`) to a compress program.
|
||||
|
||||
The compressor program that will be executed to get the `COMPRESSOR`
|
||||
extension. The program should have a single " {}", which will be the
|
||||
replaced with the target filename.
|
||||
The compressor program that will be executed to get the `COMPRESSOR`
|
||||
extension. The program should have a single " {}", which will be the
|
||||
replaced with the target filename.
|
||||
|
||||
Compressor must:
|
||||
- read symlinks (thus --force is needed to gzip, zstd, xz).
|
||||
- keep the original file in place (--keep).
|
||||
Compressor must:
|
||||
- read symlinks (thus --force is needed to gzip, zstd, xz).
|
||||
- keep the original file in place (--keep).
|
||||
|
||||
Example:
|
||||
Example:
|
||||
|
||||
{
|
||||
xz = "${xz}/bin/xz --force --keep {}";
|
||||
}
|
||||
{
|
||||
xz = "${xz}/bin/xz --force --keep {}";
|
||||
}
|
||||
|
||||
See compressDrvWeb, which is a wrapper on top of compressDrv, for broader
|
||||
use examples.
|
||||
See compressDrvWeb, which is a wrapper on top of compressDrv, for broader
|
||||
use examples.
|
||||
*/
|
||||
{
|
||||
lib,
|
||||
xorg,
|
||||
runCommand,
|
||||
}: drv: {
|
||||
formats,
|
||||
compressors,
|
||||
...
|
||||
}: let
|
||||
validProg = ext: prog: let
|
||||
matches = (builtins.length (builtins.split "\\{}" prog) - 1) / 2;
|
||||
in
|
||||
lib.assertMsg
|
||||
(matches == 1)
|
||||
"compressor ${ext} needs to have exactly one '{}', found ${builtins.toString matches}";
|
||||
mkCmd = ext: prog:
|
||||
assert validProg ext prog; ''
|
||||
}:
|
||||
drv:
|
||||
{ formats, compressors, ... }:
|
||||
let
|
||||
validProg =
|
||||
ext: prog:
|
||||
let
|
||||
matches = (builtins.length (builtins.split "\\{}" prog) - 1) / 2;
|
||||
in
|
||||
lib.assertMsg (
|
||||
matches == 1
|
||||
) "compressor ${ext} needs to have exactly one '{}', found ${builtins.toString matches}";
|
||||
mkCmd =
|
||||
ext: prog:
|
||||
assert validProg ext prog;
|
||||
''
|
||||
find -L $out -type f -regextype posix-extended -iregex '.*\.(${formatsPipe})' -print0 \
|
||||
| xargs -0 -P$NIX_BUILD_CORES -I{} ${prog}
|
||||
'';
|
||||
formatsPipe = builtins.concatStringsSep "|" formats;
|
||||
in
|
||||
runCommand "${drv.name}-compressed" {} ''
|
||||
mkdir $out
|
||||
(cd $out; ${xorg.lndir}/bin/lndir ${drv})
|
||||
runCommand "${drv.name}-compressed" { } ''
|
||||
mkdir $out
|
||||
(cd $out; ${xorg.lndir}/bin/lndir ${drv})
|
||||
|
||||
${
|
||||
lib.concatStringsSep
|
||||
"\n\n"
|
||||
(lib.mapAttrsToList mkCmd compressors)
|
||||
}
|
||||
''
|
||||
${lib.concatStringsSep "\n\n" (lib.mapAttrsToList mkCmd compressors)}
|
||||
''
|
||||
|
||||
@@ -2,40 +2,41 @@
|
||||
gzip,
|
||||
runCommand,
|
||||
compressDrv,
|
||||
}: let
|
||||
example = runCommand "sample-drv" {} ''
|
||||
}:
|
||||
let
|
||||
example = runCommand "sample-drv" { } ''
|
||||
mkdir $out
|
||||
echo 42 > $out/1.txt
|
||||
echo 43 > $out/1.md
|
||||
touch $out/2.png
|
||||
'';
|
||||
drv = compressDrv example {
|
||||
formats = ["txt"];
|
||||
formats = [ "txt" ];
|
||||
compressors.gz = "${gzip}/bin/gzip --force --keep --fast {}";
|
||||
};
|
||||
wrapped = compressDrv drv {
|
||||
formats = ["md"];
|
||||
formats = [ "md" ];
|
||||
compressors.gz = "${gzip}/bin/gzip --force --keep --fast {}";
|
||||
};
|
||||
in
|
||||
runCommand "test-compressDrv" {} ''
|
||||
set -ex
|
||||
runCommand "test-compressDrv" { } ''
|
||||
set -ex
|
||||
|
||||
ls -l ${drv}
|
||||
test -h ${drv}/1.txt
|
||||
test -f ${drv}/1.txt.gz
|
||||
cmp ${drv}/1.txt <(${gzip}/bin/zcat ${drv}/1.txt.gz)
|
||||
ls -l ${drv}
|
||||
test -h ${drv}/1.txt
|
||||
test -f ${drv}/1.txt.gz
|
||||
cmp ${drv}/1.txt <(${gzip}/bin/zcat ${drv}/1.txt.gz)
|
||||
|
||||
test -h ${drv}/2.png
|
||||
test ! -a ${drv}/2.png.gz
|
||||
test -h ${drv}/2.png
|
||||
test ! -a ${drv}/2.png.gz
|
||||
|
||||
# compressDrv always points to the final file, no matter how many times
|
||||
# it's been wrapped
|
||||
cmp <(readlink -e ${drv}/1.txt) <(readlink -e ${wrapped}/1.txt)
|
||||
# compressDrv always points to the final file, no matter how many times
|
||||
# it's been wrapped
|
||||
cmp <(readlink -e ${drv}/1.txt) <(readlink -e ${wrapped}/1.txt)
|
||||
|
||||
test -f ${wrapped}/1.txt.gz
|
||||
test -f ${wrapped}/1.md.gz
|
||||
test ! -f ${drv}/1.md.gz
|
||||
test -f ${wrapped}/1.txt.gz
|
||||
test -f ${wrapped}/1.md.gz
|
||||
test ! -f ${drv}/1.md.gz
|
||||
|
||||
mkdir $out
|
||||
''
|
||||
mkdir $out
|
||||
''
|
||||
|
||||
@@ -1,83 +1,96 @@
|
||||
/*
|
||||
compressDrvWeb compresses a derivation for common web server use.
|
||||
compressDrvWeb compresses a derivation for common web server use.
|
||||
|
||||
Useful when one wants to pre-compress certain static assets and pass them to
|
||||
the web server. For example, `pkgs.gamja` creates this derivation:
|
||||
Useful when one wants to pre-compress certain static assets and pass them to
|
||||
the web server. For example, `pkgs.gamja` creates this derivation:
|
||||
|
||||
/nix/store/2wn1qbk8gp4y2m8xvafxv1b2dcdqj8fz-gamja-1.0.0-beta.9/
|
||||
├── index.2fd01148.js
|
||||
├── index.2fd01148.js.map
|
||||
├── index.37aa9a8a.css
|
||||
├── index.37aa9a8a.css.map
|
||||
├── index.html
|
||||
└── manifest.webmanifest
|
||||
/nix/store/2wn1qbk8gp4y2m8xvafxv1b2dcdqj8fz-gamja-1.0.0-beta.9/
|
||||
├── index.2fd01148.js
|
||||
├── index.2fd01148.js.map
|
||||
├── index.37aa9a8a.css
|
||||
├── index.37aa9a8a.css.map
|
||||
├── index.html
|
||||
└── manifest.webmanifest
|
||||
|
||||
`pkgs.compressDrvWeb pkgs.gamja`:
|
||||
`pkgs.compressDrvWeb pkgs.gamja`:
|
||||
|
||||
/nix/store/f5ryid7zrw2hid7h9kil5g5j29q5r2f7-gamja-1.0.0-beta.9-compressed
|
||||
├── index.2fd01148.js -> /nix/store/2wn1qbk8gp4y2m8xvafxv1b2dcdqj8fz-gamja-1.0.0-beta.9/index.2fd01148.js
|
||||
├── index.2fd01148.js.br
|
||||
├── index.2fd01148.js.gz
|
||||
├── index.2fd01148.js.map -> /nix/store/2wn1qbk8gp4y2m8xvafxv1b2dcdqj8fz-gamja-1.0.0-beta.9/index.2fd01148.js.map
|
||||
├── index.2fd01148.js.map.br
|
||||
├── index.2fd01148.js.map.gz
|
||||
├── index.37aa9a8a.css -> /nix/store/2wn1qbk8gp4y2m8xvafxv1b2dcdqj8fz-gamja-1.0.0-beta.9/index.37aa9a8a.css
|
||||
├── index.37aa9a8a.css.br
|
||||
├── index.37aa9a8a.css.gz
|
||||
├── index.37aa9a8a.css.map -> /nix/store/2wn1qbk8gp4y2m8xvafxv1b2dcdqj8fz-gamja-1.0.0-beta.9/index.37aa9a8a.css.map
|
||||
├── index.37aa9a8a.css.map.br
|
||||
├── index.37aa9a8a.css.map.gz
|
||||
├── index.html -> /nix/store/2wn1qbk8gp4y2m8xvafxv1b2dcdqj8fz-gamja-1.0.0-beta.9/index.html
|
||||
├── index.html.br
|
||||
├── index.html.gz
|
||||
├── manifest.webmanifest -> /nix/store/2wn1qbk8gp4y2m8xvafxv1b2dcdqj8fz-gamja-1.0.0-beta.9/manifest.webmanifest
|
||||
├── manifest.webmanifest.br
|
||||
└── manifest.webmanifest.gz
|
||||
/nix/store/f5ryid7zrw2hid7h9kil5g5j29q5r2f7-gamja-1.0.0-beta.9-compressed
|
||||
├── index.2fd01148.js -> /nix/store/2wn1qbk8gp4y2m8xvafxv1b2dcdqj8fz-gamja-1.0.0-beta.9/index.2fd01148.js
|
||||
├── index.2fd01148.js.br
|
||||
├── index.2fd01148.js.gz
|
||||
├── index.2fd01148.js.map -> /nix/store/2wn1qbk8gp4y2m8xvafxv1b2dcdqj8fz-gamja-1.0.0-beta.9/index.2fd01148.js.map
|
||||
├── index.2fd01148.js.map.br
|
||||
├── index.2fd01148.js.map.gz
|
||||
├── index.37aa9a8a.css -> /nix/store/2wn1qbk8gp4y2m8xvafxv1b2dcdqj8fz-gamja-1.0.0-beta.9/index.37aa9a8a.css
|
||||
├── index.37aa9a8a.css.br
|
||||
├── index.37aa9a8a.css.gz
|
||||
├── index.37aa9a8a.css.map -> /nix/store/2wn1qbk8gp4y2m8xvafxv1b2dcdqj8fz-gamja-1.0.0-beta.9/index.37aa9a8a.css.map
|
||||
├── index.37aa9a8a.css.map.br
|
||||
├── index.37aa9a8a.css.map.gz
|
||||
├── index.html -> /nix/store/2wn1qbk8gp4y2m8xvafxv1b2dcdqj8fz-gamja-1.0.0-beta.9/index.html
|
||||
├── index.html.br
|
||||
├── index.html.gz
|
||||
├── manifest.webmanifest -> /nix/store/2wn1qbk8gp4y2m8xvafxv1b2dcdqj8fz-gamja-1.0.0-beta.9/manifest.webmanifest
|
||||
├── manifest.webmanifest.br
|
||||
└── manifest.webmanifest.gz
|
||||
|
||||
When this `-compressed` directory is passed to a properly configured web
|
||||
server, it will serve those pre-compressed files:
|
||||
|
||||
When this `-compressed` directory is passed to a properly configured web
|
||||
server, it will serve those pre-compressed files:
|
||||
$ curl -I -H 'Accept-Encoding: br' https://irc.example.org/
|
||||
<...>
|
||||
content-encoding: br
|
||||
<...>
|
||||
|
||||
$ curl -I -H 'Accept-Encoding: br' https://irc.example.org/
|
||||
<...>
|
||||
content-encoding: br
|
||||
<...>
|
||||
For example, a caddy configuration snippet for gamja to serve
|
||||
the static assets (JS, CSS files) pre-compressed:
|
||||
|
||||
For example, a caddy configuration snippet for gamja to serve
|
||||
the static assets (JS, CSS files) pre-compressed:
|
||||
virtualHosts."irc.example.org".extraConfig = ''
|
||||
root * ${pkgs.compressDrvWeb pkgs.gamja {}}
|
||||
file_server browse {
|
||||
precompressed br gzip
|
||||
}
|
||||
'';
|
||||
|
||||
virtualHosts."irc.example.org".extraConfig = ''
|
||||
root * ${pkgs.compressDrvWeb pkgs.gamja {}}
|
||||
file_server browse {
|
||||
precompressed br gzip
|
||||
}
|
||||
'';
|
||||
This feature is also available in nginx via `ngx_brotli` and
|
||||
`ngx_http_gzip_static_module`.
|
||||
|
||||
This feature is also available in nginx via `ngx_brotli` and
|
||||
`ngx_http_gzip_static_module`.
|
||||
Inputs:
|
||||
- formats :: [String]
|
||||
|
||||
Inputs:
|
||||
- formats :: [String]
|
||||
List of file extensions to compress.
|
||||
|
||||
List of file extensions to compress.
|
||||
Default: common formats that compress well. The list may be expanded.
|
||||
|
||||
Default: common formats that compress well. The list may be expanded.
|
||||
- extraFormats :: [String]
|
||||
|
||||
- extraFormats :: [String]
|
||||
Extra extensions to compress in addition to `formats`.
|
||||
|
||||
Extra extensions to compress in addition to `formats`.
|
||||
- compressors :: {String -> String}
|
||||
|
||||
- compressors :: {String -> String}
|
||||
|
||||
See parameter `compressors` of compressDrv.
|
||||
See parameter `compressors` of compressDrv.
|
||||
*/
|
||||
{
|
||||
zopfli,
|
||||
brotli,
|
||||
compressDrv,
|
||||
}: drv: {
|
||||
formats ? ["css" "js" "svg" "ttf" "eot" "txt" "xml" "map" "html" "json" "webmanifest"],
|
||||
extraFormats ? [],
|
||||
}:
|
||||
drv:
|
||||
{
|
||||
formats ? [
|
||||
"css"
|
||||
"js"
|
||||
"svg"
|
||||
"ttf"
|
||||
"eot"
|
||||
"txt"
|
||||
"xml"
|
||||
"map"
|
||||
"html"
|
||||
"json"
|
||||
"webmanifest"
|
||||
],
|
||||
extraFormats ? [ ],
|
||||
compressors ? {
|
||||
"gz" = "${zopfli}/bin/zopfli --keep {}";
|
||||
"br" = "${brotli}/bin/brotli --keep --no-copy-stat {}";
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
{
|
||||
coreutils,
|
||||
writeShellApplication,
|
||||
}:
|
||||
{ coreutils, writeShellApplication }:
|
||||
writeShellApplication {
|
||||
name = "nicer";
|
||||
text = ''
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
{
|
||||
tmux,
|
||||
writeShellApplication,
|
||||
...
|
||||
}:
|
||||
{ tmux, writeShellApplication, ... }:
|
||||
writeShellApplication {
|
||||
name = "tmuxbash";
|
||||
text = ''
|
||||
|
||||
Reference in New Issue
Block a user