<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>Nix Grymoire</title>
  <link href="http://v2.whatthefuck.computer/grymoires/nix"/>
  <link rel="self" href="http://v2.whatthefuck.computer/grymoires/nix.xml"/>
  <updated>2024-10-23T10:50:00Z</updated>
  <author>
    <name>ryan rix &lt;garden@whatthefuck.computer&gt;</name>
  </author>
  <id>http://v2.whatthefuck.computer/grymoires/nix</id>
    <entry>
    <title>Include local repo submodules in =nix build=</title>
    <link href="http://v2.whatthefuck.computer/grymoires/nix#20241023T105057.464999"/>
    <id>urn:uid:20241023T105057.464999</id>
    <published>2024-10-23T10:50:00Z</published>
    <updated>2024-10-23T10:50:00Z</updated>
    <content type="html">&lt;article&gt;&lt;h1 id=&quot;20241023T105057.464999&quot;&gt;Include local repo submodules in &lt;code&gt;nix build&lt;/code&gt;&lt;/h1&gt;&lt;p&gt;Another beautiful little piece of a priori knowledge, how to get a local nix flake build to include the repo&amp;#39;s submodules:
&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;You do not add the submodule itself as an input, you need to add the submodules=1 query parameter to the input that has the submodule.
&lt;/p&gt;&lt;/blockquote&gt;&lt;figure class=&quot;src-block&quot; data-language=&quot;shell&quot;&gt;&lt;figcaption class=&quot;src-block-meta&quot;&gt;&lt;span class=&quot;src-lang&quot;&gt;shell&lt;/span&gt;&lt;/figcaption&gt;&lt;pre&gt;&lt;code class=&quot;language-shell&quot;&gt;nix build .?submodules=1&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;&lt;/article&gt;</content>
  </entry>
    <entry>
    <title>How to prevent double-wrapping of =nixpkgs= apps</title>
    <link href="http://v2.whatthefuck.computer/grymoires/nix#20240610T155108.463916"/>
    <id>urn:uid:20240610T155108.463916</id>
    <published>2024-06-10T16:15:00Z</published>
    <updated>2024-06-10T16:15:00Z</updated>
    <content type="html">&lt;article&gt;&lt;h1 id=&quot;20240610T155108.463916&quot;&gt;How to prevent double-wrapping of &lt;code&gt;nixpkgs&lt;/code&gt; apps&lt;/h1&gt;&lt;p&gt;Recently &lt;code&gt;pantalaimon&lt;/code&gt; stopped working, complaining that it couldn&amp;#39;t do &lt;code&gt;GObject&lt;/code&gt; introspection to load the DBus library it uses for its user interface. I spent some time digging in to it because i like using &lt;a href=&quot;//v2.cce.whatthefuck.computer/ement&quot;&gt;Ement.el&lt;/a&gt; more than &lt;code&gt;element-desktop&lt;/code&gt;, and found that GTK/GNOME apps require these &amp;quot;typelib&amp;quot; files to be in a known path to do the object introspection. (I don&amp;#39;t know how you GNOME/GTK people live like this, but that&amp;#39;s a different conversation)
&lt;/p&gt;&lt;p&gt;My first attempt injected them with a custom &lt;code&gt;wrapProgram&lt;/code&gt; invocation since &lt;code&gt;wrapGAppsHook&lt;/code&gt; was used for GUI stuff:
&lt;/p&gt;&lt;figure class=&quot;src-block&quot; data-language=&quot;nix&quot;&gt;&lt;figcaption class=&quot;src-block-meta&quot;&gt;&lt;span class=&quot;src-lang&quot;&gt;nix&lt;/span&gt;&lt;/figcaption&gt;&lt;pre&gt;&lt;code class=&quot;language-nix&quot;&gt;postFixup = let
  typelibPath = lib.makeSearchPath &amp;quot;/lib/girepository-1.0&amp;quot; [
    (placeholder &amp;quot;out&amp;quot;)
    (lib.getLib glib)
  ];
