Skip to content

Commit

Permalink
update treefmt
Browse files Browse the repository at this point in the history
  • Loading branch information
inclyc committed Aug 10, 2024
1 parent 0b1d93d commit 1168cb0
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 97 deletions.
199 changes: 103 additions & 96 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,104 +12,111 @@
};
};

outputs = { nixpkgs, flake-parts, treefmt-nix, ... }@inputs: flake-parts.lib.mkFlake { inherit inputs; } {
imports = [
inputs.flake-parts.flakeModules.easyOverlay
inputs.flake-root.flakeModule
];
perSystem = { config, pkgs, ... }:
let
inherit (pkgs) nixVersions llvmPackages_16 callPackage stdenv;
nix = nixVersions.nix_2_19;
llvmPackages = llvmPackages_16;
nixf = callPackage ./libnixf { };
nixt = callPackage ./libnixt {
inherit nix;
};
nixd = callPackage ./nixd {
inherit nix nixf nixt;
inherit llvmPackages;
};
nixdMono = callPackage ./. {
inherit nix llvmPackages;
};
nixdLLVM = nixdMono.override {
stdenv = if stdenv.isDarwin then stdenv else llvmPackages.stdenv;
};
regressionDeps = with pkgs; [
clang-tools
lit
];
shellOverride = old: {
nativeBuildInputs = old.nativeBuildInputs ++ regressionDeps;
shellHook = ''
export PATH="${pkgs.clang-tools}/bin:$PATH"
export NIX_SRC=${nix.src}
export NIX_PATH=nixpkgs=${nixpkgs}
'';
hardeningDisable = [ "fortify" ];
};
treefmtEval = treefmt-nix.lib.evalModule pkgs ./treefmt.nix;
in
{
packages.default = nixd;
overlayAttrs = {
inherit (config.packages) nixd;
};
packages = { inherit nixd nixf nixt; };
outputs =
{
nixpkgs,
flake-parts,
treefmt-nix,
...
}@inputs:
flake-parts.lib.mkFlake { inherit inputs; } {
imports = [
inputs.flake-parts.flakeModules.easyOverlay
inputs.flake-root.flakeModule
];
perSystem =
{ config, pkgs, ... }:
let
inherit (pkgs)
nixVersions
llvmPackages_16
callPackage
stdenv
;
nix = nixVersions.nix_2_19;
llvmPackages = llvmPackages_16;
nixf = callPackage ./libnixf { };
nixt = callPackage ./libnixt { inherit nix; };
nixd = callPackage ./nixd {
inherit nix nixf nixt;
inherit llvmPackages;
};
nixdMono = callPackage ./. { inherit nix llvmPackages; };
nixdLLVM = nixdMono.override { stdenv = if stdenv.isDarwin then stdenv else llvmPackages.stdenv; };
regressionDeps = with pkgs; [
clang-tools
lit
];
shellOverride = old: {
nativeBuildInputs = old.nativeBuildInputs ++ regressionDeps;
shellHook = ''
export PATH="${pkgs.clang-tools}/bin:$PATH"
export NIX_SRC=${nix.src}
export NIX_PATH=nixpkgs=${nixpkgs}
'';
hardeningDisable = [ "fortify" ];
};
treefmtEval = treefmt-nix.lib.evalModule pkgs ./treefmt.nix;
in
{
packages.default = nixd;
overlayAttrs = {
inherit (config.packages) nixd;
};
packages = {
inherit nixd nixf nixt;
};

devShells.llvm = nixdLLVM.overrideAttrs shellOverride;
devShells.llvm = nixdLLVM.overrideAttrs shellOverride;

devShells.default = nixdMono.overrideAttrs shellOverride;
devShells.default = nixdMono.overrideAttrs shellOverride;

devShells.nvim = pkgs.mkShell {
nativeBuildInputs = [
nixd
pkgs.nixfmt-rfc-style
pkgs.git
(import ./nixd/docs/editors/nvim-lsp.nix { inherit pkgs; })
];
inputsFrom = [
config.flake-root.devShell
];
shellHook = ''
echo -e "\n\033[1;31mDuring the first time nixd launches, the flake inputs will be fetched from the internet, this is rather slow.\033[0m"
echo -e "\033[1;34mEntering the nvim test environment...\033[0m"
cd $FLAKE_ROOT
export GIT_REPO=https://github.com/nix-community/nixd.git
export EXAMPLES_PATH=nixd/docs/examples
export WORK_TEMP=/tmp/NixOS_Home-Manager
if [ -d "$WORK_TEMP" ]; then
rm -rf $WORK_TEMP
fi
mkdir -p $WORK_TEMP
cp -r $EXAMPLES_PATH/NixOS_Home-Manager/* $WORK_TEMP/ 2>/dev/null
if [[ $? -ne 0 ]]; then
export GIT_DIR=$WORK_TEMP/.git
export GIT_WORK_TREE=/tmp/NixOS_Home-Manager
git init
git config core.sparseCheckout true
git remote add origin $GIT_REPO
echo "$EXAMPLES_PATH/NixOS_Home-Manager/" >$GIT_DIR/info/sparse-checkout
git pull origin main
cp $GIT_WORK_TREE\/$EXAMPLES_PATH/NixOS_Home-Manager/* $GIT_WORK_TREE 2>/dev/null
rm -rf $GIT_WORK_TREE/nixd
fi
cd $WORK_TEMP
echo -e "\033[1;32mNow, you can edit the nix file by running the following command:\033[0m"
echo -e "\033[1;33m'nvim-lsp flake.nix'\033[0m"
echo -e "\033[1;34mEnvironment setup complete.\033[0m"
'';
};
devShells.vscodium = pkgs.mkShell {
nativeBuildInputs = [
nixd
pkgs.nixfmt-rfc-style
(import ./nixd/docs/editors/vscodium.nix { inherit pkgs; })
];
devShells.nvim = pkgs.mkShell {
nativeBuildInputs = [
nixd
pkgs.nixfmt-rfc-style
pkgs.git
(import ./nixd/docs/editors/nvim-lsp.nix { inherit pkgs; })
];
inputsFrom = [ config.flake-root.devShell ];
shellHook = ''
echo -e "\n\033[1;31mDuring the first time nixd launches, the flake inputs will be fetched from the internet, this is rather slow.\033[0m"
echo -e "\033[1;34mEntering the nvim test environment...\033[0m"
cd $FLAKE_ROOT
export GIT_REPO=https://github.com/nix-community/nixd.git
export EXAMPLES_PATH=nixd/docs/examples
export WORK_TEMP=/tmp/NixOS_Home-Manager
if [ -d "$WORK_TEMP" ]; then
rm -rf $WORK_TEMP
fi
mkdir -p $WORK_TEMP
cp -r $EXAMPLES_PATH/NixOS_Home-Manager/* $WORK_TEMP/ 2>/dev/null
if [[ $? -ne 0 ]]; then
export GIT_DIR=$WORK_TEMP/.git
export GIT_WORK_TREE=/tmp/NixOS_Home-Manager
git init
git config core.sparseCheckout true
git remote add origin $GIT_REPO
echo "$EXAMPLES_PATH/NixOS_Home-Manager/" >$GIT_DIR/info/sparse-checkout
git pull origin main
cp $GIT_WORK_TREE\/$EXAMPLES_PATH/NixOS_Home-Manager/* $GIT_WORK_TREE 2>/dev/null
rm -rf $GIT_WORK_TREE/nixd
fi
cd $WORK_TEMP
echo -e "\033[1;32mNow, you can edit the nix file by running the following command:\033[0m"
echo -e "\033[1;33m'nvim-lsp flake.nix'\033[0m"
echo -e "\033[1;34mEnvironment setup complete.\033[0m"
'';
};
devShells.vscodium = pkgs.mkShell {
nativeBuildInputs = [
nixd
pkgs.nixfmt-rfc-style
(import ./nixd/docs/editors/vscodium.nix { inherit pkgs; })
];
};
formatter = treefmtEval.config.build.wrapper;
};
formatter = treefmtEval.config.build.wrapper;
};
systems = nixpkgs.lib.systems.flakeExposed;
};
systems = nixpkgs.lib.systems.flakeExposed;
};
}
2 changes: 1 addition & 1 deletion treefmt.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
projectRootFile = "flake.nix";
programs = {
clang-format.enable = true;
nixpkgs-fmt.enable = true;
nixfmt.enable = true;
black.enable = true;
};
}

0 comments on commit 1168cb0

Please sign in to comment.