Skip to content

Commit

Permalink
added formatter + reformat existing codebase (nix-community#175)
Browse files Browse the repository at this point in the history
  • Loading branch information
GaetanLepage authored Feb 20, 2023
1 parent 0bf4313 commit 264de8c
Show file tree
Hide file tree
Showing 96 changed files with 3,705 additions and 3,319 deletions.
14 changes: 8 additions & 6 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
(import (
fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/c75e76f80c57784a6734356315b306140646ee84.tar.gz";
sha256 = "071aal00zp2m9knnhddgr2wqzlx6i6qa1263lv1y7bdn2w20h10h"; }
) {
src = ./.;
}).defaultNix
fetchTarball {
url = "https://github.com/edolstra/flake-compat/archive/c75e76f80c57784a6734356315b306140646ee84.tar.gz";
sha256 = "071aal00zp2m9knnhddgr2wqzlx6i6qa1263lv1y7bdn2w20h10h";
}
) {
src = ./.;
})
.defaultNix
46 changes: 25 additions & 21 deletions docs.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
{ pkgs, lib, modules, ... }:
let
{
pkgs,
lib,
modules,
...
}: let
options = lib.evalModules {
modules = modules;
specialArgs = { inherit pkgs lib; };
specialArgs = {inherit pkgs lib;};
};
docs = pkgs.nixosOptionsDoc {
# If we don't do this, we end up with _module.args on the generated options, which we do not want
Expand All @@ -11,25 +15,25 @@ let
};
asciidoc = docs.optionsAsciiDoc;
in
pkgs.stdenv.mkDerivation {
name = "nixvim-docs";
pkgs.stdenv.mkDerivation {
name = "nixvim-docs";

src = asciidoc;
buildInputs = [
pkgs.asciidoctor
];
src = asciidoc;
buildInputs = [
pkgs.asciidoctor
];

phases = [ "buildPhase" ];
phases = ["buildPhase"];

buildPhase = ''
mkdir -p $out/share/doc
cat <<EOF > header.adoc
= NixVim options
This lists all the options available for NixVim.
:toc:
buildPhase = ''
mkdir -p $out/share/doc
cat <<EOF > header.adoc
= NixVim options
This lists all the options available for NixVim.
:toc:
EOF
cat header.adoc $src > tmp.adoc
asciidoctor tmp.adoc -o $out/share/doc/index.html
'';
}
EOF
cat header.adoc $src > tmp.adoc
asciidoctor tmp.adoc -o $out/share/doc/index.html
'';
}
9 changes: 4 additions & 5 deletions example.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{ pkgs, ... }:
{
{pkgs, ...}: {
programs.nixvim = {
# This just enables NixVim.
# If all you have is this, then there will be little visible difference
Expand Down Expand Up @@ -53,8 +52,8 @@
# This is one of lightline's example configurations
active = {
left = [
[ "mode" "paste" ]
[ "redaonly" "filename" "modified" "helloworld" ]
["mode" "paste"]
["redaonly" "filename" "modified" "helloworld"]
];
};

Expand All @@ -73,7 +72,7 @@

# What about plugins not available as a module?
# Use extraPlugins:
extraPlugins = with pkgs.vimPlugins; [ vim-toml ];
extraPlugins = with pkgs.vimPlugins; [vim-toml];
};
};
}
154 changes: 85 additions & 69 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,92 +6,108 @@
inputs.beautysh.url = "github:lovesegfault/beautysh";
inputs.beautysh.inputs.nixpkgs.follows = "nixpkgs";

outputs = { self, nixpkgs, flake-utils, ... }@inputs:
outputs = {
self,
nixpkgs,
flake-utils,
...
} @ inputs:
with nixpkgs.lib;
with builtins;
let
with builtins; let
# TODO: Support nesting
nixvimModules = map (f: ./modules + "/${f}") (attrNames (builtins.readDir ./modules));

