1
Fork 0

feat: attempted to install prettierd

This commit is contained in:
Matei Adriel 2022-02-01 15:28:29 +02:00
parent 85cc99140c
commit 79455a6e29
12 changed files with 319 additions and 16577 deletions

41
.pnpm-debug.log Normal file
View file

@ -0,0 +1,41 @@
{
"0 debug pnpm:scope": {
"selected": 1
},
"1 debug pnpm:package-manifest": {
"initial": {},
"prefix": "/home/adrielus/Projects/nixos-config"
},
"2 debug pnpm:context": {
"currentLockfileExists": false,
"storeDir": "/home/adrielus/.pnpm-store/v3",
"virtualStoreDir": "/home/adrielus/Projects/nixos-config/node_modules/.pnpm"
},
"3 debug pnpm:stage": {
"prefix": "/home/adrielus/Projects/nixos-config",
"stage": "resolution_started"
},
"4 debug pnpm:update-check": {
"currentVersion": "6.22.2",
"latestVersion": "6.29.1"
},
"5 error pnpm": {
"code": "ERR_PNPM_FETCH_404",
"hint": "prettierd is not in the npm registry, or you have no permission to fetch it.\n\nAn authorization header was used: Bearer 265b[hidden]",
"request": {
"authHeaderValue": "Bearer 265ba49b-cc14-402e-8c57-e070a7bc1997",
"url": "https://registry.npmjs.org/prettierd"
},
"response": {
"size": 0
},
"pkgName": "prettierd",
"pkgsStack": [],
"err": {
"name": "pnpm",
"message": "GET https://registry.npmjs.org/prettierd: Not Found - 404",
"code": "ERR_PNPM_FETCH_404",
"stack": "pnpm: GET https://registry.npmjs.org/prettierd: Not Found - 404\n at RetryOperation._fn (/nix/store/kh5rqvj2l82gznih1b5isc43mk2dnh6j-pnpm-6.22.2/lib/node_modules/pnpm/dist/pnpm.cjs:84952:18)\n at processTicksAndRejections (internal/process/task_queues.js:95:5)"
}
}
}

View file

@ -2,9 +2,19 @@ local mapSilent = require("my.keymaps").mapSilent
local M = {}
function M.setup()
local bindings = {
-- Open files with control + P
mapSilent('n', '<c-P>', "<cmd>lua require('fzf-lua').files()<CR>")
files = "<c-P>",
-- See diagnostics with space + d
lsp_document_diagnostics = "<space>d",
lsp_workspace_diagnostics = "<space>D"
}
function M.setup()
for action, keybind in pairs(bindings) do
-- Maps the keybind to the action
mapSilent('n', keybind, "<cmd>lua require('fzf-lua')." .. action .. "()<CR>")
end
end
return M

View file

@ -84,16 +84,29 @@ function M.setup()
}
end
local efmLanguages = {
typescript = {
formatCommand = 'prettierd "${INPUT}"',
formatStdin = true,
env = {string.format('PRETTIERD_DEFAULT_CONFIG=%s', vim.fn.expand('~/.config/nvim/utils/linter-config/.prettierrc.json'))}
},
lua = {{formatCommand = formatLua, formatStdin = true}}
}
-- Setup auto-formatting
require"lspconfig".efm.setup {
init_options = {documentFormatting = true},
filetypes = {"lua"},
settings = {rootMarkers = {".git/"}, languages = {lua = {{formatCommand = formatLua, formatStdin = true}}}}
filetypes = {"lua", "ts", "js", "tsx", "jsx"},
settings = {rootMarkers = {".git/"}, languages = efmLanguages}
}
-- Auto format lua stuff
cmd("autocmd BufWritePre *.lua lua vim.lsp.buf.formatting_sync(nil, 100)")
-- cmd("autocmd BufWritePre nix vim.lsp.buf.formatting_sync(nil, 100)")
local autoFormatOn = {lua = 100, purs = 1000, nix = 100, js = 100, ts = 100, tsx = 100, jsx = 100}
-- Auto format
for extension, timeout in pairs(autoFormatOn) do
-- I wonder if this could be done in a single glob pattern
cmd("autocmd BufWritePre *." .. extension .. " lua vim.lsp.buf.formatting_sync(nil, " .. timeout .. ")")
end
end
return M

