Skip to content

Instantly share code, notes, and snippets.

@GeorgesAlkhouri
Last active January 13, 2025 19:23
Show Gist options
  • Select an option

  • Save GeorgesAlkhouri/1cda58343338571e1cc14f6a04270f17 to your computer and use it in GitHub Desktop.

Select an option

Save GeorgesAlkhouri/1cda58343338571e1cc14f6a04270f17 to your computer and use it in GitHub Desktop.
Nix store and dependencies management cheat sheet

Nix Fonts without NixOS

Create the local fontconfig directory mkdir -p ~/.config/fontconfig/conf.d/

Create a file in that directory for the Nix fonts

cat << EOF > ~/.config/fontconfig/conf.d/10-nix-fonts.conf
<?xml version='1.0'?>
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
<fontconfig>
 <dir>~/.nix-profile/share/fonts/</dir>
</fontconfig>
EOF

Nix behind Proxy

The Nix installer has special handling for these proxy-related environment variables: http_proxy, https_proxy, ftp_proxy, no_proxy, HTTP_PROXY, HTTPS_PROXY, FTP_PROXY, NO_PROXY.

If any of these variables are set when running the Nix installer, then the installer will create an override file at /etc/systemd/system/nix-daemon.service.d/override.conf so nix-daemon will use them.

Nix Store

Show store path of a package

nix-store -q $(which tldr)

Show all underlying deps of a package

nix-store -q --tree $(which tldr)

Dynamically show all underlying packages of store path

nix run github:utdemir/nix-tree -- path/to/store

Show build log from a package in nix store

nix log $(which tldr)

Show the current system's closure

nix path-info -r /run/current-system

Verify nix store and db consistency [and also repair it]

[sudo] nix-store [--repair] --verify --check-contents

Shows all packages in the nix store that have a direct dependency on a package

nix-store --query --referrers /nix/store/cvsa1c75253sassaqb8dv0mx7sq0gnnp-vvenc-1.13.0.drv

nix-locate to locate packages providing a certain file in nixpkgs

nix-locate 'bin/hello'

Nix Direnv

Add files to be tracked for changes to .envrc

nix_direnv_watch_file your-file.nix
use nix # or use flake

Nix Sec

Create SBOM for target

nix run github:tiiuae/sbomnix#sbomnix -- [--cdx cdx.json] path/to/artifact

Scan store path for vulnerability

nix run github:tiiuae/sbomnix#vulnxscan -- path/to/store

Build

Build NixOS configuration with flake

nix build .#nixosConfigurations.hostname.config.system.build.toplevel

Override

Python packages

      python = let
        packageOverrides = self: super: {
          setuptools = super.setuptools.overridePythonAttrs (old: rec {
            version = "67.6.0";
            src = super.fetchPypi {
              pname = "setuptools";
              inherit version;
              hash = "sha256-LuiSzV8p8zcwl/WoFGl+OXzzzjE2Ft8K8RIx4q0RgHc=";
            };
          });
        };
      in
        pkgs.python39.override {
          inherit packageOverrides;
          self = python;
        };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment