mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-20 16:15:43 +02:00
update-scripts: move out of flake
See the explanation in the new update-scripts/README.md file.
This commit is contained in:
parent
96d0a2e390
commit
d3cb750e6a
10 changed files with 146 additions and 88 deletions
5
.github/workflows/update.yml
vendored
5
.github/workflows/update.yml
vendored
|
@ -64,11 +64,12 @@ jobs:
|
||||||
echo "EOF" >> "$GITHUB_OUTPUT"
|
echo "EOF" >> "$GITHUB_OUTPUT"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
- name: Update autogenerated files
|
- name: Update generated files
|
||||||
id: generate
|
id: generate
|
||||||
run: |
|
run: |
|
||||||
old=$(git show --no-patch --format=%h)
|
old=$(git show --no-patch --format=%h)
|
||||||
nix run .#generate-files -- --commit
|
nix-build ./update-scripts -A generate
|
||||||
|
./result/bin/generate --commit
|
||||||
new=$(git show --no-patch --format=%h)
|
new=$(git show --no-patch --format=%h)
|
||||||
if [ "$old" != "$new" ]; then
|
if [ "$old" != "$new" ]; then
|
||||||
body=$(git show --no-patch --format=%b)
|
body=$(git show --no-patch --format=%b)
|
||||||
|
|
|
@ -10,11 +10,10 @@
|
||||||
./templates.nix
|
./templates.nix
|
||||||
./tests.nix
|
./tests.nix
|
||||||
./wrappers.nix
|
./wrappers.nix
|
||||||
./updates
|
|
||||||
];
|
];
|
||||||
|
|
||||||
perSystem =
|
perSystem =
|
||||||
{ pkgs, system, ... }:
|
{ system, ... }:
|
||||||
{
|
{
|
||||||
_module.args = {
|
_module.args = {
|
||||||
pkgsUnfree = import inputs.nixpkgs {
|
pkgsUnfree = import inputs.nixpkgs {
|
||||||
|
|
|
@ -1,84 +0,0 @@
|
||||||
{
|
|
||||||
perSystem =
|
|
||||||
{ pkgs, config, ... }:
|
|
||||||
{
|
|
||||||
apps.generate-files.program = pkgs.writeShellApplication {
|
|
||||||
name = "generate-files";
|
|
||||||
|
|
||||||
runtimeInputs = [ pkgs.nixfmt-rfc-style ];
|
|
||||||
|
|
||||||
text = ''
|
|
||||||
repo_root=$(git rev-parse --show-toplevel)
|
|
||||||
generated_dir=$repo_root/generated
|
|
||||||
|
|
||||||
commit=
|
|
||||||
while [ $# -gt 0 ]; do
|
|
||||||
case "$1" in
|
|
||||||
--commit) commit=1
|
|
||||||
;;
|
|
||||||
--*) echo "unknown option $1"
|
|
||||||
;;
|
|
||||||
*) echo "unexpected argument $1"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
shift
|
|
||||||
done
|
|
||||||
|
|
||||||
generate() {
|
|
||||||
echo "$2"
|
|
||||||
cp "$1" "$generated_dir/$2.nix"
|
|
||||||
nixfmt "$generated_dir/$2.nix"
|
|
||||||
}
|
|
||||||
|
|
||||||
mkdir -p "$generated_dir"
|
|
||||||
generate "${config.packages.rust-analyzer-options}" "rust-analyzer"
|
|
||||||
generate "${config.packages.efmls-configs-sources}" "efmls-configs"
|
|
||||||
generate "${config.packages.none-ls-builtins}" "none-ls"
|
|
||||||
|
|
||||||
if [ -n "$commit" ]; then
|
|
||||||
cd "$generated_dir"
|
|
||||||
git add .
|
|
||||||
|
|
||||||
# Construct a msg body from `git status -- .`
|
|
||||||
body=$(
|
|
||||||
git status \
|
|
||||||
--short \
|
|
||||||
--ignored=no \
|
|
||||||
--untracked-files=no \
|
|
||||||
--no-ahead-behind \
|
|
||||||
-- . \
|
|
||||||
| sed \
|
|
||||||
-e 's/^\s*\([A-Z]\)\s*/\1 /' \
|
|
||||||
-e 's/^A/Added/' \
|
|
||||||
-e 's/^M/Updated/' \
|
|
||||||
-e 's/^R/Renamed/' \
|
|
||||||
-e 's/^D/Removed/' \
|
|
||||||
-e 's/^/- /'
|
|
||||||
)
|
|
||||||
|
|
||||||
# Construct the commit message based on the body
|
|
||||||
# NOTE: Can't use `wc -l` due to how `echo` pipes its output
|
|
||||||
count=$(echo -n "$body" | awk 'END {print NR}')
|
|
||||||
if [ "$count" -gt 1 ] || [ ''${#body} -gt 50 ]; then
|
|
||||||
msg=$(echo -e "generated: Update\n\n$body")
|
|
||||||
else
|
|
||||||
msg="generated:''${body:1}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Commit if there are changes
|
|
||||||
if [ "$count" -gt 0 ]; then
|
|
||||||
echo "Committing $count changes..."
|
|
||||||
echo "$msg"
|
|
||||||
git commit -m "$msg" --no-verify
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
|
|
||||||
packages = {
|
|
||||||
rust-analyzer-options = pkgs.callPackage ./rust-analyzer.nix { };
|
|
||||||
efmls-configs-sources = pkgs.callPackage ./efmls-configs.nix { };
|
|
||||||
none-ls-builtins = pkgs.callPackage ./none-ls.nix { };
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
30
update-scripts/README.md
Normal file
30
update-scripts/README.md
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
# Update scripts
|
||||||
|
|
||||||
|
This directory contains update scripts that are not part of the actual flake.
|
||||||
|
|
||||||
|
These scripts are used by the `update` CI workflow, so you shouldn't need to run them manually.
|
||||||
|
This workflow is found at `.github/workflows/update.yml`.
|
||||||
|
|
||||||
|
## Developing
|
||||||
|
|
||||||
|
Because these scripts aren't packaged in the flake, you should use `nix-build` and `nix-shell` instead of `nix build`, `nix run`, and `nix develop`, etc.
|
||||||
|
|
||||||
|
For example, `nix-build -A generate` will build `./generate.nix` into `./result/bin/generate`.
|
||||||
|
|
||||||
|
A `shell.nix` is available that will place `generate` on your PATH.
|
||||||
|
|
||||||
|
You could use this directory's shell/packages from another working directory by supplying `nix-build` or `nix-shell` with a path.
|
||||||
|
E.g. `nix-shell ./update-scripts`.
|
||||||
|
|
||||||
|
## Explanation
|
||||||
|
|
||||||
|
These packages are not in the flake outputs for two main reasons:
|
||||||
|
- Packages built using the flake must follow the flake's `nixConfig`
|
||||||
|
- Packages included in the flake's output are checked by `nix flake check`
|
||||||
|
|
||||||
|
Being unable to bypass `nixConfig` is an issue because we want to disable [IFD] for the flake, but not for these generate scripts.
|
||||||
|
|
||||||
|
If something changes upstream that causes the builds to fail, we don't want this to block us updating `flake.lock`.
|
||||||
|
We'd still be made aware of any issues by the `update` CI workflow failing.
|
||||||
|
|
||||||
|
[IFD]: https://nixos.org/manual/nix/stable/language/import-from-derivation
|
29
update-scripts/default.nix
Normal file
29
update-scripts/default.nix
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
{
|
||||||
|
# By default, import nixpkgs from flake.lock
|
||||||
|
pkgs ?
|
||||||
|
let
|
||||||
|
lock = (builtins.fromJSON (builtins.readFile ../flake.lock)).nodes.nixpkgs.locked;
|
||||||
|
nixpkgs = fetchTarball {
|
||||||
|
url =
|
||||||
|
assert lock.type == "github";
|
||||||
|
"https://github.com/${lock.owner}/${lock.repo}/archive/${lock.rev}.tar.gz";
|
||||||
|
sha256 = lock.narHash;
|
||||||
|
};
|
||||||
|
in
|
||||||
|
import nixpkgs { },
|
||||||
|
lib ? pkgs.lib,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
lib.fix (self: {
|
||||||
|
# The main script
|
||||||
|
default = self.generate;
|
||||||
|
generate = lib.callPackageWith (pkgs // self) ./generate.nix { };
|
||||||
|
|
||||||
|
# A shell that has the generate script
|
||||||
|
shell = pkgs.mkShell { nativeBuildInputs = [ self.generate ]; };
|
||||||
|
|
||||||
|
# Derivations that build the generated files
|
||||||
|
efmls-configs-sources = pkgs.callPackage ./efmls-configs.nix { };
|
||||||
|
none-ls-builtins = pkgs.callPackage ./none-ls.nix { };
|
||||||
|
rust-analyzer-options = pkgs.callPackage ./rust-analyzer.nix { };
|
||||||
|
})
|
79
update-scripts/generate.nix
Normal file
79
update-scripts/generate.nix
Normal file
|
@ -0,0 +1,79 @@
|
||||||
|
{
|
||||||
|
writeShellApplication,
|
||||||
|
rust-analyzer-options,
|
||||||
|
efmls-configs-sources,
|
||||||
|
none-ls-builtins,
|
||||||
|
nixfmt-rfc-style,
|
||||||
|
}:
|
||||||
|
writeShellApplication {
|
||||||
|
name = "generate";
|
||||||
|
|
||||||
|
runtimeInputs = [ nixfmt-rfc-style ];
|
||||||
|
|
||||||
|
text = ''
|
||||||
|
repo_root=$(git rev-parse --show-toplevel)
|
||||||
|
generated_dir=$repo_root/generated
|
||||||
|
|
||||||
|
commit=
|
||||||
|
while [ $# -gt 0 ]; do
|
||||||
|
case "$1" in
|
||||||
|
--commit) commit=1
|
||||||
|
;;
|
||||||
|
--*) echo "unknown option $1"
|
||||||
|
;;
|
||||||
|
*) echo "unexpected argument $1"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
|
generate() {
|
||||||
|
echo "$2"
|
||||||
|
cp "$1" "$generated_dir/$2.nix"
|
||||||
|
nixfmt "$generated_dir/$2.nix"
|
||||||
|
}
|
||||||
|
|
||||||
|
mkdir -p "$generated_dir"
|
||||||
|
generate "${rust-analyzer-options}" "rust-analyzer"
|
||||||
|
generate "${efmls-configs-sources}" "efmls-configs"
|
||||||
|
generate "${none-ls-builtins}" "none-ls"
|
||||||
|
|
||||||
|
if [ -n "$commit" ]; then
|
||||||
|
cd "$generated_dir"
|
||||||
|
git add .
|
||||||
|
|
||||||
|
# Construct a msg body from `git status -- .`
|
||||||
|
body=$(
|
||||||
|
git status \
|
||||||
|
--short \
|
||||||
|
--ignored=no \
|
||||||
|
--untracked-files=no \
|
||||||
|
--no-ahead-behind \
|
||||||
|
-- . \
|
||||||
|
| sed \
|
||||||
|
-e 's/^\s*\([A-Z]\)\s*/\1 /' \
|
||||||
|
-e 's/^A/Added/' \
|
||||||
|
-e 's/^M/Updated/' \
|
||||||
|
-e 's/^R/Renamed/' \
|
||||||
|
-e 's/^D/Removed/' \
|
||||||
|
-e 's/^/- /'
|
||||||
|
)
|
||||||
|
|
||||||
|
# Construct the commit message based on the body
|
||||||
|
# NOTE: Can't use `wc -l` due to how `echo` pipes its output
|
||||||
|
count=$(echo -n "$body" | awk 'END {print NR}')
|
||||||
|
if [ "$count" -gt 1 ] || [ ''${#body} -gt 50 ]; then
|
||||||
|
msg=$(echo -e "generated: Update\n\n$body")
|
||||||
|
else
|
||||||
|
msg="generated:''${body:1}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Commit if there are changes
|
||||||
|
if [ "$count" -gt 0 ]; then
|
||||||
|
echo "Committing $count changes..."
|
||||||
|
echo "$msg"
|
||||||
|
git commit -m "$msg" --no-verify
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
'';
|
||||||
|
}
|
4
update-scripts/shell.nix
Normal file
4
update-scripts/shell.nix
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
let
|
||||||
|
packages = import ./. { };
|
||||||
|
in
|
||||||
|
packages.shell
|
Loading…
Add table
Add a link
Reference in a new issue