refactor: formatted with alejandra

This commit is contained in:
Matthijs Steen 2023-04-28 10:54:13 +02:00
parent 57f1716bc6
commit 38f51739f3
5 changed files with 99 additions and 71 deletions

View File

@ -1,9 +1,12 @@
{
description = "NixOS VSCode server";
outputs = { self, nixpkgs }: let
outputs = {
self,
nixpkgs,
}: let
pkgs = import nixpkgs { system = "x86_64-linux"; };
auto-fix-vscode-server = pkgs.callPackage ./pkgs/auto-fix-vscode-server.nix {};
auto-fix-vscode-server = pkgs.callPackage ./pkgs/auto-fix-vscode-server.nix { };
in {
nixosModule = import ./modules/vscode-server;
nixosModules.default = self.nixosModule;

View File

@ -1,6 +1,8 @@
import ./module.nix ({ name, description, serviceConfig }:
{
import ./module.nix ({
name,
description,
serviceConfig,
}: {
systemd.user.services.${name} = {
inherit description serviceConfig;
wantedBy = [ "default.target" ];

View File

@ -1,6 +1,8 @@
import ./module.nix ({ name, description, serviceConfig }:
{
import ./module.nix ({
name,
description,
serviceConfig,
}: {
systemd.user.services.${name} = {
Unit = {
Description = description;

View File

@ -1,7 +1,9 @@
moduleConfig:
{ config, lib, pkgs, ... }:
{
moduleConfig: {
config,
lib,
pkgs,
...
}: {
options.services.vscode-server = let
inherit (lib) mkEnableOption mkOption;
inherit (lib.types) listOf nullOr package str;
@ -43,22 +45,23 @@ moduleConfig:
config = let
inherit (lib) mkDefault mkIf mkMerge;
cfg = config.services.vscode-server;
in mkIf cfg.enable (mkMerge [
{
services.vscode-server.nodejsPackage = mkIf cfg.enableFHS (mkDefault pkgs.nodejs-16_x);
}
(moduleConfig {
name = "auto-fix-vscode-server";
description = "Automatically fix the VS Code server used by the remote SSH extension";
serviceConfig = {
# When a monitored directory is deleted, it will stop being monitored.
# Even if it is later recreated it will not restart monitoring it.
# Unfortunately the monitor does not kill itself when it stops monitoring,
# so rather than creating our own restart mechanism, we leverage systemd to do this for us.
Restart = "always";
RestartSec = 0;
ExecStart = "${pkgs.callPackage ../../pkgs/auto-fix-vscode-server.nix (removeAttrs cfg [ "enable" ])}/bin/auto-fix-vscode-server";
};
})
]);
in
mkIf cfg.enable (mkMerge [
{
services.vscode-server.nodejsPackage = mkIf cfg.enableFHS (mkDefault pkgs.nodejs-16_x);
}
(moduleConfig {
name = "auto-fix-vscode-server";
description = "Automatically fix the VS Code server used by the remote SSH extension";
serviceConfig = {
# When a monitored directory is deleted, it will stop being monitored.
# Even if it is later recreated it will not restart monitoring it.
# Unfortunately the monitor does not kill itself when it stops monitoring,
# so rather than creating our own restart mechanism, we leverage systemd to do this for us.
Restart = "always";
RestartSec = 0;
ExecStart = "${pkgs.callPackage ../../pkgs/auto-fix-vscode-server.nix (removeAttrs cfg [ "enable" ])}/bin/auto-fix-vscode-server";
};
})
]);
}

View File

@ -1,32 +1,46 @@
{ lib, buildFHSUserEnv
, writeShellApplication, coreutils, findutils, inotify-tools, patchelf
, stdenv, curl, icu, libunwind, libuuid, lttng-ust, openssl, zlib, krb5
, enableFHS ? false
, nodejsPackage ? null
, extraRuntimeDependencies ? [ ]
, installPath ? "~/.vscode-server"
}:
let
{
lib,
buildFHSUserEnv,
writeShellApplication,
coreutils,
findutils,
inotify-tools,
patchelf,
stdenv,
curl,
icu,
libunwind,
libuuid,
lttng-ust,
openssl,
zlib,
krb5,
enableFHS ? false,
nodejsPackage ? null,
extraRuntimeDependencies ? [ ],
installPath ? "~/.vscode-server",
}: let
inherit (lib) makeBinPath makeLibraryPath optionalString;
# Based on: https://github.com/NixOS/nixpkgs/blob/nixos-unstable/pkgs/applications/editors/vscode/generic.nix
runtimeDependencies = [
stdenv.cc.libc
stdenv.cc.cc
runtimeDependencies =
[
stdenv.cc.libc
stdenv.cc.cc
# dotnet
curl
icu
libunwind
libuuid
lttng-ust
openssl
zlib
# dotnet
curl
icu
libunwind
libuuid
lttng-ust
openssl
zlib
# mono
krb5
] ++ extraRuntimeDependencies;
# mono
krb5
]
++ extraRuntimeDependencies;
nodejs = nodejsPackage;
nodejsFHS = buildFHSUserEnv {
@ -107,26 +121,30 @@ let
echo "Patching Node.js of VS Code server installation in $actual_dir..." >&2
${optionalString (nodejs != null) ''
ln -sfT ${if enableFHS then nodejsFHS else nodejs}/bin/node "$actual_dir/node"
''}
ln -sfT ${
if enableFHS
then nodejsFHS
else nodejs
}/bin/node "$actual_dir/node"
''}
${optionalString (!enableFHS) ''
mv "$actual_dir/node" "$actual_dir/node.orig"
cat <<EOF > "$actual_dir/node"
#!/usr/bin/env sh
mv "$actual_dir/node" "$actual_dir/node.orig"
cat <<EOF > "$actual_dir/node"
#!/usr/bin/env sh
# The core utilities are missing in the case of WSL, but required by Node.js.
PATH="\''${PATH:+\''${PATH}:}${makeBinPath [ coreutils ]}"
# The core utilities are missing in the case of WSL, but required by Node.js.
PATH="\''${PATH:+\''${PATH}:}${makeBinPath [ coreutils ]}"
# We leave the rest up to the Bash script
# to keep having to deal with 'sh' compatibility to a minimum.
${patchELFScript}/bin/patchelf-vscode-server '$bin_dir'
# We leave the rest up to the Bash script
# to keep having to deal with 'sh' compatibility to a minimum.
${patchELFScript}/bin/patchelf-vscode-server '$bin_dir'
# Let Node.js take over as if this script never existed.
exec '$bin_dir/node.orig' "\$@"
EOF
chmod +x "$actual_dir/node"
''}
# Let Node.js take over as if this script never existed.
exec '$bin_dir/node.orig' "\$@"
EOF
chmod +x "$actual_dir/node"
''}
# Mark the bin directory as being patched.
echo 0 > "$bin_dir/.patched"
@ -157,5 +175,5 @@ let
done < <(inotifywait -q -m -e CREATE,ISDIR -e DELETE_SELF --format '%f:%e' "$bins_dir")
'';
};
in autoFixScript
in
autoFixScript