wip adding articles

master
Ingolf Wagner 2021-07-20 18:08:41 +02:00
parent 873d8264d9
commit 82c193b419
Signed by: palo
GPG Key ID: 76BF5F1928B9618B
7 changed files with 288 additions and 81 deletions

View File

@ -8,7 +8,7 @@ date: 2018-09-28T21:43:24+02:00
Hey here are some articles about technical issues.
Most of them are about
[NixOS](https://nixos.org) topics,
because it is the OS of my choice.
because it is the Operation System of my choice.
If you are interested in more output of me please visit
["my other page"](https://ingolf-wagner.de).

View File

@ -128,7 +128,7 @@ let
source = lib.evalSource [
{
nixpkgs.git = {
ref = "nixos-18.03";
ref = "origin/nixos-21.05";
url = https://github.com/NixOS/nixpkgs-channels;
};
nixos-config.file = toString ./configuration.nix;
@ -146,7 +146,7 @@ in {
Now you can deploy the machine by running:
```shell
$> nix-build ./krops.nix -A server01 && result
$> nix-build ./krops.nix -A server01 && ./result
```
You need to make sure you have ssh access to the root user on `server01.mydomain.org`
@ -397,7 +397,7 @@ in {
server01 = server01;
server02 = server02;
all = pkgs.writeScript "deploy-all-servers"
(lib.concatStringSep "\n" [ server01 server02 ]);
(lib.concatStringsSep "\n" [ server01 server02 ]);
}
```

View File

@ -1,29 +0,0 @@
---
title: "Kubernetes"
date: 2018-06-18T08:56:23+02:00
tags: ["kubernetes", "tinc", "nixos"]
draft: true
---
# My Kubernetes Setup
Here I describe how I setup my home network.
## Tinc
how tinc is configured
## How Kubernetes is configured
### diagram
Hier
### flannel usage
write me
### how to make the services work ?
todo

268
content/nixos/language-server.md Executable file
View File

@ -0,0 +1,268 @@
---
title: Language Server
date: 2019-09-11
tags:
- NixOS
summary: >
How to setup your projects using lsp, emacs (or your favorite editor), direnv and nix-shell.
---
# Setup
In this article we are discussing a concrete setup with concrete tools and a concrete language.
But the solutions described here, are intended to help you with your set up.
Here are the Tools used.
* [Spacemacs](http://spacemacs.org/) : my editor or choice.
* [all-hies](https://github.com/Infinisil/all-hies) : to start a [haskell-ide-engine](https://github.com/haskell/haskell-ide-engine) which is the haskell-lsp-server.
* [direnv](https://direnv.net/) : to automatically load `shell.nix` configuration in my editor, when opening a file.
* [lsp-haskell.el](https://github.com/emacs-lsp/lsp-haskell) : the emacs plugin to interact with the haskell-ide-engine.
* [nix-shell](https://nixos.wiki/wiki/Development_environment_with_nix-shell) : because all projects should have one.
## Goal
* Configure Spacemacs as much as possible via `configuration.nix`, without the `lsp-server` being configured by the `configuration.nix`.
* The `lsp-server` setup should be fully defined inside the `shell.nix` of the project I'm working on.
This way project specific tweaks are stored in the place where it belongs,
and other people can use their favorite IDE with the same setup.
# Configure Spacemacs
Spacemacs is basically an `~/.emacs.d` folder and a mutable file `~/.spacemacs`.
I tried to configure `~/.spacemacs` via [home-manager](https://github.com/rycee/home-manager)
but this does not play well with updates and with `customization`.
Now I'm using [home-manager](https://github.com/rycee/home-manager)
to configure files in `~/.spacemacs.d/` and `load` them in
the configuration functions inside `~/.spacemacs`. A simple `(load "~/.spacemacs.d/hook-user-config.el")`
inside the `dotspacemacs/user-config` function is enough, to make it work.
```nix
{ pkgs, lib, config, ... }:
let
user = "mainUser";
userName = config.users.users."${user}".name;
home = config.users.users."${user}".home;
fontSize = 14;
startupBanner = pkgs.fetchurl{
url = "https://github.com/NixOS/nixos-homepage/raw/master/logo/nix-wiki.png";
sha256 = "1hrz7wr7i0b2bips60ygacbkmdzv466lsbxi22hycg42kv4m0173";
};
in
{
systemd.services =
let
clone =
repository: folder: branch:
{
enable = true;
wantedBy = [ "multi-user.target" ];
description = "clone ${repository} to ${folder}";
serviceConfig.User = userName;
unitConfig.ConditionPathExists = "!${folder}";
script = ''
${pkgs.git}/bin/git clone ${repository} --branch ${branch} ${folder}
'';
};
in
{
emacs-pull = clone "https://github.com/syl20bnr/spacemacs" "${home}/.emacs.d" "master";
};
home-manager.users."${user}" = {
home.file.".spacemacs.d/hook-init.el".text = ''
;; just add (load "~/.spacemacs.d/hook-init.el")
;; at the end of dotspacemacs/init function
;; overrides of dotspacemacs/init ()
(setq-default
dotspacemacs-themes '(solarized-light solarized-dark)
dotspacemacs-startup-banner "${startupBanner}"
dotspacemacs-default-font '("Terminus"
:size ${toString fontSize}
:weight normal
:width normal
:powerline-scale 1.1))
'';
home.file.".spacemacs.d/hook-layers.el".text = ''
;; just add (load "~/.spacemacs.d/hook-layers.el")
;; at the end of dotspacemacs/layers function
(let
((user-layers dotspacemacs-configuration-layers))
(setq
dotspacemacs-configuration-layers
(append user-layers
'( spell-checking
syntax-checking
(haskell :variables
haskell-enable-hindent t
haskell-completion-backend 'lsp
haskell-enable-hindent-style "gibiansky"
haskell-process-type 'cabal-new-repl)
))))
(let
((user-packages dotspacemacs-additional-packages ))
(setq
dotspacemacs-additional-packages
(append user-packages
'( lsp-mode
lsp-ui
lsp-haskell
direnv
))))
'';
home.file.".spacemacs.d/hook-user-config.el".text = ''
;; just add (load "~/.spacemacs.d/hook-user-config.el")
;; at the end of dotspacemacs/user-config function
;; lsp setup for haskell
;; hie-wrapper must be installed and configured in the direnv setup
(setq lsp-haskell-process-path-hie "hie-wrapper")
(setq lsp-response-timeout 60)
(require 'lsp-haskell)
(add-hook 'haskell-mode-hook #'lsp)
(add-hook 'haskell-mode-hook #'direnv-update-environment)
'';
};
}
```
We setup emacs to run `direnve-update-environment` and `lsp` once we start the `haskell-mode`.
But we did not install `lsp`.
In my setups the `lsp-server` is installed by the project file (lsp.nix), and is loaded via `direnv` (`direnv-update-environment` in emacs).
If you don't like that just use the snippet from the next section.
## Alternative Configuration (install lsp in the configuration.nix)
You can install the `lsp` (in our case `hie-wrapper`) globally in your `configuration.nix` .
I usually do this in my projects (via `lsp.nix`). Here is the part that differs.
```nix
home.file.".spacemacs.d/hook-user-config.el".text =
let
all-hies = import (fetchTarball "https://github.com/infinisil/all-hies/tarball/master") {};
in ''
;; just add (load "~/.spacemacs.d/hook-user-config.el")
;; at the end of dotspacemacs/user-config function
;; lsp setup for haskell
(setq lsp-haskell-process-path-hie
"${all-hies.selection{ selector = p: { inherit (p) ghc864;}; } }/bin/hie-wrapper")
(setq lsp-response-timeout 60)
(require 'lsp-haskell)
(add-hook 'haskell-mode-hook #'lsp)
(add-hook 'haskell-mode-hook #'direnv-update-environment) ;; still needed
'';
```
# Setup the project
For a Haskell project I have this minimal setup of files.
## lsp.nix
This file is to setup the `lsp-server`.
If you already installed the `lsp-server` via the `configuration.nix`, this file is not necessary,
but also does not hurt.
```nix
{ pkgs ? import <nixpkgs> {} }:
let
all-hies = import (fetchTarball "https://github.com/infinisil/all-hies/tarball/master") {};
in
pkgs.mkShell {
buildInputs = with pkgs; [
haskellPackages.hoogle
haskellPackages.hindent
haskellPackages.hlint
haskellPackages.stylish-haskell
(all-hies.selection { selector = p: {inherit (p) ghc864; }; })
];
}
```
## env.nix
Provides the environment to run
`cabal test` and `cabal build`.
All package files (e.g. `./current-project.nix`) are created by `cabal2nix`.
```nix
{ pkgs ? import <nixpkgs> {
overlays = [
(self: super: {
haskellPackages = super.haskellPackages.override {
overrides = self: super: {
datetime = super.callPackage ./datetime.nix {};
current-project = super.callPackage ./current-project.nix { };
};
};
})];
}}:
pkgs.haskellPackages.current-project.env
```
## `shell.nix`
For other scripts and tooling important for development.
```nix
{ pkgs ? import <nixpkgs> {} }:
let
updateCabal = pkgs.writeShellScriptBin "update-cabal" /* sh */ ''
echo "# created by cabal2nix " > ${toString ./.}/current-project.nix
${pkgs.cabal2nix}/bin/cabal2nix ${toString ./.} >> ${toString ./.}/current-project.nix
'';
in
pkgs.mkShell {
buildInputs = with pkgs; [
updateCabal
openapi-generator-cli
openssl
cabal2nix
];
}
```
## `.envrc`
finally we need a `direnv` configuration file.
`direnv` and the `direnv-mode` make it possible
to load the environment needed and provided by the `*.nix` files.
```sh
use nix ./env.nix
use nix ./lsp.nix
use nix ./shell.nix
```
Don't forget to run `direnv allowed . ` in the project folder.
# Conclusion
Now we are capable to use the `lsp-server` configured in all our projects,
with the editor we prefer.
Your colleagues will have little problems with the setup and improve it.
If you prefer to install the lsp globally, you can simply do that as described,
this will not interfere with the `lsp` server setup in the `lsp.nix` file.
I'm running this setup for quite a while now, and
I experience little to no problems with it.
The most common thing is that I have to fire `lsp-restart-workspace` to remove old errors,
but doing this every hour is not a problem for me.
## Support
If you have comments or problems just ping me `palo @ irc.freenode.net`

View File

@ -1,16 +0,0 @@
---
title: "Nix Generators"
date: 2018-06-27T19:09:36+02:00
draft: true
---
# Nix Generators for the win.
Today I'll talk about a nice project which might your live simpler.
[nixos-generators](https://github.com/Lassulus/nixos-generators)
## Creating installation ISO
You want to create a iso that alreay knows the wifi password and starts sshd and root knows your ssh key?
This is you choice.

View File

@ -8,7 +8,8 @@ tags:
- Ansible
- Terraform
summary: >
A tool to create your JSON generator.
I like NixOS and the way modules work. I miss them when I do tasks in other languages that have less power than NixOS, for example Ansible and Terraform.
Luckily all these tools can be configured via JSON, and Nix can easily create JSON.
---
# nix-instantiate
@ -393,7 +394,7 @@ Whoa, a lot of other resources joined the party.
Additionally, the `additionalFileSize` parameter is
properly removed from `resource.hcloud_server.test`.
You could also create this very simple example in `HCL` by using
You could also create this very simple example in `HCL` by using
`variables`, `locals` and `count`.
By doing that, you already reached the limits of
`HCL` but in Nix this is a very simple example.

View File

@ -47,11 +47,12 @@ To find the newest `rev` and `sha256` just call `nix-shell -p nix-prefetch-git -
```
{pkgs, ... }:
let
tincModule = {
url = "https://github.com/mrVanDalo/nixos-tinc.git";
rev = "8755d954fcadeef5d0e30488a7b11e3f1a505769";
sha256 = "0swkk5zxg9vqdf2j0m9zki13wr0g8ws77y4v5wzklrdcmbny5qjm";
tincModule = pkgs.fetchgit {
"url" = "https://github.com/mrVanDalo/nixos-tinc.git";
"rev" = "1b8c822a20be38ca19120f4c5d7f9f3236851674";
"sha256" = "0a99rxhrqwh454q6w1znb0icdpm8fl4rnr1dr7xblacqjmghhyh1";
};
in {
imports = [
"${tincModule}"
@ -113,8 +114,8 @@ but for this example we only have one.
{{<figure src="/nixos/tinc/3computers.svg">}}
Here is the `configuration.nix`.
First we define the whole topolgy in `default` and
than we `enable` and configure secret-keys
First we define the whole topology in `default` and
then we `enable` and configure secret-keys
for every computer in `Gibson`, `Hackbardt` and `HAL`
```
@ -122,11 +123,11 @@ let
includePrivateKeys = host: {
deployment.keys."rsa_key" = {
keyFile = ./secrets/"${host}"/rsa_key.priv;
keyFile = toString (./secrets/ + "/${host}/rsa_key.priv");
destDir = "/root/secrets";
};
deployment.keys."ed25519_key" = {
keyFile = ./secrets/"${host}"/ed25519_key.priv;
keyFile = toString (./secrets/ + "/${host}/ed25519_key.priv");
destDir = "/root/secrets";
};
};
@ -142,7 +143,7 @@ default =
with lib;
services.custom.tinc =
let
publicHostFile = host: fileContent ./public/"${host}"/hostfile;
publicHostFile = host: lib.fileContents (./public + "/${host}/hostfile");
in {
"private" = {
debugLevel = 0;
@ -167,27 +168,9 @@ default =
};
}
# Gibson specific
# ---------------
Gibson =
{config, pkgs, ... }:
includePrivateKeys "Gibson" // {
services.custom.tinc = {
"private" = {
enable = true;
privateRsaKeyFile = config.deployment.keys."rsa_key".path;
privateEd25519KeyFile = config.deployment.keys."ed25519_key".path;
};
};
}
# Hackbardt specific
# ------------------
Hackbardt =
{config, pkgs, ... }:
includePrivateKeys "Hackbardt" // {
services.custom.tinc = {
"private" = {
Gibson =
enable = true;
connectTo = [ "Gibson" ];
privateRsaKeyFile = config.deployment.keys."rsa_key".path;
@ -260,7 +243,7 @@ to configure sub-network routing.
Achieving this is very simple,
just add the `tincSubnet` parameter in the `hosts` attribute and your done.
```
```nix
...
default =
@ -269,7 +252,7 @@ default =
with lib;
services.custom.tinc =
let
publicHostFile = name: fileContent ./public/"${name}"/hostfile;
publicHostFile = name: lib.fileContents (./public + "/${host}/hostfile");
in {
"private" = {
debugLevel = 0;