View file

@ -1,26 +1,23 @@
{ pkgs, ... }:
let
# config-nvim = "/etc/nixos/configuration/dotfiles/neovim";
config-nvim = pkgs.vimUtils.buildVimPluginFrom2Nix {
name = "config-nvim";
src = ../../dotfiles/neovim;
};
in
{
home-manager.users.adrielus.programs.neovim = {
enable = true;
package = pkgs.neovim-nightly;
extraConfig = ''
let g:disable_paq = v:true
luafile ${config-nvim}/init.lua
'';
extraPackages = with pkgs; [
fzf # Required by lua-fzf
# Language servers
nodePackages.typescript # typescript
nodePackages.typescript-language-server # typescript
easy-purescript-nix.purescript-language-server # purescript
sumneko-lua-language-server # lua
efm-langserver # auto-formatting
@ -28,6 +25,11 @@ in
# Formatters
luaformatter # lua
nodePackages.prettierd # prettier but faster
# Others
fzf # Required by lua-fzf
nodePackages.typescript # typescript language
];
plugins = with pkgs.vimPlugins;

View file

@ -1,9 +0,0 @@
[
"pnpm",
"tsdx",
"mklicense",
"preact-cli",
"create-next-app",
"create-snowpack-app",
"bower"
]

File diff suppressed because it is too large Load diff

View file

@ -1,9 +1,9 @@
{ pkgs, ... }: {
nixpkgs.overlays = [
(import ./tweakSources.nix)
(import ./npm.nix)
# I hope this works
# I hope this works (spoiler: it did not)
(import ./edopro)
];
}

6
modules/overlays/npm.nix Normal file
View file

@ -0,0 +1,6 @@
self: super:
let customPackages = pkgs.callPackage ./npm { };
in with self; {
# Faster prettier for editors
nodePackages.prettierd = customPackages."@fsouza/prettierd";
}

View file

@ -1,4 +1,4 @@
# This file has been generated by node2nix 1.8.0. Do not edit!
# This file has been generated by node2nix 1.9.0. Do not edit!
{pkgs ? import <nixpkgs> {
inherit system;
@ -6,12 +6,12 @@
let
nodeEnv = import ./node-env.nix {
inherit (pkgs) stdenv python2 utillinux runCommand writeTextFile;
inherit nodejs;
inherit (pkgs) stdenv lib python2 runCommand writeTextFile writeShellScript;
inherit pkgs nodejs;
libtool = if pkgs.stdenv.isDarwin then pkgs.darwin.cctools else null;
};
in
import ./node-packages.nix {
inherit (pkgs) fetchurl fetchgit;
inherit (pkgs) fetchurl nix-gitignore stdenv lib fetchgit;
inherit nodeEnv;
}

View file

@ -1,8 +1,11 @@
# This file originates from node2nix
{stdenv, nodejs, python2, utillinux, libtool, runCommand, writeTextFile}:
{lib, stdenv, nodejs, python2, pkgs, libtool, runCommand, writeTextFile, writeShellScript}:
let
# Workaround to cope with utillinux in Nixpkgs 20.09 and util-linux in Nixpkgs master
utillinux = if pkgs ? utillinux then pkgs.utillinux else pkgs.util-linux;
python = if nodejs ? python then nodejs.python else python2;
# Create a tar wrapper that filters all the 'Ignoring unknown extended header keyword' noise
@ -37,36 +40,22 @@ let
'';
};
includeDependencies = {dependencies}:
stdenv.lib.optionalString (dependencies != [])
(stdenv.lib.concatMapStrings (dependency:
''
# Bundle the dependencies of the package
mkdir -p node_modules
cd node_modules
# Common shell logic
installPackage = writeShellScript "install-package" ''
installPackage() {
local packageName=$1 src=$2
# Only include dependencies if they don't exist. They may also be bundled in the package.
if [ ! -e "${dependency.name}" ]
then
${composePackage dependency}
fi
local strippedName
cd ..
''
) dependencies);
# Recursively composes the dependencies of a package
composePackage = { name, packageName, src, dependencies ? [], ... }@args:
builtins.addErrorContext "while evaluating node package '${packageName}'" ''
DIR=$(pwd)
local DIR=$PWD
cd $TMPDIR
unpackFile ${src}
unpackFile $src
# Make the base dir in which the target dependency resides first
mkdir -p "$(dirname "$DIR/${packageName}")"
mkdir -p "$(dirname "$DIR/$packageName")"
if [ -f "${src}" ]
if [ -f "$src" ]
then
# Figure out what directory has been unpacked
packageDir="$(find . -maxdepth 1 -type d | tail -1)"
@ -76,31 +65,56 @@ let
chmod -R u+w "$packageDir"
# Move the extracted tarball into the output folder
mv "$packageDir" "$DIR/${packageName}"
elif [ -d "${src}" ]
mv "$packageDir" "$DIR/$packageName"
elif [ -d "$src" ]
then
# Get a stripped name (without hash) of the source directory.
# On old nixpkgs it's already set internally.
if [ -z "$strippedName" ]
then
strippedName="$(stripHash ${src})"
strippedName="$(stripHash $src)"
fi
# Restore write permissions to make building work
chmod -R u+w "$strippedName"
# Move the extracted directory into the output folder
mv "$strippedName" "$DIR/${packageName}"
mv "$strippedName" "$DIR/$packageName"
fi
# Unset the stripped name to not confuse the next unpack step
unset strippedName
# Change to the package directory to install dependencies
cd "$DIR/$packageName"
}
'';
# Include the dependencies of the package
cd "$DIR/${packageName}"
# Bundle the dependencies of the package
#
# Only include dependencies if they don't exist. They may also be bundled in the package.
includeDependencies = {dependencies}:
lib.optionalString (dependencies != []) (
''
mkdir -p node_modules
cd node_modules
''
+ (lib.concatMapStrings (dependency:
''
if [ ! -e "${dependency.name}" ]; then
${composePackage dependency}
fi
''
) dependencies)
+ ''
cd ..
''
);
# Recursively composes the dependencies of a package
composePackage = { name, packageName, src, dependencies ? [], ... }@args:
builtins.addErrorContext "while evaluating node package '${packageName}'" ''
installPackage "${packageName}" "${src}"
${includeDependencies { inherit dependencies; }}
cd ..
${stdenv.lib.optionalString (builtins.substring 0 1 packageName == "@") "cd .."}
${lib.optionalString (builtins.substring 0 1 packageName == "@") "cd .."}
'';
pinpointDependencies = {dependencies, production}:
@ -161,12 +175,12 @@ let
''
node ${pinpointDependenciesFromPackageJSON} ${if production then "production" else "development"}
${stdenv.lib.optionalString (dependencies != [])
${lib.optionalString (dependencies != [])
''
if [ -d node_modules ]
then
cd node_modules
${stdenv.lib.concatMapStrings (dependency: pinpointDependenciesOfPackage dependency) dependencies}
${lib.concatMapStrings (dependency: pinpointDependenciesOfPackage dependency) dependencies}
cd ..
fi
''}
@ -183,7 +197,7 @@ let
cd "${packageName}"
${pinpointDependencies { inherit dependencies production; }}
cd ..
${stdenv.lib.optionalString (builtins.substring 0 1 packageName == "@") "cd .."}
${lib.optionalString (builtins.substring 0 1 packageName == "@") "cd .."}
fi
'';
@ -242,8 +256,8 @@ let
if(fs.existsSync("./package-lock.json")) {
var packageLock = JSON.parse(fs.readFileSync("./package-lock.json"));
if(packageLock.lockfileVersion !== 1) {
process.stderr.write("Sorry, I only understand lock file version 1!\n");
if(![1, 2].includes(packageLock.lockfileVersion)) {
process.stderr.write("Sorry, I only understand lock file versions 1 and 2!\n");
process.exit(1);
}
@ -344,8 +358,8 @@ let
cd "${packageName}"
runHook preRebuild
${stdenv.lib.optionalString bypassCache ''
${stdenv.lib.optionalString reconstructLock ''
${lib.optionalString bypassCache ''
${lib.optionalString reconstructLock ''
if [ -f package-lock.json ]
then
echo "WARNING: Reconstruct lock option enabled, but a lock file already exists!"
@ -361,14 +375,14 @@ let
node ${addIntegrityFieldsScript}
''}
npm ${forceOfflineFlag} --nodedir=${nodeSources} ${npmFlags} ${stdenv.lib.optionalString production "--production"} rebuild
npm ${forceOfflineFlag} --nodedir=${nodeSources} ${npmFlags} ${lib.optionalString production "--production"} rebuild
if [ "''${dontNpmInstall-}" != "1" ]
then
# NPM tries to download packages even when they already exist if npm-shrinkwrap is used.
rm -f npm-shrinkwrap.json
npm ${forceOfflineFlag} --nodedir=${nodeSources} ${npmFlags} ${stdenv.lib.optionalString production "--production"} install
npm ${forceOfflineFlag} --nodedir=${nodeSources} ${npmFlags} ${lib.optionalString production "--production"} install
fi
'';
@ -388,16 +402,17 @@ let
, dontStrip ? true
, unpackPhase ? "true"
, buildPhase ? "true"
, meta ? {}
, ... }@args:
let
extraArgs = removeAttrs args [ "name" "dependencies" "buildInputs" "dontStrip" "dontNpmInstall" "preRebuild" "unpackPhase" "buildPhase" ];
extraArgs = removeAttrs args [ "name" "dependencies" "buildInputs" "dontStrip" "dontNpmInstall" "preRebuild" "unpackPhase" "buildPhase" "meta" ];
in
stdenv.mkDerivation ({
name = "node_${name}-${version}";
name = "${name}-${version}";
buildInputs = [ tarWrapper python nodejs ]
++ stdenv.lib.optional (stdenv.isLinux) utillinux
++ stdenv.lib.optional (stdenv.isDarwin) libtool
++ lib.optional (stdenv.isLinux) utillinux
++ lib.optional (stdenv.isDarwin) libtool
++ buildInputs;
inherit nodejs;
@ -411,6 +426,8 @@ let
passAsFile = [ "compositionScript" "pinpointDependenciesScript" ];
installPhase = ''
source ${installPackage}
# Create and enter a root node_modules/ folder
mkdir -p $out/lib/node_modules
cd $out/lib/node_modules
@ -443,6 +460,81 @@ let
# Run post install hook, if provided
runHook postInstall
'';
meta = {
# default to Node.js' platforms
platforms = nodejs.meta.platforms;
} // meta;
} // extraArgs);
# Builds a node environment (a node_modules folder and a set of binaries)
buildNodeDependencies =
{ name
, packageName
, version
, src
, dependencies ? []
, buildInputs ? []
, production ? true
, npmFlags ? ""
, dontNpmInstall ? false
, bypassCache ? false
, reconstructLock ? false
, dontStrip ? true
, unpackPhase ? "true"
, buildPhase ? "true"
, ... }@args:
let
extraArgs = removeAttrs args [ "name" "dependencies" "buildInputs" ];
in
stdenv.mkDerivation ({
name = "node-dependencies-${name}-${version}";
buildInputs = [ tarWrapper python nodejs ]
++ lib.optional (stdenv.isLinux) utillinux
++ lib.optional (stdenv.isDarwin) libtool
++ buildInputs;
inherit dontStrip; # Stripping may fail a build for some package deployments
inherit dontNpmInstall unpackPhase buildPhase;
includeScript = includeDependencies { inherit dependencies; };
pinpointDependenciesScript = pinpointDependenciesOfPackage args;
passAsFile = [ "includeScript" "pinpointDependenciesScript" ];
installPhase = ''
source ${installPackage}
mkdir -p $out/${packageName}
cd $out/${packageName}
source $includeScriptPath
# Create fake package.json to make the npm commands work properly
cp ${src}/package.json .
chmod 644 package.json
${lib.optionalString bypassCache ''
if [ -f ${src}/package-lock.json ]
then
cp ${src}/package-lock.json .
fi
''}
# Go to the parent folder to make sure that all packages are pinpointed
cd ..
${lib.optionalString (builtins.substring 0 1 packageName == "@") "cd .."}
${prepareAndInvokeNPM { inherit packageName bypassCache reconstructLock npmFlags production; }}
# Expose the executables that were installed
cd ..
${lib.optionalString (builtins.substring 0 1 packageName == "@") "cd .."}
mv ${packageName} lib
ln -s $out/lib/node_modules/.bin $out/bin
'';
} // extraArgs);
# Builds a development shell
@ -464,59 +556,12 @@ let
, ... }@args:
let
extraArgs = removeAttrs args [ "name" "dependencies" "buildInputs" ];
nodeDependencies = stdenv.mkDerivation ({
name = "node-dependencies-${name}-${version}";
buildInputs = [ tarWrapper python nodejs ]
++ stdenv.lib.optional (stdenv.isLinux) utillinux
++ stdenv.lib.optional (stdenv.isDarwin) libtool
++ buildInputs;
inherit dontStrip; # Stripping may fail a build for some package deployments
inherit dontNpmInstall unpackPhase buildPhase;
includeScript = includeDependencies { inherit dependencies; };
pinpointDependenciesScript = pinpointDependenciesOfPackage args;
passAsFile = [ "includeScript" "pinpointDependenciesScript" ];
installPhase = ''
mkdir -p $out/${packageName}
cd $out/${packageName}
source $includeScriptPath
# Create fake package.json to make the npm commands work properly
cp ${src}/package.json .
chmod 644 package.json
${stdenv.lib.optionalString bypassCache ''
if [ -f ${src}/package-lock.json ]
then
cp ${src}/package-lock.json .
fi
''}
# Go to the parent folder to make sure that all packages are pinpointed
cd ..
${stdenv.lib.optionalString (builtins.substring 0 1 packageName == "@") "cd .."}
${prepareAndInvokeNPM { inherit packageName bypassCache reconstructLock npmFlags production; }}
# Expose the executables that were installed
cd ..
${stdenv.lib.optionalString (builtins.substring 0 1 packageName == "@") "cd .."}
mv ${packageName} lib
ln -s $out/lib/node_modules/.bin $out/bin
'';
} // extraArgs);
nodeDependencies = buildNodeDependencies args;
in
stdenv.mkDerivation {
name = "node-shell-${name}-${version}";
buildInputs = [ python nodejs ] ++ stdenv.lib.optional (stdenv.isLinux) utillinux ++ buildInputs;
buildInputs = [ python nodejs ] ++ lib.optional (stdenv.isLinux) utillinux ++ buildInputs;
buildCommand = ''
mkdir -p $out/bin
cat > $out/bin/shell <<EOF
@ -529,14 +574,15 @@ let
# Provide the dependencies in a development shell through the NODE_PATH environment variable
inherit nodeDependencies;
shellHook = stdenv.lib.optionalString (dependencies != []) ''
shellHook = lib.optionalString (dependencies != []) ''
export NODE_PATH=${nodeDependencies}/lib/node_modules
export PATH="${nodeDependencies}/bin:$PATH"
'';
};
in
{
buildNodeSourceDist = stdenv.lib.makeOverridable buildNodeSourceDist;
buildNodePackage = stdenv.lib.makeOverridable buildNodePackage;
buildNodeShell = stdenv.lib.makeOverridable buildNodeShell;
buildNodeSourceDist = lib.makeOverridable buildNodeSourceDist;
buildNodePackage = lib.makeOverridable buildNodePackage;
buildNodeDependencies = lib.makeOverridable buildNodeDependencies;
buildNodeShell = lib.makeOverridable buildNodeShell;
}

View file

@ -0,0 +1 @@
["@fsouza/prettierd"]

View file

@ -0,0 +1,80 @@
# This file has been generated by node2nix 1.9.0. Do not edit!
{nodeEnv, fetchurl, fetchgit, nix-gitignore, stdenv, lib, globalBuildInputs ? []}:
let
sources = {
"core_d-3.2.0" = {
name = "core_d";
packageName = "core_d";
version = "3.2.0";
src = fetchurl {
url = "https://registry.npmjs.org/core_d/-/core_d-3.2.0.tgz";
sha512 = "waKkgHU2P19huhuMjCqCDWTYjxCIHoB+nnYjI7pVMUOC1giWxMNDrXkPw9QjWY+PWCFm49bD3wA/J+c7BGZ+og==";
};
};
"has-flag-4.0.0" = {
name = "has-flag";
packageName = "has-flag";
version = "4.0.0";
src = fetchurl {
url = "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz";
sha512 = "EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==";
};
};
"nanolru-1.0.0" = {
name = "nanolru";
packageName = "nanolru";
version = "1.0.0";
src = fetchurl {
url = "https://registry.npmjs.org/nanolru/-/nanolru-1.0.0.tgz";
sha512 = "GyQkE8M32pULhQk7Sko5raoIbPalAk90ICG+An4fq6fCsFHsP6fB2K46WGXVdoJpy4SGMnZ/EKbo123fZJomWg==";
};
};
"prettier-2.5.1" = {
name = "prettier";
packageName = "prettier";
version = "2.5.1";
src = fetchurl {
url = "https://registry.npmjs.org/prettier/-/prettier-2.5.1.tgz";
sha512 = "vBZcPRUR5MZJwoyi3ZoyQlc1rXeEck8KgeC9AwwOn+exuxLxq5toTRDTSaVrXHxelDMHy9zlicw8u66yxoSUFg==";
};
};
"supports-color-8.1.1" = {
name = "supports-color";
packageName = "supports-color";
version = "8.1.1";
src = fetchurl {
url = "https://registry.npmjs.org/supports-color/-/supports-color-8.1.1.tgz";
sha512 = "MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q==";
};
};
};
in
{
"@fsouza/prettierd" = nodeEnv.buildNodePackage {
name = "_at_fsouza_slash_prettierd";
packageName = "@fsouza/prettierd";
version = "0.18.1";
src = fetchurl {
url = "https://registry.npmjs.org/@fsouza/prettierd/-/prettierd-0.18.1.tgz";
sha512 = "W2H1E09e1B31MuyOlpXOtemxZ+9qZk7TTOzebVDh5WqHB7+jo1WOJtGwwTyp1k9irlvqqF/FpRzIUrKBR4KGqA==";
};
dependencies = [
sources."core_d-3.2.0"
sources."has-flag-4.0.0"
sources."nanolru-1.0.0"
sources."prettier-2.5.1"
sources."supports-color-8.1.1"
];
buildInputs = globalBuildInputs;
meta = {
description = "prettier, as a daemon";
homepage = "https://github.com/fsouza/prettierd#readme";
license = "ISC";
};
production = true;
bypassCache = true;
reconstructLock = true;
};
}