mirror of
https://github.com/Swarsel/.dotfiles.git
synced 2025-12-06 09:07:21 +01:00
The configuration options that used to be stored in Emacs.org and Nix.org are now no longer split into two files. Instead, there now is a single file SwarselSystems.org that holds both these configs.
6.1 KiB
6.1 KiB
Useful Nix bits
- Importing a NixOS module that is not in nixpkgs
- Build a firefox addon
- Define shell utility as package
- Add program with prebuild binaries to nix store
- Patch a utilty for nix paths:
- let-block for overriding a package in nixpkgs (here: replacing airsonic with airsonic-advanced)
This pages houses a few configuration snippets that might be useful if you are new to the nix ecosystem. It will be infrequently updated as I come across things that I deem to be interesting to such a reader.
Importing a NixOS module that is not in nixpkgs
This requires changes in multiple locations. As an example we will use an early version of the mautrix-signal module by Niklas Korz.
-
Add the module source to flake.nix:
{ inputs = { [...] # provides expressions for mautrix-signal nixpkgs-mautrix-signal ={ url = github:niklaskorz/nixpkgs/nixos-23.11-mautrix-signal; }; [...] }; outputs = inputs@{ self, [...] nixpkgs-mautrix-signal, [...] }: let [...] pkgsmautrix = import nixpkgs-mautrix-signal { inherit system; config.allowUnfree = true; }; [...] in { nixosConfigurations = { matrix = nixpkgs.lib.nixosSystem { pkgs = pkgsmautrix; # this is to import a service module that is not on nixpkgs # this way avoids infinite recursion errors specialArgs.unstable = nixpkgs-mautrix-signal; modules = [ [...] ]; }; }; } } -
Import the module in the configuration:
[...] imports = [ [...] (unstable + "/nixos/modules/services/matrix/mautrix-signal.nix") ]; [...]
Build a firefox addon
- app id can be found in the manifest.json file of the .xpi (.xpi is just a normal archive)
- url can be found by copy url of the "add extension" button on the addon page
- the rest of the information is also found in the manifest.json, but might not be needed
programs.firefox = {
[...]
profiles.default = {
[...]
extensions = with pkgs.nur.repos.rycee.firefox-addons; [
[...]
(buildFirefoxXpiAddon {
pname = ":emoji:";
version = "0.1.3";
addonId = "gonelf@gmail.com";
url = "https://addons.mozilla.org/firefox/downloads/file/3365324/emojidots-0.1.3.xpi";
sha256 = "4f7cc25c478fe52eb82f37c9ff4978dcaa3f95020398c5b184e517f6efa2c201";
meta = with lib;
{
description = "emoji autocomplete anywhere on the internet";
mozPermissions = [ "https://gist.githubusercontent.com/gonelf/d8ae3ccb7902b501c4a5dd625d4089da/raw/5eeda197ba92f8c8139e846a1225d5640077e06f/emoji_pretty.json" "tabs" "storage"];
platforms = platforms.all;
};
})
[...]
Define shell utility as package
home.packages = with pkgs; [ # or for NixOS environment.systemPackages = with pkgs; [
[...]
(pkgs.writeShellApplication {
name = "pass-fuzzel";
runtimeInputs = [ pkgs.pass pkgs.fuzzel ];
text = ''
shopt -s nullglob globstar
typeit=0
if [[ $# -ge 1 && $1 == "--type" ]]; then
typeit=1
shift
fi
export PASSWORD_STORE_DIR=~/.local/share/password-store
prefix=''${PASSWORD_STORE_DIR-~/.local/share/password-store}
password_files=( "$prefix"/**/*.gpg )
password_files=( "''${password_files[@]#"$prefix"/}" )
password_files=( "''${password_files[@]%.gpg}" )
password=$(printf '%s\n' "''${password_files[@]}" | fuzzel --dmenu "$@")
[[ -n $password ]] || exit
if [[ $typeit -eq 0 ]]; then
pass show -c "$password" &>/tmp/pass-fuzzel
else
pass show "$password" | { IFS= read -r pass; printf %s "$pass"; } | wtype -
fi
notify-send -u critical -a pass -t 1000 "Copied/Typed Password"
'';
})
[...]
Add program with prebuild binaries to nix store
home.packages = with pkgs; [ # or for NixOS environment.systemPackages = with pkgs; [
[...]
(stdenv.mkDerivation {
name = "oama";
src = pkgs.fetchurl {
name = "oama";
url = "https://github.com/pdobsan/oama/releases/download/0.13.1/oama-0.13.1-Linux-x86_64-static.tgz";
sha256 = "sha256-OTdCObVfnMPhgZxVtZqehgUXtKT1iyqozdkPIV+i3Gc=";
};
phases = [
"unpackPhase"
];
unpackPhase = ''
mkdir -p $out/bin
tar xvf $src -C $out/
mv $out/oama-0.13.1-Linux-x86_64-static/oama $out/bin/
'';
})
[...]
Patch a utilty for nix paths:
let-block for overriding a package in nixpkgs (here: replacing airsonic with airsonic-advanced)
This can be useful if a module does not let you use your own package yourself.
pkgs = import nixpkgs { inherit system;
overlays = [ emacs-overlay.overlay
nur.overlay
nixgl.overlay
(self: super: {
airsonic = super.airsonic.overrideAttrs (_: rec {
version = "11.0.2-kagemomiji";
name = "airsonic-advanced-${version}";
src = super.fetchurl {
url = "https://github.com/kagemomiji/airsonic-advanced/releases/download/11.0.2/airsonic.war";
sha256 = "PgErtEizHraZgoWHs5jYJJ5NsliDd9VulQfS64ackFo=";
};
});
})
];
config.allowUnfree = true;
};