<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Lafuente</title>
<link href="https://www.lafuente.me/feed/feed.xml" rel="self"/>
<link href="https://www.lafuente.me/"/>
<updated>2022-03-11T14:56:14.005-00:00</updated>
<id>https://www.lafuente.me/</id>
<author>
<name>José Luis Lafuente</name>
<email>jl@lafuente.me</email>
</author>
<entry>
<title>Custom Clojure helpers in your REPL</title>
<link href="https://www.lafuente.me/posts/clojure-setup"/>
<updated>2022-03-07T00:00:00-00:00</updated>
<id>https://www.lafuente.me/posts/clojure-setup</id>
<category term="clojure"/>
<content type="html">&lt;h2 id=&quot;the-problem&quot;&gt;The problem &lt;a class=&quot;direct-link&quot; href=&quot;#the-problem&quot;&gt;#&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;Over time, I wrote several Clojure helper functions I use while I&#x27;m writing new code. I want to load those helpers every time I start a Clojure REPL. How can I make those helpers available in any Clojure project I&#x27;m working on? Especially in 3rd party projects I don&#x27;t control.&lt;/p&gt; &lt;h2 id=&quot;the-solution&quot;&gt;The solution &lt;a class=&quot;direct-link&quot; href=&quot;#the-solution&quot;&gt;#&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;Traditionally, Clojure developers put development utilities in a &lt;code&gt;user.clj&lt;/code&gt; file, since Clojure automatically loads any &lt;code&gt;user.clj&lt;/code&gt; found in the classpath. In recent Clojure versions, Clojure CLI was introduced, and now we can call any Clojure function from the command line. Knowing that, a better alternative is to move all our helpers to their own project, and to create an alias in our &lt;code&gt;~/.config/clojure/deps.edn&lt;/code&gt; for those utilities.&lt;/p&gt; &lt;p&gt;As an example, let&#x27;s suppose this is the main file for my helpers project:&lt;/p&gt; &lt;pre class=&quot;language-clojure&quot;&gt;&lt;code class=&quot;language-clojure&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;ns&lt;/span&gt; local-utils&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;br&gt;&lt;br&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;defn&lt;/span&gt; init&lt;br&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:keys&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;main&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;br&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;println&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Loading helpers...&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;br&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token keyword&quot;&gt;load-file&lt;/span&gt; main&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;We can add an alias in our &lt;code&gt;deps.edn&lt;/code&gt; file:&lt;/p&gt; &lt;pre class=&quot;language-clojure&quot;&gt;&lt;code class=&quot;language-clojure&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:aliases&lt;/span&gt;&lt;br&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:user&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:exec-fn&lt;/span&gt; local-utils/init&lt;br&gt; &lt;span class=&quot;token operator&quot;&gt;:extra-deps&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;me.lafuente/clj-dev-utils &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:local&lt;/span&gt;/&lt;span class=&quot;token keyword&quot;&gt;root&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;$HOME/projects/clj-dev-utils&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;Now, in any project, we can do &lt;code&gt;clj -X:foo:bar:user :main &amp;quot;path/to/main.clj&amp;quot;&lt;/code&gt;. In this example, we are just printing a message before loading the main entry point, but we can do whatever we want.&lt;/p&gt; &lt;p&gt;My personal Clojure helpers are here: &lt;a href=&quot;https://github.com/jlesquembre/clj-dev-utils&quot;&gt;https://github.com/jlesquembre/clj-dev-utils&lt;/a&gt;&lt;/p&gt; &lt;p&gt;My &lt;code&gt;init&lt;/code&gt; function loads some helper utilities, initializes &lt;a href=&quot;https://github.com/djblue/portal&quot;&gt;portal&lt;/a&gt;, enables &lt;a href=&quot;https://github.com/metosin/malli&quot;&gt;malli&lt;/a&gt; instrumentation (if present in the classpath) and starts a &lt;a href=&quot;https://nrepl.org/&quot;&gt;nREPL&lt;/a&gt; server. We can also provide the main function to be loaded.&lt;/p&gt; &lt;p&gt;A library I&#x27;m using for my helpers is &lt;a href=&quot;https://github.com/gfredericks/dot-slash-2&quot;&gt;https://github.com/gfredericks/dot-slash-2&lt;/a&gt; With it, I can create aliases under the &lt;code&gt;.&lt;/code&gt; namespace. For example, &lt;code&gt;./sh&lt;/code&gt; points to &lt;code&gt;clojure.java.shell/sh&lt;/code&gt;. The &lt;code&gt;.&lt;/code&gt; namespace is loaded automatically, so I can evaluate &lt;code&gt;(./sh &amp;quot;ls&amp;quot;)&lt;/code&gt; in any file without an explicit &lt;code&gt;require&lt;/code&gt;&lt;/p&gt;
</content>
</entry>
<entry>
<title>Web components and eleventy</title>
<link href="https://www.lafuente.me/posts/webcomponents-eleventy"/>
<updated>2020-08-11T00:00:00-00:00</updated>
<id>https://www.lafuente.me/posts/webcomponents-eleventy</id>
<category term="11ty"/><category term="webcomponents"/>
<content type="html">&lt;p&gt;If you want to have some dynamic content in your &lt;a href=&quot;https://www.11ty.dev/&quot;&gt;eleventy&lt;/a&gt; static website, a good option is to use Web Components, they play very well together.&lt;/p&gt; &lt;p&gt;I&#x27;m going to explain how I added a web component to my blog, in this example I&#x27;ll use &lt;a href=&quot;https://modelviewer.dev/&quot;&gt;model-viewer&lt;/a&gt; component. This is the final result:&lt;/p&gt; &lt;p&gt;&lt;model-viewer src=&quot;/models/Astronaut.glb&quot; style=&quot;height: 50vh&quot; alt=&quot;A 3D model of an astronaut&quot; auto-rotate camera-controls&gt;&lt;/model-viewer&gt;&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;&lt;a href=&quot;https://poly.google.com/view/dLHpzNdygsg&quot;&gt;Astronaut&lt;/a&gt; by &lt;a href=&quot;https://poly.google.com/user/4aEd8rQgKu2&quot;&gt;Poly&lt;/a&gt;, licensed under &lt;a href=&quot;https://creativecommons.org/licenses/by/2.0/&quot;&gt;CC-BY&lt;/a&gt;.&lt;/p&gt; &lt;/blockquote&gt; &lt;p&gt;First, make sure that you set the &lt;code&gt;html&lt;/code&gt; option for &lt;em&gt;markdownIt&lt;/em&gt; to &lt;code&gt;true&lt;/code&gt; in your &lt;a href=&quot;https://www.11ty.dev/&quot;&gt;eleventy&lt;/a&gt; config file (usually &lt;code&gt;.eleventy.js&lt;/code&gt;):&lt;/p&gt; &lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;module&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function-variable function&quot;&gt;exports&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;eleventyConfig&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;br&gt; &lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; markdownIt &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;markdown-it&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br&gt; &lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt; options &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;br&gt; html&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;&lt;br&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br&gt;&lt;br&gt; eleventyConfig&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;setLibrary&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;md&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;markdownIt&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;options&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;You also need to tell &lt;a href=&quot;https://www.11ty.dev/&quot;&gt;eleventy&lt;/a&gt; to copy the web components to your output directory. If you installed &lt;a href=&quot;https://modelviewer.dev/&quot;&gt;model-viewer&lt;/a&gt; with npm, you can copy it adding this to your &lt;code&gt;.eleventy.js&lt;/code&gt; config file:&lt;/p&gt; &lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;eleventyConfig&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;addPassthroughCopy&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;br&gt; &lt;span class=&quot;token string&quot;&gt;&quot;node_modules/@google/model-viewer/dist/model-viewer.min.js&quot;&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;:&lt;/span&gt;&lt;br&gt; &lt;span class=&quot;token string&quot;&gt;&quot;js-modules/model-viewer.min.js&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;But you also need to import the web components in your web pages. To do that, I&#x27;m taking advantage of &lt;a href=&quot;https://www.11ty.dev/&quot;&gt;eleventy&lt;/a&gt;&#x27;s &lt;a href=&quot;https://www.11ty.dev/docs/data-frontmatter/&quot;&gt;Front Matter Data&lt;/a&gt; and the &lt;a href=&quot;https://www.11ty.dev/docs/data-cascade/&quot;&gt;Data Cascade&lt;/a&gt;. In the &lt;a href=&quot;https://www.11ty.dev/docs/data-frontmatter/&quot;&gt;front matter&lt;/a&gt; I define the components I want to use, that way I can load different components per page:&lt;/p&gt; &lt;pre&gt;&lt;code&gt;--- title: Web components and eleventy tags: - 11ty - webcomponents modules: - &amp;quot;model-viewer.min.js&amp;quot; --- &lt;/code&gt;&lt;/pre&gt; &lt;p&gt;The &lt;code&gt;modules&lt;/code&gt; property (you can use another name) is a list with all the files I want to load in that page. You need to process that property when the template is rendered. I use &lt;a href=&quot;https://www.11ty.dev/docs/languages/javascript/&quot;&gt;JavaScript&lt;/a&gt; for my templates, plus &lt;a href=&quot;https://github.com/popeindustries/lit-html-server&quot;&gt;lit-html-server&lt;/a&gt;, but you should be able to adapted the next snippet to any of the &lt;a href=&quot;https://www.11ty.dev/docs/languages/&quot;&gt;Template Languages&lt;/a&gt; supported by &lt;a href=&quot;https://www.11ty.dev/&quot;&gt;eleventy&lt;/a&gt;:&lt;/p&gt; &lt;pre class=&quot;language-js&quot;&gt;&lt;code class=&quot;language-js&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; html&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; renderToString &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;require&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;@popeindustries/lit-html-server&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br&gt;module&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;exports &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;token class-name&quot;&gt;BaseTemplate&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;br&gt; &lt;span class=&quot;token keyword&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;render&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;br&gt; &lt;span class=&quot;token keyword&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;renderToString&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;br&gt; html&lt;span class=&quot;token template-string&quot;&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&lt;br&gt; &lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;${&lt;/span&gt;data&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;modules&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;br&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token parameter&quot;&gt;file&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&gt;&lt;/span&gt;&lt;br&gt; html&lt;span class=&quot;token template-string&quot;&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&amp;lt;script type=&quot;module&quot; src=&quot;/js-modules/&lt;/span&gt;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;${&lt;/span&gt;file&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&quot;&gt;&amp;lt;/script&gt;&lt;/span&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;/span&gt;&lt;br&gt; &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token interpolation-punctuation punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token string&quot;&gt;&lt;br&gt; &lt;/span&gt;&lt;span class=&quot;token template-punctuation string&quot;&gt;`&lt;/span&gt;&lt;/span&gt;&lt;br&gt; &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;You can see the real file here: &lt;a href=&quot;https://github.com/jlesquembre/blog/blob/d1cbf61d5d1f37baaa686c063190b637efb95c6c/_includes/layouts/base.11ty.js&quot;&gt;blog/base.11ty.js&lt;/a&gt;&lt;/p&gt; &lt;p&gt;And now you can just write the html directly on your markdown files:&lt;/p&gt; &lt;pre class=&quot;language-html&quot;&gt;&lt;code class=&quot;language-html&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;&lt;/span&gt;model-viewer&lt;/span&gt;&lt;br&gt; &lt;span class=&quot;token attr-name&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;/models/Astronaut.glb&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;br&gt; &lt;span class=&quot;token attr-name&quot;&gt;alt&lt;/span&gt;&lt;span class=&quot;token attr-value&quot;&gt;&lt;span class=&quot;token punctuation attr-equals&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;A 3D model of an astronaut&lt;span class=&quot;token punctuation&quot;&gt;&quot;&lt;/span&gt;&lt;/span&gt;&lt;br&gt; &lt;span class=&quot;token attr-name&quot;&gt;auto-rotate&lt;/span&gt;&lt;br&gt; &lt;span class=&quot;token attr-name&quot;&gt;camera-controls&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token tag&quot;&gt;&lt;span class=&quot;token punctuation&quot;&gt;&amp;lt;/&lt;/span&gt;model-viewer&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;This makes pretty easy to embedded custom components in your markdown documents, making it similar to writing &lt;a href=&quot;https://mdxjs.com/&quot;&gt;MDX&lt;/a&gt;.&lt;/p&gt;
</content>
</entry>
<entry>
<title>Custom home-manager installation with NixOS</title>
<link href="https://www.lafuente.me/posts/installing-home-manager"/>
<updated>2020-07-21T00:00:00-00:00</updated>
<id>https://www.lafuente.me/posts/installing-home-manager</id>
<category term="home-manager"/><category term="nixos"/>
<content type="html">&lt;p&gt;Recently I hear about &lt;a href=&quot;https://github.com/ryantm/home-manager-template&quot;&gt;home-manager-template&lt;/a&gt;. The project rationale resonates with me. In fact, I did something similiar on my NixOS &lt;code&gt;configuration.nix&lt;/code&gt;.&lt;/p&gt; &lt;p&gt;Apart of trying to make the &lt;a href=&quot;https://rycee.gitlab.io/home-manager/&quot;&gt;home-manager&lt;/a&gt; installation more reproducible, my goals are:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Install &lt;a href=&quot;https://rycee.gitlab.io/home-manager/&quot;&gt;home-manager&lt;/a&gt; from my system &lt;code&gt;configuration.nix&lt;/code&gt;.&lt;/li&gt; &lt;li&gt;Use &lt;a href=&quot;https://rycee.gitlab.io/home-manager/&quot;&gt;home-manager&lt;/a&gt; from a git checkout. That makes easier for me to test new ideas or patches.&lt;/li&gt; &lt;li&gt;Don&#x27;t repeat my self. I don&#x27;t want to define the same variable at the system level and in &lt;a href=&quot;https://rycee.gitlab.io/home-manager/&quot;&gt;home-manager&lt;/a&gt;, e.g.: my username or my hostname.&lt;/li&gt; &lt;/ul&gt; &lt;p&gt;To accomplish that, I have the following function in my &lt;code&gt;configuration.nix&lt;/code&gt;:&lt;/p&gt; &lt;pre class=&quot;language-nix&quot;&gt;&lt;code class=&quot;language-nix&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt;&lt;br&gt; user &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;john&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br&gt; userHome &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;/home/&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token antiquotation variable&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;user&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br&gt; hostName &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;laptop&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br&gt;&lt;br&gt; home&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;manager &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; home&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;manager&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;path&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; config&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;path &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;&lt;br&gt; &lt;span class=&quot;token keyword&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;builtins&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;typeOf&lt;/span&gt; home&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;manager&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;path &lt;span class=&quot;token operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;string&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br&gt; &lt;span class=&quot;token keyword&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;builtins&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;typeOf&lt;/span&gt; config&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;path &lt;span class=&quot;token operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;string&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;br&gt; pkgs&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;callPackage&lt;br&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token url&quot;&gt;/.&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; home&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;manager&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;path &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;/home-manager&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; path &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token antiquotation variable&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;home&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;manager&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;path&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;br&gt; &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;overrideAttrs &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;old&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;br&gt; nativeBuildInputs &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt; pkgs&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;makeWrapper &lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br&gt; buildCommand &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;br&gt; &lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt;&lt;br&gt; home&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;mananger&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;bootstrap &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; pkgs&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;writeTextFile &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;br&gt; name &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;home-manager-bootstrap.nix&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br&gt; text &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#x27;&#x27;&lt;br&gt; { config, pkgs, ... }:&lt;br&gt; {&lt;br&gt; # Home Manager needs a bit of information about you and the&lt;br&gt; # paths it should manage.&lt;br&gt; home.username = &quot;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token antiquotation variable&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;user&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&quot;;&lt;br&gt; home.homeDirectory = &quot;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token antiquotation variable&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;userHome&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&quot;;&lt;br&gt; home.sessionVariables.HOSTNAME = &quot;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token antiquotation variable&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;hostName&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&quot;;&lt;br&gt; imports = [ &lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token antiquotation variable&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;config&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;path&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt; ];&lt;br&gt; }&lt;br&gt; &#x27;&#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;in&lt;/span&gt;&lt;br&gt; &lt;span class=&quot;token string&quot;&gt;&#x27;&#x27;&lt;br&gt; &lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token antiquotation variable&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;old&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;buildCommand&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;br&gt; wrapProgram $out/bin/home-manager --set HOME_MANAGER_CONFIG &quot;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token antiquotation variable&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;home&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;mananger&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;bootstrap&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&quot;&lt;br&gt; &#x27;&#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;token keyword&quot;&gt;in&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;br&gt; users&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;users&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token antiquotation variable&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;user&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;br&gt; home &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; userHome&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br&gt; packages &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;br&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;home&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;manager &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;br&gt; home&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;manager&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;path &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token antiquotation variable&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;userHome&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;/home-manager&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br&gt; config&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;path &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;builtins&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;toString&lt;/span&gt; &lt;span class=&quot;token url&quot;&gt;../home-manager&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;/&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token antiquotation variable&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;hostName&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;.nix&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;br&gt; &lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;Let&#x27;s break that code to understand what is happening.&lt;/p&gt; &lt;pre class=&quot;language-nix&quot;&gt;&lt;code class=&quot;language-nix&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt;&lt;br&gt; user &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;john&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br&gt; userHome &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;/home/&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token antiquotation variable&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;user&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br&gt; hostName &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;laptop&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;First I define some variables I&#x27;ll use later. It is possible to define a function where you pass them as arguments, but for now I&#x27;m just using a let block.&lt;/p&gt; &lt;hr&gt; &lt;pre class=&quot;language-nix&quot;&gt;&lt;code class=&quot;language-nix&quot;&gt; home&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;manager &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; home&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;manager&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;path&lt;span class=&quot;token punctuation&quot;&gt;,&lt;/span&gt; config&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;path &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt;&lt;br&gt; &lt;span class=&quot;token keyword&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;builtins&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;typeOf&lt;/span&gt; home&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;manager&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;path &lt;span class=&quot;token operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;string&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br&gt; &lt;span class=&quot;token keyword&quot;&gt;assert&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;builtins&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;typeOf&lt;/span&gt; config&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;path &lt;span class=&quot;token operator&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;string&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;Now I define a function responsible for installing &lt;a href=&quot;https://rycee.gitlab.io/home-manager/&quot;&gt;home-manager&lt;/a&gt; . It takes 2 arguments, &lt;code&gt;home-manager-path&lt;/code&gt; (path to my local &lt;a href=&quot;https://rycee.gitlab.io/home-manager/&quot;&gt;home-manager&lt;/a&gt; git checkout) and &lt;code&gt;config-path&lt;/code&gt; (path to my main &lt;a href=&quot;https://rycee.gitlab.io/home-manager/&quot;&gt;home-manager&lt;/a&gt; configuration file, usually called &lt;code&gt;home.nix&lt;/code&gt;). I&#x27;m also type-checking the arguments.&lt;/p&gt; &lt;hr&gt; &lt;pre class=&quot;language-nix&quot;&gt;&lt;code class=&quot;language-nix&quot;&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;br&gt; pkgs&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;callPackage&lt;br&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;token url&quot;&gt;/.&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; home&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;manager&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;path &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;/home-manager&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt; path &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token antiquotation variable&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;home&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;manager&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;path&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;br&gt; &lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;overrideAttrs &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;old&lt;span class=&quot;token punctuation&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;I&#x27;m calling the derivation provided by &lt;a href=&quot;https://rycee.gitlab.io/home-manager/&quot;&gt;home-manager&lt;/a&gt;, it is defined here:&lt;/p&gt; &lt;p&gt;&lt;a href=&quot;https://github.com/rycee/home-manager/blob/master/home-manager/default.nix&quot;&gt;https://github.com/rycee/home-manager/blob/master/home-manager/default.nix&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Notice that it takes one argument, &lt;code&gt;path&lt;/code&gt;, the path to my local &lt;a href=&quot;https://rycee.gitlab.io/home-manager/&quot;&gt;home-manager&lt;/a&gt; checkout. Since I need further customization, I use the &lt;code&gt;overrideAttrs&lt;/code&gt; function to produce a new derivation based on the original one.&lt;/p&gt; &lt;hr&gt; &lt;pre class=&quot;language-nix&quot;&gt;&lt;code class=&quot;language-nix&quot;&gt; nativeBuildInputs &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt; pkgs&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;makeWrapper &lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br&gt; buildCommand &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;br&gt; &lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt;&lt;br&gt; home&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;mananger&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;bootstrap &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; pkgs&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;writeTextFile &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;br&gt; &lt;span class=&quot;token comment&quot;&gt;# ...&lt;/span&gt;&lt;br&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;in&lt;/span&gt;&lt;br&gt; &lt;span class=&quot;token string&quot;&gt;&#x27;&#x27;&lt;br&gt; &lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token antiquotation variable&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;old&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;buildCommand&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;br&gt; wrapProgram $out/bin/home-manager --set HOME_MANAGER_CONFIG &quot;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token antiquotation variable&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;home&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;mananger&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;bootstrap&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&quot;&lt;br&gt; &#x27;&#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;These are the arguments for &lt;code&gt;overrideAttrs&lt;/code&gt;. Since I want to wrap &lt;a href=&quot;https://rycee.gitlab.io/home-manager/&quot;&gt;home-manager&lt;/a&gt;, I need &lt;code&gt;pkgs.makeWrapper&lt;/code&gt;.&lt;/p&gt; &lt;p&gt;I&#x27;m extending the build command. I&#x27;m calling the original &lt;a href=&quot;https://rycee.gitlab.io/home-manager/&quot;&gt;home-manager&lt;/a&gt; build command, and then wrapping it to set the environment variable &lt;code&gt;HOME_MANAGER_CONFIG&lt;/code&gt; to a file that I&#x27;m generating with the &lt;code&gt;writeTextFile&lt;/code&gt; helper function. More details on that later. Notice that &lt;code&gt;HOME_MANAGER_CONFIG&lt;/code&gt; is the entrypoint for &lt;a href=&quot;https://rycee.gitlab.io/home-manager/&quot;&gt;home-manager&lt;/a&gt;, usually that file is &lt;code&gt;home.nix&lt;/code&gt;.&lt;/p&gt; &lt;hr&gt; &lt;pre class=&quot;language-nix&quot;&gt;&lt;code class=&quot;language-nix&quot;&gt; home&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;mananger&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;bootstrap &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; pkgs&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;writeTextFile &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;br&gt; name &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;home-manager-bootstrap.nix&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br&gt; text &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#x27;&#x27;&lt;br&gt; { config, pkgs, ... }:&lt;br&gt; {&lt;br&gt; # Home Manager needs a bit of information about you and the&lt;br&gt; # paths it should manage.&lt;br&gt; home.username = &quot;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token antiquotation variable&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;user&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&quot;;&lt;br&gt; home.homeDirectory = &quot;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token antiquotation variable&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;userHome&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&quot;;&lt;br&gt; home.sessionVariables.HOSTNAME = &quot;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token antiquotation variable&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;hostName&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&quot;;&lt;br&gt; imports = [ &lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token antiquotation variable&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;config&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;path&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt; ];&lt;br&gt; }&lt;br&gt; &#x27;&#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;This is how I&#x27;m generating the main the entrypoint file for &lt;a href=&quot;https://rycee.gitlab.io/home-manager/&quot;&gt;home-manager&lt;/a&gt;. It&#x27;s a &lt;code&gt;.nix&lt;/code&gt; file itself, which is added to the nix store. When I generate my NixOS configuration, with &lt;code&gt;nixos-rebuild build&lt;/code&gt;, I know the value for some of the variables needed by &lt;a href=&quot;https://rycee.gitlab.io/home-manager/&quot;&gt;home-manager&lt;/a&gt;, like my username or the hostname. I&#x27;m taking advange of that to generate a minimal &lt;code&gt;home.nix&lt;/code&gt; file, where the values for that variables are injected, and then I&#x27;m importing my real &lt;a href=&quot;https://rycee.gitlab.io/home-manager/&quot;&gt;home-manager&lt;/a&gt; configuration (defined by the &lt;code&gt;config-path&lt;/code&gt; variable)&lt;/p&gt; &lt;hr&gt; &lt;pre class=&quot;language-nix&quot;&gt;&lt;code class=&quot;language-nix&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;in&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;br&gt; users&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;users&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token antiquotation variable&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;user&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;br&gt; home &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; userHome&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br&gt; packages &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt;&lt;br&gt; &lt;span class=&quot;token punctuation&quot;&gt;(&lt;/span&gt;home&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;manager &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;br&gt; home&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;manager&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;path &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token antiquotation variable&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;userHome&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;/home-manager&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br&gt; config&lt;span class=&quot;token operator&quot;&gt;-&lt;/span&gt;path &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token keyword&quot;&gt;builtins&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;token function&quot;&gt;toString&lt;/span&gt; &lt;span class=&quot;token url&quot;&gt;../home-manager&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;/&lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token antiquotation variable&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;hostName&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;.nix&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;)&lt;/span&gt;&lt;br&gt; &lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;The last step, this is how I install &lt;a href=&quot;https://rycee.gitlab.io/home-manager/&quot;&gt;home-manager&lt;/a&gt; from my NixOS &lt;code&gt;configuration.nix&lt;/code&gt;. I&#x27;m just adding the package returned by my &lt;code&gt;home-manager&lt;/code&gt; function. The 2 arguments to the functions are the path to my local &lt;a href=&quot;https://rycee.gitlab.io/home-manager/&quot;&gt;home-manager&lt;/a&gt; checkout and the path to my &lt;code&gt;home.nix&lt;/code&gt; file.&lt;/p&gt;
</content>
</entry>
<entry>
<title>Running a local dns and web server</title>
<link href="https://www.lafuente.me/posts/local-dns-and-web-server"/>
<updated>2020-06-24T00:00:00-00:00</updated>
<id>https://www.lafuente.me/posts/local-dns-and-web-server</id>
<category term="dns"/><category term="nix"/><category term="webserver"/>
<content type="html">&lt;p&gt;As a software developer, I run multiple web services to be accessed only from localhost. While it is possible to access them on &lt;code&gt;http://localhost&lt;/code&gt;, I prefer to have more descriptive urls, like &lt;code&gt;http://docs.local&lt;/code&gt;.&lt;/p&gt; &lt;p&gt;I&#x27;m going to describe my &lt;a href=&quot;https://nixos.org/&quot;&gt;NixOS&lt;/a&gt; setup to resolve &lt;code&gt;.local&lt;/code&gt; domains to localhost and access my local web server. I&#x27;m using &lt;a href=&quot;https://coredns.io/&quot;&gt;CoreDNS&lt;/a&gt; and &lt;a href=&quot;https://caddyserver.com/&quot;&gt;Caddy&lt;/a&gt; to accomplish it. Keep in mind that while I&#x27;m showing nix configuration snippets, you could extract the configuration files and run a similar setup in any Linux distribution.&lt;/p&gt; &lt;p&gt;It is interesting to notice that &lt;a href=&quot;https://coredns.io/&quot;&gt;CoreDNS&lt;/a&gt; started its life as a fork of &lt;a href=&quot;https://caddyserver.com/&quot;&gt;Caddy&lt;/a&gt;.&lt;/p&gt; &lt;h1 id=&quot;dns-server&quot;&gt;DNS server &lt;a class=&quot;direct-link&quot; href=&quot;#dns-server&quot;&gt;#&lt;/a&gt;&lt;/h1&gt; &lt;p&gt;While I could use &lt;a href=&quot;http://www.thekelleys.org.uk/dnsmasq/doc.html&quot;&gt;dnsmasq&lt;/a&gt;, I wanted to try a newer DNS server, &lt;a href=&quot;https://coredns.io/&quot;&gt;CoreDNS&lt;/a&gt;. Let&#x27;s start the service with some custom configuration:&lt;/p&gt; &lt;pre class=&quot;language-nix&quot;&gt;&lt;code class=&quot;language-nix&quot;&gt;services&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;coredns&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;enable &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br&gt;services&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;coredns&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;config &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;&lt;br&gt; &lt;span class=&quot;token string&quot;&gt;&#x27;&#x27;&lt;br&gt; . {&lt;br&gt; # Cloudflare and Google&lt;br&gt; forward . 1.1.1.1 1.0.0.1 8.8.8.8 8.8.4.4&lt;br&gt; cache&lt;br&gt; }&lt;br&gt;&lt;br&gt; local {&lt;br&gt; template IN A {&lt;br&gt; answer &quot;{{ .Name }} 0 IN A 127.0.0.1&quot;&lt;br&gt; }&lt;br&gt; }&lt;br&gt; &#x27;&#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;The first block will forward all the DNS requests to Cloudflare and Google DNS servers, and the results will be cached (1 hour by default)&lt;/p&gt; &lt;p&gt;The second block returns an A record with value &lt;code&gt;127.0.0.1&lt;/code&gt; for any request for a &lt;code&gt;.local&lt;/code&gt; domain.&lt;/p&gt; &lt;p&gt;So far, so good, we have a local DNS server up and running. Now we need to configure our network manager to use that DNS server. If you are on &lt;a href=&quot;https://nixos.org/&quot;&gt;NixOS&lt;/a&gt;, that&#x27;s pretty easy:&lt;/p&gt; &lt;pre class=&quot;language-nix&quot;&gt;&lt;code class=&quot;language-nix&quot;&gt;networking&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;networkmanager&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;insertNameservers &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;127.0.0.1&quot;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt; &lt;h1 id=&quot;web-server&quot;&gt;Web server &lt;a class=&quot;direct-link&quot; href=&quot;#web-server&quot;&gt;#&lt;/a&gt;&lt;/h1&gt; &lt;p&gt;I could use &lt;a href=&quot;https://nginx.org/en/docs/&quot;&gt;nginx&lt;/a&gt;, but I decided to use &lt;a href=&quot;https://caddyserver.com/&quot;&gt;Caddy&lt;/a&gt; instead because it comes with an HTTP API out of the box. I&#x27;m not explaining it in this post, but &lt;a href=&quot;https://caddyserver.com/&quot;&gt;Caddy&lt;/a&gt;&#x27;s API opens the door to many interesting possibilities.&lt;/p&gt; &lt;p&gt;Let&#x27;s take a look our &lt;code&gt;Caddyfile&lt;/code&gt; configuration:&lt;/p&gt; &lt;pre&gt;&lt;code&gt;http://docs.local { root * /path/to/dir file_server } &lt;/code&gt;&lt;/pre&gt; &lt;p&gt;Here we are saying that all requests to &lt;code&gt;http://docs.local&lt;/code&gt; should serve static files located at &lt;code&gt;/path/to/dir&lt;/code&gt;.&lt;/p&gt; &lt;p&gt;Until &lt;a href=&quot;https://github.com/NixOS/nixpkgs/pull/86686&quot;&gt;#86686&lt;/a&gt; is merged, you need to create your own systemd unit to start &lt;a href=&quot;https://caddyserver.com/&quot;&gt;Caddy&lt;/a&gt;:&lt;/p&gt; &lt;pre class=&quot;language-nix&quot;&gt;&lt;code class=&quot;language-nix&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;let&lt;/span&gt;&lt;br&gt; caddyConfig &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; pkgs&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;writeText &lt;span class=&quot;token string&quot;&gt;&quot;Caddyfile&quot;&lt;/span&gt;&lt;br&gt; &lt;span class=&quot;token string&quot;&gt;&#x27;&#x27;&lt;br&gt; http://docs.local {&lt;br&gt; root * /path/to/dir&lt;br&gt; file_server&lt;br&gt; }&lt;br&gt; &#x27;&#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;token keyword&quot;&gt;in&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;br&gt; systemd&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;services&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;caddy &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;br&gt; description &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;Caddy web server&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br&gt; after &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;network-online.target&quot;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br&gt; wants &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;network-online.target&quot;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br&gt; wantedBy &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;multi-user.target&quot;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br&gt; serviceConfig &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;br&gt; User &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;caddy&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br&gt; Group &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;caddy&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br&gt; ExecStart &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#x27;&#x27;&lt;br&gt; &lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token antiquotation variable&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;pkgs&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;caddy2&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;/bin/caddy run --config &lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token antiquotation variable&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;caddyConfig&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt; --adapter caddyfile&lt;br&gt; &#x27;&#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br&gt; ExecReload &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&#x27;&#x27;&lt;br&gt; &lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token antiquotation variable&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;pkgs&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;caddy2&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt;/bin/caddy reload --config &lt;span class=&quot;token interpolation&quot;&gt;&lt;span class=&quot;token antiquotation variable&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;caddyConfig&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/span&gt; --adapter caddyfile&lt;br&gt; &#x27;&#x27;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br&gt; TimeoutStopSec &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;5s&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br&gt; LimitNOFILE &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;1048576&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br&gt; LimitNPROC &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;512&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br&gt; PrivateTmp &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br&gt; ProtectSystem &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;full&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br&gt; AmbientCapabilities &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;cap_net_bind_service&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br&gt;&lt;br&gt; users&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;users&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;caddy &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;br&gt; group &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;caddy&quot;&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br&gt; uid &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; config&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;ids&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;uids&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;caddy&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br&gt; home &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; caddyDir&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br&gt; createHome &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token boolean&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br&gt; extraGroups &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;token string&quot;&gt;&quot;users&quot;&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br&gt; &lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br&gt;&lt;br&gt; users&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;groups&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;caddy&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;gid &lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt; config&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;ids&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;uids&lt;span class=&quot;token punctuation&quot;&gt;.&lt;/span&gt;caddy&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
</content>
</entry>
<entry>
<title>GitHub actions with Docker and Nix</title>
<link href="https://www.lafuente.me/posts/github-actions-docker-nix"/>
<updated>2020-06-11T00:00:00-00:00</updated>
<id>https://www.lafuente.me/posts/github-actions-docker-nix</id>
<category term="automation"/><category term="clojure"/><category term="docker"/><category term="github"/><category term="nix"/>
<content type="html">&lt;p&gt;I created my first GitHub action: &lt;a href=&quot;https://github.com/jlesquembre/clojars-publish-action&quot;&gt;clojars publish action&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;To see an example in action, you can go to &lt;a href=&quot;https://github.com/jlesquembre/dummy-clj&quot;&gt;jlesquembre/dummy-clj&lt;/a&gt; and take a look to the actions tab.&lt;/p&gt; &lt;p&gt;GitHub actions can run in Docker containers, so I created a Docker image. At first, I went to Docker hub and looked for the clojure images, but I realized that I also needed to install maven. There is also a maven image, but since I need maven &lt;strong&gt;and&lt;/strong&gt; clojure on the container, the only option was to create my own image based on the official ones and install the other dependency manually.&lt;/p&gt; &lt;p&gt;Then, I remembered about an interesting project I hear about, &lt;a href=&quot;https://nixery.dev/&quot;&gt;Nixery&lt;/a&gt;. With it, you can create Docker images based on &lt;a href=&quot;https://nixos.org/&quot;&gt;NixOS&lt;/a&gt;, and it makes really easy to install dependecies. In my case, I just needed this:&lt;/p&gt; &lt;pre class=&quot;language-dockerfile&quot;&gt;&lt;code class=&quot;language-dockerfile&quot;&gt;&lt;span class=&quot;token keyword&quot;&gt;FROM&lt;/span&gt; nixery.dev/shell/maven/clojure&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;Done, you alredy have a container with some basic linux utilities, maven and clojure. If you need to install something else, just add &lt;code&gt;/other-dep&lt;/code&gt;.&lt;/p&gt; &lt;p&gt;Since I&#x27;m already a &lt;a href=&quot;https://nixos.org/&quot;&gt;NixOS&lt;/a&gt; user, it is a really good solution for me. It gives me an easy way to install dependecies, on the linux distribution I know the best.&lt;/p&gt;
</content>
</entry>
<entry>
<title>Eleventy migration</title>
<link href="https://www.lafuente.me/posts/eleventy-migration"/>
<updated>2020-06-07T00:00:00-00:00</updated>
<id>https://www.lafuente.me/posts/eleventy-migration</id>
<category term="11ty"/><category term="lit-html"/>
<content type="html">&lt;p&gt;After 6 years from my &lt;a href=&quot;/posts/gnupg-notes&quot;&gt;last post entry&lt;/a&gt;, I&#x27;m migrating my personal blog to &lt;a href=&quot;https://www.11ty.dev/&quot;&gt;Eleventy&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;I heard good things about it and I wanted to give it a try. So far I&#x27;m liking it a lot, the best part about &lt;a href=&quot;https://www.11ty.dev/&quot;&gt;Eleventy&lt;/a&gt; is its flexibility. As an example, I started writing my templates in &lt;a href=&quot;https://mozilla.github.io/nunjucks/&quot;&gt;Nunjucks&lt;/a&gt;, but since I didn&#x27;t like the syntax too much, I decided to write the templates just with &lt;a href=&quot;https://www.11ty.dev/docs/languages/javascript/&quot;&gt;JavaScript&lt;/a&gt;. It was an improvement, but I was missing some of the functionality provided by &lt;a href=&quot;https://lit-html.polymer-project.org/&quot;&gt;lit-html&lt;/a&gt;. I found a project to render &lt;a href=&quot;https://lit-html.polymer-project.org/&quot;&gt;lit-html&lt;/a&gt; templates on the server, &lt;a href=&quot;https://github.com/popeindustries/lit-html-server&quot;&gt;lit-html-server&lt;/a&gt;, and it was incredibly easy to plug it into &lt;a href=&quot;https://www.11ty.dev/&quot;&gt;Eleventy&lt;/a&gt; and start to use &lt;a href=&quot;https://lit-html.polymer-project.org/&quot;&gt;lit-html&lt;/a&gt; templates on my static site.&lt;/p&gt; &lt;p&gt;Now I write the posts in Markdown, which are rendered with &lt;a href=&quot;https://github.com/markdown-it/markdown-it&quot;&gt;markdown-it&lt;/a&gt;, and the result is passed to the templates to render the final html with &lt;a href=&quot;https://github.com/popeindustries/lit-html-server&quot;&gt;lit-html-server&lt;/a&gt;&lt;/p&gt; &lt;p&gt;I&#x27;ll also try to write regularly. I liked the idea from &lt;a href=&quot;https://lambdaisland.com/blog/2019-11-25-advent-of-parens&quot;&gt;Lambda Island: Advent of Parens&lt;/a&gt;, where the author challenged himself to write a blog post for every day of December until the 24th. While I&#x27;m not writing a new post every day, I like the idea of writing smaller posts, but more often. Let&#x27;s see how it goes.&lt;/p&gt;
</content>
</entry>
<entry>
<title>GnuPG Notes</title>
<link href="https://www.lafuente.me/posts/gnupg-notes"/>
<updated>2014-04-24T00:00:00-00:00</updated>
<id>https://www.lafuente.me/posts/gnupg-notes</id>
<category term="gnupg"/>
<content type="html">&lt;h2 id=&quot;create-new-key&quot;&gt;Create new key &lt;a class=&quot;direct-link&quot; href=&quot;#create-new-key&quot;&gt;#&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;Create or edit the file &lt;code&gt;~/.gnupg/gpg.conf&lt;/code&gt; and add the following lines to use the cryptographically stronger SHA512 hashing algorithm for signatures in preference to SHA1 algorithm.&lt;/p&gt; &lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;personal-digest-preferences SHA512&lt;br&gt;cert-digest-algo SHA512&lt;br&gt;default-preference-list SHA512 SHA384 SHA256 SHA224 AES256 AES192 AES CAST5 ZLIB BZIP2 ZIP Uncompressed&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;Now we can generate the keys:&lt;/p&gt; &lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;gpg --gen-key&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;The system will prompt us to generate some entropy, we can just run this in other terminal. Any expensive operation over the file system, like &lt;code&gt;find&lt;/code&gt; would we also ok.&lt;/p&gt; &lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token function&quot;&gt;ls&lt;/span&gt; -R ~&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;By default we have one master key (for signing) and one subkey (for encryption)&lt;/p&gt; &lt;h2 id=&quot;list-keys&quot;&gt;List keys &lt;a class=&quot;direct-link&quot; href=&quot;#list-keys&quot;&gt;#&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;We can see our public keys with this command:&lt;/p&gt; &lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;gpg --list-keys&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;And our secret keys with this command:&lt;/p&gt; &lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;gpg --list-secret-keys&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;To see more information about the keys, we can use this command:&lt;/p&gt; &lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;gpg --edit-key KEYID_or_EMAIL&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;The output is something like this:&lt;/p&gt; &lt;pre&gt;&lt;code&gt;Secret key is available. pub 4096R/AB58430D created: 2014-04-14 expires: never usage: SC trust: ultimate validity: ultimate sub 4096R/D5293C21 created: 2014-04-14 expires: never usage: E [ultimate] (1). John Doe &amp;lt;jonh@gmail.com&amp;gt; &lt;/code&gt;&lt;/pre&gt; &lt;p&gt;Meaning of the usage field abbreviation:&lt;/p&gt; &lt;table&gt; &lt;thead&gt; &lt;tr&gt; &lt;th&gt;Constant&lt;/th&gt; &lt;th style=&quot;text-align:center&quot;&gt;Character&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;PUBKEY_USAGE_SIG&lt;/td&gt; &lt;td style=&quot;text-align:center&quot;&gt;S&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;PUBKEY_USAGE_CERT&lt;/td&gt; &lt;td style=&quot;text-align:center&quot;&gt;C&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;PUBKEY_USAGE_ENC&lt;/td&gt; &lt;td style=&quot;text-align:center&quot;&gt;E&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;PUBKEY_USAGE_AUTH&lt;/td&gt; &lt;td style=&quot;text-align:center&quot;&gt;A&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;p&gt;Thus, for example, usage: SCA means that the sub-key can be used for signing, for creating a certificate and authentication purposes.&lt;/p&gt; &lt;p&gt;The primary user id is indicated by a dot, and selected keys or user ids are indicated by an asterisk&lt;/p&gt; &lt;h2 id=&quot;user-id-management&quot;&gt;User id management &lt;a class=&quot;direct-link&quot; href=&quot;#user-id-management&quot;&gt;#&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;Use the &lt;code&gt;gpg ‐‐edit-key&lt;/code&gt; command to launch the &lt;code&gt;gpg&amp;gt;&lt;/code&gt; prompt.&lt;/p&gt; &lt;p&gt;Select a uid:&lt;/p&gt; &lt;pre&gt;&lt;code&gt;gpg&amp;gt; uid n &lt;/code&gt;&lt;/pre&gt; &lt;p&gt;&lt;code&gt;n&lt;/code&gt; is the uid number. Use * to select all and 0 to deselect all.&lt;/p&gt; &lt;p&gt;Add a uid:&lt;/p&gt; &lt;pre&gt;&lt;code&gt;gpg&amp;gt; adduid &lt;/code&gt;&lt;/pre&gt; &lt;p&gt;Make uid primary, before you need to select a uid:&lt;/p&gt; &lt;pre&gt;&lt;code&gt;gpg&amp;gt; primary &lt;/code&gt;&lt;/pre&gt; &lt;h2 id=&quot;create-subkey&quot;&gt;Create subkey &lt;a class=&quot;direct-link&quot; href=&quot;#create-subkey&quot;&gt;#&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;For extra security, it might be appropriate to physically remove the master private key from your computer, and instead use a second generated subkey for signing files. You can sign and encrypt files as normal with your signing subkey and encryption subkey. If those keys ever get compromised, you can simply revoke them and generate new ones with your uncompromised master key.&lt;/p&gt; &lt;pre&gt;&lt;code&gt;gpg --edit-key KEYID_or_EMAIL gpg&amp;gt; addkey . . . gpg&amp;gt; save &lt;/code&gt;&lt;/pre&gt; &lt;h2 id=&quot;create-subkey-for-ssh-authentication&quot;&gt;Create subkey for SSH authentication &lt;a class=&quot;direct-link&quot; href=&quot;#create-subkey-for-ssh-authentication&quot;&gt;#&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;You need to create a subkey for authentication. To do this, you need to run gpg in expert mode:&lt;/p&gt; &lt;pre&gt;&lt;code&gt;gpg --expert --edit-key KEYID_or_EMAIL gpg&amp;gt; addkey # Select (11) ECC (set your own capabilities) # Select (1) Curve 25519 # Select successively (S), (E), and (A) to remove the signing and encryption capabilities and enable the authentication capability. gpg&amp;gt; save &lt;/code&gt;&lt;/pre&gt; &lt;p&gt;To export your public ssh key:&lt;/p&gt; &lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;gpg --export-ssh-key KEYID_or_EMAIL&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;To make gnupg use your authentication key for ssh:&lt;/p&gt; &lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;gpg --with-keygrip --list-public-keys KEYID_or_EMAIL&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;And add the keygrip for the authentication key to &lt;code&gt;~/.gnupg/sshcontrol&lt;/code&gt;&lt;/p&gt; &lt;h2 id=&quot;export-keys&quot;&gt;Export keys &lt;a class=&quot;direct-link&quot; href=&quot;#export-keys&quot;&gt;#&lt;/a&gt;&lt;/h2&gt; &lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;gpg --armor --export KEYID_or_EMAIL &lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; keyname.public.asc&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;&lt;code&gt;--armor&lt;/code&gt; exports the key in ascii format. Is also posible use &lt;code&gt;--export-secret-key&lt;/code&gt; or &lt;code&gt;--export-secret-subkeys&lt;/code&gt;&lt;/p&gt; &lt;p&gt;&lt;code&gt;--export&lt;/code&gt; exports your whole public key. It probably doesn&#x27;t make sense to only export a public subkey (public keys are supposed to be public) and various important bits of information are tied to the main key in any case. Your user id, for example, is stored on the main key.&lt;/p&gt; &lt;h2 id=&quot;import-subkeys&quot;&gt;Import subkeys &lt;a class=&quot;direct-link&quot; href=&quot;#import-subkeys&quot;&gt;#&lt;/a&gt;&lt;/h2&gt; &lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;gpg --import subkey.asc&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;It is not possible to delete only the secret master key. If you want to delete only the master secret key, you need to follow this steps:&lt;/p&gt; &lt;ul&gt; &lt;li&gt; &lt;p&gt;Export secret subkeys&lt;/p&gt; &lt;/li&gt; &lt;li&gt; &lt;p&gt;Delete secret key&lt;/p&gt; &lt;/li&gt; &lt;/ul&gt; &lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;gpg --delete-secret-key KEYID_or_EMAIL&lt;/code&gt;&lt;/pre&gt; &lt;ul&gt; &lt;li&gt;Import secret subkeys&lt;/li&gt; &lt;/ul&gt; &lt;p&gt;You can verify it worked by running:&lt;/p&gt; &lt;pre&gt;&lt;code&gt;gpg --list-secret-keys /home/john/.gnupg/secring.gpg ----------------------------- sec# 4096R/AB58430D 2014-04-14 uid John Doe &amp;lt;jonh@gmail.com&amp;gt; ssb 4096R/D5293C21 2014-04-14 &lt;/code&gt;&lt;/pre&gt; &lt;p&gt;The pound sign &lt;code&gt;#&lt;/code&gt; means the signing subkey is not in the keypair located in the keyring.&lt;/p&gt; &lt;h2 id=&quot;encrypting-a-file&quot;&gt;Encrypting a file &lt;a class=&quot;direct-link&quot; href=&quot;#encrypting-a-file&quot;&gt;#&lt;/a&gt;&lt;/h2&gt; &lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;gpg --recipient MY_KEY --recipient OTHER_KEY --encrypt message.txt&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;The encrypted message is written to &lt;code&gt;message.txt.gpg&lt;/code&gt;&lt;/p&gt; &lt;p&gt;I wanted to make sure I could read the message too, for this reason I have two recipents.&lt;/p&gt; &lt;h3 id=&quot;references&quot;&gt;References &lt;a class=&quot;direct-link&quot; href=&quot;#references&quot;&gt;#&lt;/a&gt;&lt;/h3&gt; &lt;ul&gt; &lt;li&gt;&lt;a href=&quot;https://sanctum.geek.nz/arabesque/series/gnu-linux-crypto/&quot;&gt;Series: GNU/Linux Crypto « Arabesque&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href=&quot;https://alexcabal.com/creating-the-perfect-gpg-keypair/&quot;&gt;Creating the perfect GPG keypair&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href=&quot;http://unix.stackexchange.com/questions/31996/how-are-the-gpg-usage-flags-defined-in-the-key-details-listing&quot;&gt;How are the GPG usage flags defined in the key details listing? - Unix &amp;amp; Linux Stack Exchange&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;
</content>
</entry>
<entry>
<title>Arch Linux, quick installation guide</title>
<link href="https://www.lafuente.me/posts/arch-linux-quick-installation-guide"/>
<updated>2014-03-28T00:00:00-00:00</updated>
<id>https://www.lafuente.me/posts/arch-linux-quick-installation-guide</id>
<category term="archlinux"/>
<content type="html">&lt;h2 id=&quot;ipxe&quot;&gt;iPXE &lt;a class=&quot;direct-link&quot; href=&quot;#ipxe&quot;&gt;#&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;Install from a USB using &lt;a href=&quot;http://ipxe.org/&quot;&gt;iPXE&lt;/a&gt;.&lt;/p&gt; &lt;p&gt;Download image from &lt;a href=&quot;http://boot.ipxe.org/ipxe.iso&quot;&gt;http://boot.ipxe.org/ipxe.iso&lt;/a&gt; and copy to an USB stick.&lt;/p&gt; &lt;p&gt;Find your USB&lt;/p&gt; &lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;lsblk&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;Copy the image to the USB&lt;/p&gt; &lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token function&quot;&gt;sudo&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;dd&lt;/span&gt; &lt;span class=&quot;token assign-left variable&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;ipxe.iso &lt;span class=&quot;token assign-left variable&quot;&gt;of&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;/dev/sdX&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;Now boot with the USB&lt;/p&gt; &lt;h2 id=&quot;arch-linux-netboot&quot;&gt;Arch Linux Netboot &lt;a class=&quot;direct-link&quot; href=&quot;#arch-linux-netboot&quot;&gt;#&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;Obtain an IP address&lt;/p&gt; &lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;dhcp&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;Start Arch Linux boot, original link is &lt;a href=&quot;http://releng.archlinux.org/pxeboot/arch.ipxe&quot;&gt;http://releng.archlinux.org/pxeboot/arch.ipxe&lt;/a&gt;&lt;/p&gt; &lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;chain http://bit.do/archipxe&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;Get &lt;a href=&quot;https://github.com/helmuthdu/aui&quot;&gt;Arch Linux Ultimate Install Script&lt;/a&gt;&lt;/p&gt; &lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token function&quot;&gt;wget&lt;/span&gt; http://bit.do/archis&lt;br&gt;&lt;span class=&quot;token function&quot;&gt;tar&lt;/span&gt; xzf archis&lt;br&gt;&lt;span class=&quot;token builtin class-name&quot;&gt;cd&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt;dir&lt;span class=&quot;token operator&quot;&gt;&gt;&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; ./ais&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;Reboot and finish the installation. If network doesn&#x27;t work do&lt;/p&gt; &lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;systemctl start dhcpcd&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;Helper to finish the installation, original at &lt;a href=&quot;https://raw.githubusercontent.com/jlesquembre/arch_install_script/master/ais.sh&quot;&gt;https://raw.githubusercontent.com/jlesquembre/arch_install_script/master/ais.sh&lt;/a&gt;&lt;/p&gt; &lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token function&quot;&gt;wget&lt;/span&gt; http://bit.do/jlais&lt;/code&gt;&lt;/pre&gt;
</content>
</entry>
<entry>
<title>Using the KDE Wallet to store ssh keys with passphrases</title>
<link href="https://www.lafuente.me/posts/using-the-kde-wallet-to-store-ssh-keys-with-passphrases"/>
<updated>2012-03-09T00:00:00-00:00</updated>
<id>https://www.lafuente.me/posts/using-the-kde-wallet-to-store-ssh-keys-with-passphrases</id>
<category term="kde"/><category term="linux"/><category term="openssh"/>
<content type="html">&lt;p&gt;I have read an article about SSH passphrases (&lt;a href=&quot;http://help.github.com/ssh-key-passphrases/&quot;&gt;github:help&lt;/a&gt;), but they only explain how to use ssh-agent with msysgit and Mac OSX, no word about Linux.&lt;/p&gt; &lt;p&gt;This guide is about how to use KDE Wallet with ssh-agent. This way, we can use SSH keys with passphrases, but we don&#x27;t need to enter a passphrase every time we use the key, KDE Wallet does the job. I assume you are using KDE.&lt;/p&gt; &lt;p&gt;In 3 easy steps:&lt;/p&gt; &lt;h3 id=&quot;1.-install-ksshaskpass&quot;&gt;1. Install ksshaskpass &lt;a class=&quot;direct-link&quot; href=&quot;#1.-install-ksshaskpass&quot;&gt;#&lt;/a&gt;&lt;/h3&gt; &lt;p&gt;Use your favorite package manager.&lt;/p&gt; &lt;h3 id=&quot;2.-create-script-file&quot;&gt;2. Create script file &lt;a class=&quot;direct-link&quot; href=&quot;#2.-create-script-file&quot;&gt;#&lt;/a&gt;&lt;/h3&gt; &lt;p&gt;Create the file&lt;/p&gt; &lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;~/.kde/Autostart/ssh-add.sh&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;On some distributions &lt;code&gt;~/.kde4/Autostart/ssh-add.sh&lt;/code&gt;&lt;/p&gt; &lt;p&gt;And add this content&lt;/p&gt; &lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token shebang important&quot;&gt;#!/bin/sh&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;token builtin class-name&quot;&gt;export&lt;/span&gt; &lt;span class=&quot;token assign-left variable&quot;&gt;SSH_ASKPASS&lt;/span&gt;&lt;span class=&quot;token operator&quot;&gt;=&lt;/span&gt;/usr/bin/ksshaskpass&lt;br&gt;ssh-add &lt;span class=&quot;token operator&quot;&gt;&amp;lt;&lt;/span&gt; /dev/null&lt;/code&gt;&lt;/pre&gt; &lt;h3 id=&quot;3.-make-it-executable&quot;&gt;3. Make it executable &lt;a class=&quot;direct-link&quot; href=&quot;#3.-make-it-executable&quot;&gt;#&lt;/a&gt;&lt;/h3&gt; &lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token function&quot;&gt;chmod&lt;/span&gt; +x ~/.kde/Autostart/ssh-add.sh&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;And run the script (or restart the session)&lt;/p&gt; &lt;h3 id=&quot;extra&quot;&gt;Extra &lt;a class=&quot;direct-link&quot; href=&quot;#extra&quot;&gt;#&lt;/a&gt;&lt;/h3&gt; &lt;p&gt;For security reasons, is a good idea stop ssh-agent when you finish your session, create the file&lt;/p&gt; &lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;~/.kde/shutdown/ssh-agent.sh&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;With this content&lt;/p&gt; &lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token shebang important&quot;&gt;#!/bin/sh&lt;/span&gt;&lt;br&gt;ssh-agent -k&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;This file should be executable&lt;/p&gt; &lt;p&gt;A good page for more info about SSH: &lt;a href=&quot;https://wiki.archlinux.org/index.php/Secure_Shell&quot;&gt;Secure Shell (Arch Linux)&lt;/a&gt;&lt;/p&gt;
</content>
</entry>
<entry>
<title>Autofs configuration</title>
<link href="https://www.lafuente.me/posts/autofs-configuration"/>
<updated>2011-03-11T00:00:00-00:00</updated>
<id>https://www.lafuente.me/posts/autofs-configuration</id>
<category term="autofs"/><category term="linux"/>
<content type="html">&lt;p&gt;Autofs uses &lt;code&gt;/etc/autofs/auto.master&lt;/code&gt; as its default primary configuration file. We can define two kind of maps in this file, direct and indirect. An example:&lt;/p&gt; &lt;pre&gt;&lt;code&gt;# mount point config file options /- /etc/autofs/auto.direct --ghost /media/cifs /etc/autofs/auto.cifs --timeout=60 --ghost /media/sshfs /etc/autofs/auto.sshfs --timeout=60 --ghost +auto.master &lt;/code&gt;&lt;/pre&gt; &lt;p&gt;First map is a direct map, the other two are indirect. Entries in a direct map contain an absolute path, instead of the relative path names used in indirect maps. The &lt;code&gt;--ghost&lt;/code&gt; option tells the automounter to create empty directories of all the mount points. The &lt;code&gt;/media&lt;/code&gt; folder should be empty. Let&#x27;s see the other configuration files, in this example we are going to mount a remote file system using cifs and ssh.&lt;/p&gt; &lt;p&gt;&lt;code&gt;/etc/autofs/auto.direct&lt;/code&gt;&lt;/p&gt; &lt;pre&gt;&lt;code&gt;# directory mount options device to mount /home/ian/music -fstype=cifs,ro,soft,user=guest ://192.168.1.10/music /home/deb/music -fstype=cifs,ro,soft,user=guest ://192.168.1.10/music &lt;/code&gt;&lt;/pre&gt; &lt;p&gt;Folders &lt;code&gt;/home/ian/music&lt;/code&gt; and &lt;code&gt;/home/deb/music&lt;/code&gt; should be empty or not exist. In both we can access to te remote folder /music in computer 192.168.1.10&lt;/p&gt; &lt;p&gt;&lt;code&gt;/etc/autofs/auto.cifs&lt;/code&gt;&lt;/p&gt; &lt;pre&gt;&lt;code&gt;# directory mount options device to mount ian -fstype=cifs,ro,soft,user=ian ://192.168.1.10/export/home/ian deb -fstype=cifs,ro,soft,user=deb ://192.168.1.10/export/home/deb &lt;/code&gt;&lt;/pre&gt; &lt;p&gt;Folders &lt;code&gt;/media/cifs/ian&lt;/code&gt; and &lt;code&gt;/media/cifs/deb&lt;/code&gt; will be created.&lt;/p&gt; &lt;p&gt;&lt;code&gt;/etc/autofs/auto.sshfs&lt;/code&gt;&lt;/p&gt; &lt;pre&gt;&lt;code&gt;# directory mount options device to mount ian_ssh -fstype=fuse,rw,allow_other,IdentityFile=/path/to/ssh_key :sshfs\#user@192.168.1.10\:/mnt/folder/ &lt;/code&gt;&lt;/pre&gt; &lt;p&gt;Folder &lt;code&gt;/media/sshfs/ain_ssh&lt;/code&gt; will be created.&lt;/p&gt;
</content>
</entry>
<entry>
<title>Using public keys with openSSH</title>
<link href="https://www.lafuente.me/posts/using-public-keys-with-openssh"/>
<updated>2011-01-27T00:00:00-00:00</updated>
<id>https://www.lafuente.me/posts/using-public-keys-with-openssh</id>
<category term="linux"/><category term="openssh"/>
<content type="html">&lt;p&gt;&lt;img src=&quot;/images/sshconnection.png&quot; alt=&quot;ssh connection diagram&quot;&gt;&lt;/p&gt; &lt;h3 id=&quot;generate-the-key&quot;&gt;Generate the key &lt;a class=&quot;direct-link&quot; href=&quot;#generate-the-key&quot;&gt;#&lt;/a&gt;&lt;/h3&gt; &lt;p&gt;We need to create a public key, we do it in computer A:&lt;/p&gt; &lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;ssh-keygen -t rsa -b &lt;span class=&quot;token number&quot;&gt;2048&lt;/span&gt; -f /home/user_name/.ssh/key-name&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;Press always intro when asked to generate a key without passphrase. This is less secure, but it can be really useful. Now we have in our .ssh folder the keys (key-name and key-name.pub)&lt;/p&gt; &lt;h3 id=&quot;copy-public-key&quot;&gt;Copy public key &lt;a class=&quot;direct-link&quot; href=&quot;#copy-public-key&quot;&gt;#&lt;/a&gt;&lt;/h3&gt; &lt;p&gt;Copy the public key to the remote host you wish to access (in our example from computer A to B) and add it to the file&lt;/p&gt; &lt;pre&gt;&lt;code&gt;~/.ssh/authorized_keys &lt;/code&gt;&lt;/pre&gt; &lt;p&gt;If that file does not exist then you should create it. Or you can use ssh-copy-id to log into a remote machine and append the indicated identity file to that machine&#x27;s ~/.ssh/authorized_keys file.&lt;/p&gt; &lt;pre&gt;&lt;code&gt;ssh-copy-id [-i [identity_file]] [user@]machine &lt;/code&gt;&lt;/pre&gt; &lt;h3 id=&quot;test-it&quot;&gt;Test it &lt;a class=&quot;direct-link&quot; href=&quot;#test-it&quot;&gt;#&lt;/a&gt;&lt;/h3&gt; &lt;p&gt;In computer A run this command:&lt;/p&gt; &lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token function&quot;&gt;ssh&lt;/span&gt; -i key user@computerB_IP&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;If every thing is fine, you should be able to connect to computer B with this command.&lt;/p&gt; &lt;h3 id=&quot;laziness-is-a-virtue%2C-using-ssh-config&quot;&gt;Laziness is a virtue, using ssh config &lt;a class=&quot;direct-link&quot; href=&quot;#laziness-is-a-virtue%2C-using-ssh-config&quot;&gt;#&lt;/a&gt;&lt;/h3&gt; &lt;p&gt;You can create alias for your ssh connections, this way, you don&#x27;t need to remember usernames, IPs, etc...&lt;/p&gt; &lt;p&gt;First, create this file:&lt;/p&gt; &lt;pre&gt;&lt;code&gt;~/.ssh/config &lt;/code&gt;&lt;/pre&gt; &lt;p&gt;with this content:&lt;/p&gt; &lt;pre&gt;&lt;code&gt;Host alias HostName computerB_IP User username IdentityFile ~/.ssh/path/to/key &lt;/code&gt;&lt;/pre&gt; &lt;p&gt;Now it is possible connent with this command:&lt;/p&gt; &lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token function&quot;&gt;ssh&lt;/span&gt; &lt;span class=&quot;token builtin class-name&quot;&gt;alias&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;Great, isn&#x27;t it? For a complete connect list for the ssh config file, type&lt;/p&gt; &lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token function&quot;&gt;man&lt;/span&gt; ssh_config&lt;/code&gt;&lt;/pre&gt;
</content>
</entry>
<entry>
<title>File and directory permissions</title>
<link href="https://www.lafuente.me/posts/file-and-directory-permissions"/>
<updated>2011-01-24T00:00:00-00:00</updated>
<id>https://www.lafuente.me/posts/file-and-directory-permissions</id>
<category term="linux"/>
<content type="html">&lt;p&gt;The best way to understand the Linux permissions, is with an example. If we run the command &lt;code&gt;ls -l&lt;/code&gt; we get an output like this:&lt;/p&gt; &lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;1 2 3 4 5 6 7 8&lt;br&gt;- rw-r----- 1 user users 8 ene 24 11:01 f.txt&lt;br&gt;d rwxr-xr-x 2 root root 4096 ene 24 12:14 dir&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;which maps to&lt;/p&gt; &lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;1 2 3 4 5 6 7 8&lt;br&gt;d uuugggooo links owner group size date name&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;Numbers from 1 to 8 are not really in the output, but are here to clarify every field.&lt;/p&gt; &lt;ol&gt; &lt;li&gt; &lt;p&gt;First character specifies the type of the file. In the example above the hyphen (&lt;code&gt;-&lt;/code&gt;) in the first character indicates that this is a normal file, and the &lt;code&gt;d&lt;/code&gt; indicates that this other file is a directory. &lt;a href=&quot;http://en.wikipedia.org/wiki/Unix_file_types&quot;&gt;List with all file types&lt;/a&gt;&lt;/p&gt; &lt;/li&gt; &lt;li&gt; &lt;p&gt;Next 9 characters specifies the files permission. Each 3 characters refers to the read, write and execute permissions for user, group and others. In this example, &lt;code&gt;rw-r-----&lt;/code&gt; indicates read-write permission for user, read permission for group, and no permission for others.&lt;/p&gt; &lt;/li&gt; &lt;li&gt; &lt;p&gt;Number of &lt;a href=&quot;http://en.wikipedia.org/wiki/Hard_link&quot;&gt;links&lt;/a&gt;, in this case is 1 for the file &lt;code&gt;f.txt&lt;/code&gt; and 2 for the directory &lt;code&gt;dir&lt;/code&gt;.&lt;/p&gt; &lt;/li&gt; &lt;li&gt; &lt;p&gt;Owner, in this example, user for the file, and root for the directory.&lt;/p&gt; &lt;/li&gt; &lt;li&gt; &lt;p&gt;Group, in this example, users for the file, and root for the directory.&lt;/p&gt; &lt;/li&gt; &lt;li&gt; &lt;p&gt;Size of the file.&lt;/p&gt; &lt;/li&gt; &lt;li&gt; &lt;p&gt;Last modified time.&lt;/p&gt; &lt;/li&gt; &lt;li&gt; &lt;p&gt;File name.&lt;/p&gt; &lt;/li&gt; &lt;/ol&gt; &lt;p&gt;Difference in access permission between files and folders are:&lt;/p&gt; &lt;table&gt; &lt;thead&gt; &lt;tr&gt; &lt;th&gt;&lt;/th&gt; &lt;th&gt;&lt;strong&gt;File&lt;/strong&gt;&lt;/th&gt; &lt;th&gt;&lt;strong&gt;Folder&lt;/strong&gt;&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;strong&gt;Read&lt;/strong&gt;&lt;/td&gt; &lt;td&gt;File contents can be read&lt;/td&gt; &lt;td&gt;Directory listing can be obtained&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;strong&gt;Write&lt;/strong&gt;&lt;/td&gt; &lt;td&gt;File contents can be changed&lt;/td&gt; &lt;td&gt;Directory content can be changed&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;strong&gt;Execute&lt;/strong&gt;&lt;/td&gt; &lt;td&gt;File can be executed&lt;/td&gt; &lt;td&gt;Directory can be accessed&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;p&gt;Remember, give execute permission to a folder if you want to access it.&lt;/p&gt; &lt;p&gt;Instead of use the values &lt;code&gt;r&lt;/code&gt;, &lt;code&gt;w&lt;/code&gt; and &lt;code&gt;x&lt;/code&gt;, you can use numeric values, where&lt;/p&gt; &lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;r = 4&lt;br&gt;w = 2&lt;br&gt;x = 1&lt;br&gt;- = 0&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;It is possible combine this values, a table with all the possibilities:&lt;/p&gt; &lt;table&gt; &lt;thead&gt; &lt;tr&gt; &lt;th&gt;Value&lt;/th&gt; &lt;th&gt;Text equivalent&lt;/th&gt; &lt;th&gt;Meaning&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;0&lt;/td&gt; &lt;td&gt;---&lt;/td&gt; &lt;td&gt;All types of access are denied&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;1&lt;/td&gt; &lt;td&gt;--x&lt;/td&gt; &lt;td&gt;Execute access is allowed&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;2&lt;/td&gt; &lt;td&gt;-w-&lt;/td&gt; &lt;td&gt;Write access is allowed&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;3&lt;/td&gt; &lt;td&gt;-wx&lt;/td&gt; &lt;td&gt;Write and execute access are allowed&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;4&lt;/td&gt; &lt;td&gt;r--&lt;/td&gt; &lt;td&gt;Read access is allowed&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;5&lt;/td&gt; &lt;td&gt;r-x&lt;/td&gt; &lt;td&gt;Read and execute access are allowed&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;6&lt;/td&gt; &lt;td&gt;rw-&lt;/td&gt; &lt;td&gt;Read and write access are allowed&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;7&lt;/td&gt; &lt;td&gt;rwx&lt;/td&gt; &lt;td&gt;Everything is allowed&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;p&gt;To change the permissions you can use the command &lt;code&gt;chmod&lt;/code&gt;, which has this syntax:&lt;/p&gt; &lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;chmod [options] MODE FILE&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;Let&#x27;s see some examples, to give read and write access to everyone, you can use this two equivalent commands:&lt;/p&gt; &lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;chmod a=rw file.txt&lt;br&gt;chmod 666 file.txt&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;To give read and write access to user and group, but no access to others, you can use this two equivalent commands:&lt;/p&gt; &lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;chmod u=rw,g=rw,o= file.txt&lt;br&gt;chmod 660 file.txt&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;If you want to change the access permissions of a folder recursively never use the -R option. Chmod doesn&#x27;t differentiate between folders and files, and this is really important, because execution access has different meanings for files and folders. Instead use this:&lt;/p&gt; &lt;p&gt;For directories:&lt;/p&gt; &lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token function&quot;&gt;find&lt;/span&gt; &lt;span class=&quot;token builtin class-name&quot;&gt;.&lt;/span&gt; -type d -exec &lt;span class=&quot;token function&quot;&gt;chmod&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;755&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;For files:&lt;/p&gt; &lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token function&quot;&gt;find&lt;/span&gt; &lt;span class=&quot;token builtin class-name&quot;&gt;.&lt;/span&gt; -type f -exec &lt;span class=&quot;token function&quot;&gt;chmod&lt;/span&gt; &lt;span class=&quot;token number&quot;&gt;644&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;token punctuation&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;token punctuation&quot;&gt;;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;To finish, if you want to change the file owner, you can use the command chown, with this syntax:&lt;/p&gt; &lt;pre class=&quot;language-text&quot;&gt;&lt;code class=&quot;language-text&quot;&gt;chown [options] OWNER[:GROUP] file.txt&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;For example:&lt;/p&gt; &lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token function&quot;&gt;chown&lt;/span&gt; user1 file.txt&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;To change the owner recursively, use the option -R If you just want to change the group, use the command chgrp.&lt;/p&gt;
</content>
</entry>
<entry>
<title>Load a kernel module</title>
<link href="https://www.lafuente.me/posts/load-a-kernel-module"/>
<updated>2011-01-22T00:00:00-00:00</updated>
<id>https://www.lafuente.me/posts/load-a-kernel-module</id>
<category term="kernel"/><category term="linux"/>
<content type="html">&lt;p&gt;In Linux, to load a kernel module (for example, fuse) run:&lt;/p&gt; &lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;modprobe fuse&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;You can verify that the module is loaded using the following command:&lt;/p&gt; &lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token function&quot;&gt;dmesg&lt;/span&gt; &lt;span class=&quot;token operator&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;token function&quot;&gt;grep&lt;/span&gt; -i fuse&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;If you want it to to load a module, add that module to &lt;code&gt;/etc/modules&lt;/code&gt;, an example file:&lt;/p&gt; &lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token comment&quot;&gt;# /etc/modules: kernel modules to load at boot time.&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;token comment&quot;&gt;#&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;token comment&quot;&gt;# This file contains the names of kernel modules that should be loaded&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;token comment&quot;&gt;# at boot time, one per line. Lines beginning with &quot;#&quot; are ignored.&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;token comment&quot;&gt;# Parameters can be specified after the module name.&lt;/span&gt;&lt;br&gt;&lt;br&gt;fuse&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;And if you want to cofigure some options for that kernel module do it in the folder &lt;code&gt;/etc/modules&lt;/code&gt;, in our example put the options in the file &lt;code&gt;/etc/modules/fuse&lt;/code&gt;&lt;/p&gt;
</content>
</entry>
<entry>
<title>OpenSSH, remote host identification has changed</title>
<link href="https://www.lafuente.me/posts/remote-host-authentication-changed"/>
<updated>2011-01-19T00:00:00-00:00</updated>
<id>https://www.lafuente.me/posts/remote-host-authentication-changed</id>
<category term="linux"/><category term="openssh"/>
<content type="html">&lt;p&gt;Sometimes when I run the ssh command I get this error:&lt;/p&gt; &lt;pre&gt;&lt;code&gt;@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY! Someone could be eavesdropping on you right now (man-in-the-middle attack)! It is also possible that the RSA host key has just been changed. The fingerprint for the RSA key sent by the remote host is xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx. Please contact your system administrator. Add correct host key in /home/user/.ssh/known_hosts to get rid of this message. Offending key in /home/user/.ssh/known_hosts:7 RSA host key for 192.168.1.5 has changed and you have requested strict checking. Host key verification failed. &lt;/code&gt;&lt;/pre&gt; &lt;p&gt;This usually happens when I change any machine in my network. The best way to solve this problem is removing all keys belonging to hostname from &lt;code&gt;known_hosts&lt;/code&gt; file. In my case, the remote host is &lt;code&gt;192.168.1.5&lt;/code&gt;, so I run the command:&lt;/p&gt; &lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;ssh-keygen -R &lt;span class=&quot;token number&quot;&gt;192.168&lt;/span&gt;.1.5&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;And now I can access again to the remote host.&lt;/p&gt; &lt;p&gt;An alternative is to set &lt;code&gt;StrictHostKeyChecking&lt;/code&gt; to &lt;code&gt;no&lt;/code&gt; in your ssh_config. For a better description, take a look to the end of this article: &lt;a href=&quot;http://blogs.atlassian.com/2011/05/advanced_ssh_for_developers/&quot;&gt;Three helpful SSH tips for developers&lt;/a&gt;&lt;/p&gt;
</content>
</entry>
<entry>
<title>Give sudo access to any user</title>
<link href="https://www.lafuente.me/posts/give-sudo-access-to-any-user"/>
<updated>2011-01-18T00:00:00-00:00</updated>
<id>https://www.lafuente.me/posts/give-sudo-access-to-any-user</id>
<category term="linux"/><category term="sudo"/>
<content type="html">&lt;p&gt;Normally, after install the OS (Debian in my case), you don&#x27;t have sudo access, and you can see this error:&lt;/p&gt; &lt;pre&gt;&lt;code&gt;user is not in the sudoers file. This incident will be reported. &lt;/code&gt;&lt;/pre&gt; &lt;p&gt;To solve it, first log in as root, to do it enter:&lt;/p&gt; &lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token function&quot;&gt;su&lt;/span&gt; root&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;Now, as super user, you can run this command:&lt;/p&gt; &lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;visudo&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;With this command we open the sudo configuration file, add at the end this line:&lt;/p&gt; &lt;pre&gt;&lt;code&gt;user ALL=(ALL) ALL &lt;/code&gt;&lt;/pre&gt; &lt;p&gt;Replace &lt;code&gt;user&lt;/code&gt; with your user name and save the file. Don&#x27;t forget exit from the super user account, simply enter:&lt;/p&gt; &lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token builtin class-name&quot;&gt;exit&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt; &lt;h2 id=&quot;tip%3A&quot;&gt;Tip: &lt;a class=&quot;direct-link&quot; href=&quot;#tip%3A&quot;&gt;#&lt;/a&gt;&lt;/h2&gt; &lt;p&gt;If you use Debian, and want to change the default text editor for the system, enter this command:&lt;/p&gt; &lt;pre class=&quot;language-bash&quot;&gt;&lt;code class=&quot;language-bash&quot;&gt;&lt;span class=&quot;token function&quot;&gt;sudo&lt;/span&gt; update-alternatives --config editor&lt;/code&gt;&lt;/pre&gt; &lt;p&gt;A list with all text editor will appear and you can select your favourite.&lt;/p&gt; &lt;p&gt;If you want to know where the sudo incident are reported, &lt;a href=&quot;http://xkcd.com/&quot;&gt;xkcd&lt;/a&gt; offers you an explanation:&lt;/p&gt; &lt;p&gt;&lt;img src=&quot;http://imgs.xkcd.com/comics/incident.png&quot; alt=&quot;incident xkcd 838&quot;&gt;&lt;/p&gt;
</content>
</entry>
</feed>