in &amp;#39;&amp;#39;
  for pgm in pantalaimon panctl; do 
    wrapProgram &amp;quot;$out/bin/$pgm&amp;quot; \
      --prefix GI_TYPELIB_PATH : &amp;quot;$GI_TYPELIB_PATH:${typelibPath}&amp;quot;
  done
&amp;#39;&amp;#39;;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;&lt;p&gt;The reviewer on my &lt;code&gt;nixpkgs&lt;/code&gt; pull request for this recommended using &lt;code&gt;wrapGAppsNoGuiHook&lt;/code&gt; which I hadn&amp;#39;t seen before, but then said that it had to prevent &amp;quot;double-wrapping&amp;quot;, a thing I&amp;#39;ve seen myself but never resolved:
&lt;/p&gt;&lt;figure class=&quot;src-block&quot;&gt;&lt;figcaption class=&quot;src-block-meta&quot;&gt;&lt;/figcaption&gt;&lt;pre&gt;&lt;code&gt;[rrix@virtuous-cassette:~/Code/nixpkgs]$ ls -alh /nix/store/kxddbaf1w5wwwfpi02fscmqfmc6jfgqz-pantalaimon-0.10.5/bin/
total 37K
dr-xr-xr-x 2 root root    8 Dec 31  1969 .
dr-xr-xr-x 6 root root    6 Dec 31  1969 ..
-r-xr-xr-x 1 root root  16K Dec 31  1969 panctl
-r-xr-xr-x 1 root root  16K Dec 31  1969 .panctl-wrapped
-r-xr-xr-x 1 root root 6.6K Dec 31  1969 ..panctl-wrapped-wrapped
-r-xr-xr-x 1 root root  16K Dec 31  1969 pantalaimon
-r-xr-xr-x 1 root root  16K Dec 31  1969 .pantalaimon-wrapped
-r-xr-xr-x 1 root root 6.6K Dec 31  1969 ..pantalaimon-wrapped-wrapped&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;&lt;p&gt;The person recommended the following, which I did and does work, yet another &lt;a href=&quot;Nixpkgs A Priori Pattern&quot;&gt;Nixpkgs A Priori Pattern&lt;/a&gt;...:
&lt;/p&gt;&lt;figure class=&quot;src-block&quot; data-language=&quot;nix&quot;&gt;&lt;figcaption class=&quot;src-block-meta&quot;&gt;&lt;span class=&quot;src-lang&quot;&gt;nix&lt;/span&gt;&lt;/figcaption&gt;&lt;pre&gt;&lt;code class=&quot;language-nix&quot;&gt;nativeBuildInputs = [
  wrapGAppsNoGuiHook
  gobject-introspection
];

# Prevent double wrapping from wrapGApps and wrapPythonProgram
dontWrapGApps = true;
makeWrapperArgs = [
  &amp;quot;\${gappsWrapperArgs[@]}&amp;quot;
];&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;&lt;p&gt;aye aye aye...
&lt;/p&gt;&lt;/article&gt;</content>
  </entry>
    <entry>
    <title>Building a Plasma package or entire environment using =ccache=</title>
    <link href="http://v2.whatthefuck.computer/grymoires/nix#20240603T154141.986445"/>
    <id>urn:uid:20240603T154141.986445</id>
    <published>2024-06-02T15:45:00Z</published>
    <updated>2024-06-02T15:45:00Z</updated>
    <content type="html">&lt;article&gt;&lt;h1 id=&quot;20240603T154141.986445&quot;&gt;Building a Plasma package or entire environment using &lt;code&gt;ccache&lt;/code&gt;&lt;/h1&gt;&lt;p&gt;I&amp;#39;ve tried a few times now to build software on my nixos system &lt;a href=&quot;//nixos.wiki/wiki/CCache&quot;&gt;using ccache&lt;/a&gt;, but I failed mostly because &lt;code&gt;programs.ccache.packageNames&lt;/code&gt; didn&amp;#39;t reliably recurse in to the &lt;code&gt;attrset&lt;/code&gt; which all the KDE packages are hidden in. Anyways, I don&amp;#39;t compile things very often, so it was mostly shelved.