modules = pkgs: nixvimModules ++ [
(rec {
_file = ./flake.nix;
key = _file;
config = {
_module.args = {
pkgs = mkForce pkgs;
inherit (pkgs) lib;
helpers = import ./plugins/helpers.nix { inherit (pkgs) lib; };
inputs = inputs;
modules = pkgs:
nixvimModules
++ [
rec {
_file = ./flake.nix;
key = _file;
config = {
_module.args = {
pkgs = mkForce pkgs;
inherit (pkgs) lib;
helpers = import ./plugins/helpers.nix {inherit (pkgs) lib;};
inputs = inputs;
};
};
};
})
}

# ./plugins/default.nix
];
# ./plugins/default.nix
];

flakeOutput =
flake-utils.lib.eachDefaultSystem
(system:
let
pkgs = import nixpkgs { inherit system; };
extractRustAnalyzer = { stdenv, pkgs }: stdenv.mkDerivation {
pname = "extract_rust_analyzer";
version = "master";
(system: let
pkgs = import nixpkgs {inherit system;};
extractRustAnalyzer = {
stdenv,
pkgs,
}:
stdenv.mkDerivation {
pname = "extract_rust_analyzer";
version = "master";

dontUnpack = true;
dontBuild = true;
dontUnpack = true;
dontBuild = true;

buildInputs = [ pkgs.python3 ];
buildInputs = [pkgs.python3];

installPhase = ''
ls -la
mkdir -p $out/bin
cp ${./helpers/extract_rust_analyzer.py} $out/bin/extract_rust_analyzer.py
'';
};
extractRustAnalyzerPkg = pkgs.callPackage extractRustAnalyzer { };
in
{
packages = {
docs = pkgs.callPackage (import ./docs.nix) {
modules = nixvimModules;
};
runUpdates = pkgs.callPackage
({ pkgs, stdenv }: stdenv.mkDerivation {
pname = "run-updates";
version = pkgs.rust-analyzer.version;
installPhase = ''
ls -la
mkdir -p $out/bin
cp ${./helpers/extract_rust_analyzer.py} $out/bin/extract_rust_analyzer.py
'';
};
extractRustAnalyzerPkg = pkgs.callPackage extractRustAnalyzer {};
in {
packages = {
docs = pkgs.callPackage (import ./docs.nix) {
modules = nixvimModules;
};
runUpdates =
pkgs.callPackage
({
pkgs,
stdenv,
}:
stdenv.mkDerivation {
pname = "run-updates";
version = pkgs.rust-analyzer.version;

src = pkgs.rust-analyzer.src;
src = pkgs.rust-analyzer.src;

nativeBuildInputs = with pkgs; [extractRustAnalyzerPkg alejandra nixpkgs-fmt];
nativeBuildInputs = with pkgs; [extractRustAnalyzerPkg alejandra nixpkgs-fmt];

buildPhase = ''
extract_rust_analyzer.py editors/code/package.json |
alejandra --quiet |
nixpkgs-fmt > rust-analyzer-config.nix
'';
buildPhase = ''
extract_rust_analyzer.py editors/code/package.json |
alejandra --quiet |
nixpkgs-fmt > rust-analyzer-config.nix
'';

installPhase = ''
mkdir -p $out/share
cp rust-analyzer-config.nix $out/share
'';
})
{ };
};
legacyPackages = rec {
makeNixvimWithModule = import ./wrappers/standalone.nix pkgs modules;
makeNixvim = configuration: makeNixvimWithModule {
module = {
config = configuration;
};
installPhase = ''
mkdir -p $out/share
cp rust-analyzer-config.nix $out/share
'';
})
{};
};
legacyPackages = rec {
makeNixvimWithModule = import ./wrappers/standalone.nix pkgs modules;
makeNixvim = configuration:
makeNixvimWithModule {
module = {
config = configuration;
};
};
});
};
formatter = pkgs.alejandra;
});
in
flakeOutput // {
nixosModules.nixvim = import ./wrappers/nixos.nix modules;
homeManagerModules.nixvim = import ./wrappers/hm.nix modules;
nixDarwinModules.nixvim = import ./wrappers/darwin.nix modules;
};
flakeOutput
// {
nixosModules.nixvim = import ./wrappers/nixos.nix modules;
homeManagerModules.nixvim = import ./wrappers/hm.nix modules;
nixDarwinModules.nixvim = import ./wrappers/darwin.nix modules;
};
}
Loading

0 comments on commit 264de8c

Please sign in to comment.