wip not reactive highlighting

This commit is contained in:
Florian Schmitt 2024-10-23 18:51:43 +03:00
parent 088076bbea
commit 6fa808d461
3 changed files with 95 additions and 1 deletions

View file

@ -57,3 +57,7 @@
margin: 1em 0; margin: 1em 0;
white-space: pre-wrap; white-space: pre-wrap;
} }
.nix-preview .shiki {
padding: 0.5em;
}

View file

@ -1,6 +1,7 @@
<script setup> <script setup>
import NixCode from "./NixCode.vue" import NixCode from "./NixCode.vue"
import NixForm from "./NixForm.vue" import NixForm from "./NixForm.vue"
import NixPreview from "./NixPreview.vue"
import { provide, ref } from 'vue' import { provide, ref } from 'vue'
import { listTz, clientTz } from 'timezone-select-js'; import { listTz, clientTz } from 'timezone-select-js';
@ -210,6 +211,7 @@ function selectServices(bundleId, services) {
</div> </div>
<h2>Auto-generated configuration.nix file</h2> <h2>Auto-generated configuration.nix file</h2>
<NixPreview />
<pre class="nix-code"> <pre class="nix-code">
<code> <code>
{ pkgs, ... }: { pkgs, ... }:
@ -246,7 +248,7 @@ function selectServices(bundleId, services) {
commands = [ commands = [
{ {
command = "ALL" ; command = "ALL" ;
options= [ "NOPASSWD" ]; # "SETENV" # Adding the following could be a good idea options= [ "NOPASSWD" ];
} }
]; ];
} }

88
components/NixPreview.vue Normal file
View file

@ -0,0 +1,88 @@
<script setup>
import { createHighlighterCoreSync } from 'shiki/core'
import { createJavaScriptRegexEngine } from 'shiki/engine/javascript'
import nix from 'shiki/langs/nix.mjs'
import nord from 'shiki/themes/nord.mjs'
import { inject, toRaw } from 'vue'
let nixin = inject('nixin')
let n = toRaw(nixin)._rawValue
const shiki = createHighlighterCoreSync({
themes: [nord],
langs: [nix],
engine: createJavaScriptRegexEngine()
})
let html = shiki.codeToHtml(`{ pkgs, ... }:
{
networking.hosts = {
"127.0.0.1" = [ "${ n.networkingHostname }.${ n.networkingDomain}" ];
};
networking.hostName = "${ n.networkingHostname }";
networking.domain = "${ n.networkingDomain }";
networking.firewall = {
allowedTCPPorts = [
80
443
];
};
time.timeZone = "${ n.timezone }";
i18n.defaultLocale = "${ n.locale }";
<div v-for="(service) in nixin.services" :key="service">
<NixCode :service="service"/>
</div>
users.users.${ n.operatingUser } = {
isNormalUser = true;
extraGroups = [ "wheel" ];
initialPassword = "${ n.operatingUserPassword }";
};
security.sudo.extraRules= [
{
users = [ "${ n.operatingUser }" ];
commands = [
{
command = "ALL" ;
options= [ "NOPASSWD" ];
}
];
}
];
security.acme.defaults.email = "contact@nixin.local";
security.acme.acceptTerms = true;
services.nginx = {
enable = true;
# Use recommended settings
recommendedGzipSettings = true;
recommendedOptimisation = true;
recommendedProxySettings = true;
recommendedTlsSettings = true;
# Only allow PFS-enabled ciphers with AES256
sslCiphers = "AES256+EECDH:AES256+EDH:!aNULL";
};
environment.systemPackages = with pkgs; [
git
wget
tmux
mosh
htop
];
system.stateVersion = "24.05";
}
`, { lang: 'nix', theme: 'nord' })
</script>
<template>
<div class="nix-preview" v-html="html" />
</template>