&lt;/p&gt;&lt;p&gt;I&amp;#39;ve been for a few months now dealing with a difficult to reproduce crasher &lt;a href=&quot;//bugs.kde.org/show_bug.cgi?id=480925&quot;&gt;bug in Plasma KWin Wayland&lt;/a&gt; and I am more motivated than ever to try to track this down. Especially after david edmundson dropped a patch that is &amp;quot;close but no cigar&amp;quot;, I wanted to get to the point where I could build KWin and not have it be a full recompile every time I added a debug statement.
&lt;/p&gt;&lt;p&gt;This is what &lt;code&gt;ccache&lt;/code&gt; is for!
&lt;/p&gt;&lt;p&gt;In my custom package overlay I was only able to get &lt;code&gt;ccache&lt;/code&gt; used for these builds by overriding the &lt;code&gt;plasma5Packages&lt;/code&gt; &amp;quot;scope&amp;quot; -- another essentially undocumented &lt;a href=&quot;Nixpkgs A Priori Pattern&quot;&gt;Nixpkgs A Priori Pattern&lt;/a&gt;. This would cause &lt;code&gt;ccache&lt;/code&gt; to be used for every binary, and cause Binary Cache misses; every Plasma package would be compiled from source! 😩
&lt;/p&gt;&lt;p&gt;But you can do Some &lt;a href=&quot;//v2.whatthefuck.computer/computer-sad&quot;&gt;Computer :(&lt;/a&gt; Bullshit to override the scope just for KWin and inject my local source checkout in the process, I wonder if someone can suggest something more legible:
&lt;/p&gt;&lt;figure class=&quot;src-block&quot; data-language=&quot;nix&quot;&gt;&lt;figcaption class=&quot;src-block-meta&quot;&gt;&lt;span class=&quot;src-lang&quot;&gt;nix&lt;/span&gt;&lt;/figcaption&gt;&lt;pre&gt;&lt;code class=&quot;language-nix&quot;&gt;final: prev:
{
  plasma5Packages = let
    p5pcc = pkgs.plasma5Packages.overrideScope (pFinal: pPrev: rec {
      stdenv = pkgs.ccacheStdenv;
    });
  in
    pkgs.plasma5Packages.overrideScope (plasmaFinal: plasmaPrev: rec {
      kwin = p5pcc.kwin.overrideAttrs (old: {
        src = /home/rrix/Code/kwin;
      });
    });
}&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;create a &lt;code&gt;plasma5Packages&lt;/code&gt; scope with the &lt;code&gt;ccacheStdenv&lt;/code&gt; injected in to it called &lt;code&gt;p5pcc&lt;/code&gt;
&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;override the &amp;quot;stock&amp;quot; &lt;code&gt;plasma5Packages&lt;/code&gt; to:
  &lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;take the KWin package and override its &lt;code&gt;src&lt;/code&gt; attribute to point to my local fs
  &lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;use the scope with &lt;code&gt;ccache&lt;/code&gt; in it for KWin and its dependencies
&lt;/p&gt;&lt;p&gt;
&lt;/p&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/article&gt;</content>
  </entry>
    <entry>
    <title>Know when to use the undocumented =mkMerge= command</title>
    <link href="http://v2.whatthefuck.computer/grymoires/nix#20240214T164229.017718"/>
    <id>urn:uid:20240214T164229.017718</id>
    <published>2024-02-14T16:42:00Z</published>
    <updated>2024-02-14T16:42:00Z</updated>
    <content type="html">&lt;article&gt;&lt;h1 id=&quot;20240214T164229.017718&quot;&gt;Know when to use the undocumented &lt;code&gt;mkMerge&lt;/code&gt; command&lt;/h1&gt;&lt;p&gt;When writing NixOS modules, you often need to make sure that attrsets with dynamic or &lt;code&gt;cfg.enable&lt;/code&gt; or other &lt;code&gt;mkIf&lt;/code&gt; thing are merged lazily; this is done with the un-documented &lt;code&gt;nixpkgs&lt;/code&gt; function &lt;code&gt;lib.mkMerge&lt;/code&gt;... 
&lt;/p&gt;&lt;/article&gt;</content>
  </entry>
    <entry>
    <title>Copying a nix closure to a =nixos-enter=&#39;d NixOS Install (rescue environment, installer, etc)</title>
    <link href="http://v2.whatthefuck.computer/grymoires/nix#20240111T095631.700564"/>
    <id>urn:uid:20240111T095631.700564</id>
    <published>2024-01-11T09:56:00Z</published>
    <updated>2024-01-11T09:56:00Z</updated>
    <content type="html">&lt;article&gt;&lt;h1 id=&quot;20240111T095631.700564&quot;&gt;Copying a nix closure to a =nixos-enter=&amp;#39;d NixOS Install (rescue environment, installer, etc)&lt;/h1&gt;&lt;figure class=&quot;src-block&quot; data-language=&quot;shell&quot;&gt;&lt;figcaption class=&quot;src-block-meta&quot;&gt;&lt;span class=&quot;src-lang&quot;&gt;shell&lt;/span&gt;&lt;/figcaption&gt;&lt;pre&gt;&lt;code class=&quot;language-shell&quot;&gt;nix copy --to ssh://root@192.168.69.36?remote-store=local?root=/mnt /nix/store/dalm2ggzvgd2b09m0lrff61gbqf8gy05-morph --no-check-sigs&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;&lt;p&gt;I hosed my server pretty hard, and ended up having to deploy a new version of grub configuration, mountpoints etc, while I only had access to a rescue environment attached to the server. While I plan to write a full postmortem of that incident, this is useful for myself and for others, i found it discussed only in a github issue for &lt;code&gt;nix&lt;/code&gt;, presumably the options passed to the &lt;code&gt;ssh&lt;/code&gt; path are documented &lt;strong&gt;somewhere&lt;/strong&gt; but this will copy in to a store mounted under &lt;code&gt;/mnt/nix/store&lt;/code&gt; which sure is nice!
&lt;/p&gt;&lt;/article&gt;</content>
  </entry>
    <entry>
    <title>Adding a flake check to run pytest</title>
    <link href="http://v2.whatthefuck.computer/grymoires/nix#20231108T211142.868242"/>
    <id>urn:uid:20231108T211142.868242</id>
    <published>2023-11-01T21:00:00Z</published>
    <updated>2023-11-01T21:00:00Z</updated>
    <content type="html">&lt;article&gt;&lt;h1 id=&quot;20231108T211142.868242&quot;&gt;Adding a flake check to run pytest&lt;/h1&gt;&lt;figure class=&quot;src-block&quot; data-language=&quot;nix&quot;&gt;&lt;figcaption class=&quot;src-block-meta&quot;&gt;&lt;span class=&quot;src-lang&quot;&gt;nix&lt;/span&gt;&lt;/figcaption&gt;&lt;pre&gt;&lt;code class=&quot;language-nix&quot;&gt;checks.pytest = pkgs.stdenvNoCC.mkDerivation {
  name = &amp;quot;pytest&amp;quot;;
  src =./.;
  dontBuild = true;
  doCheck = true;
  nativeBuildInputs = [
    pkgs.python3.pkgs.pytest
    pkgs.callPackage ./default.nix {};
  ];
  checkPhase = &amp;quot;pytest test&amp;quot;;
  installPhase = &amp;quot;mkdir $out&amp;quot;;
};&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;&lt;/article&gt;</content>
  </entry>
  </feed>