Nix Cookbook: Difference between revisions
imported>Nix add generation trimmer script info |
imported>Nix add security section |
||
| Line 88: | Line 88: | ||
== Environment | == Environment tasks == | ||
=== Creating | === Creating shell scripts === | ||
Arbitrary system shell scripts can be created with [https://github.com/NixOS/nixpkgs/blob/808125fff694e4eb4c73952d501e975778ffdacd/pkgs/build-support/trivial-builders.nix#L225-L250 pkgs.writeShellScriptBin]. It creates a derivation which you add to [https://nixos.org/nixos/manual/#sec-declarative-package-mgmt environment.systemPackages]. | Arbitrary system shell scripts can be created with [https://github.com/NixOS/nixpkgs/blob/808125fff694e4eb4c73952d501e975778ffdacd/pkgs/build-support/trivial-builders.nix#L225-L250 pkgs.writeShellScriptBin]. It creates a derivation which you add to [https://nixos.org/nixos/manual/#sec-declarative-package-mgmt environment.systemPackages]. | ||
<syntaxHighlight lang="nix"> | <syntaxHighlight lang="nix"> | ||
| Line 105: | Line 105: | ||
</syntaxHighlight> | </syntaxHighlight> | ||
=== Creating | === Creating periodic services === | ||
Using the [https://nixos.org/nixos/manual/#sec-systemctl systemd support] periodic services can be defined. In this case a service named <code>simple-timer</code> writes out the current time to <code>/tmp/simple-timer.log</code> every minute. | Using the [https://nixos.org/nixos/manual/#sec-systemctl systemd support] periodic services can be defined. In this case a service named <code>simple-timer</code> writes out the current time to <code>/tmp/simple-timer.log</code> every minute. | ||
<syntaxHighlight lang="nix> | <syntaxHighlight lang="nix> | ||
| Line 126: | Line 127: | ||
} | } | ||
</syntaxHighlight> | </syntaxHighlight> | ||
== Wrapping packages == | == Wrapping packages == | ||
If you need to wrap a binary of a package (or a non-binary), there are a few ways of doing it. The simplest of which is just creating a new binary that calls the old one: | If you need to wrap a binary of a package (or a non-binary), there are a few ways of doing it. The simplest of which is just creating a new binary that calls the old one: | ||
| Line 201: | Line 204: | ||
}) | }) | ||
</syntaxHighlight> | </syntaxHighlight> | ||
== Securing Nix == | |||
See [[Security]] | |||
== Debugging == | == Debugging == | ||
=== Common | === Common errors === | ||
==== Bad configuration option: gssapikexalgorithms ==== | ==== Bad configuration option: gssapikexalgorithms ==== | ||
| Line 210: | Line 219: | ||
Found when using an SSH binary from Nix on typically RPM-based distros like CentOS, Fedora, Scientific Linux, Redhat, etc. '''The quick fix:''' Just comment out the configuration option in the ssh config file, you probably don't need it. | Found when using an SSH binary from Nix on typically RPM-based distros like CentOS, Fedora, Scientific Linux, Redhat, etc. '''The quick fix:''' Just comment out the configuration option in the ssh config file, you probably don't need it. | ||
==== Desktop | ==== Desktop environment does not find .desktop files ==== | ||
IF your DE does not look in <code>$HOME/.nix-profile/share</code> for .desktop files. | IF your DE does not look in <code>$HOME/.nix-profile/share</code> for .desktop files. | ||
| Line 224: | Line 233: | ||
NOTE: The above fix will make your programs installed by nix visible in your application menu, but you still will not be able to run them, because they are symlinked outside your XDG_DATA_DIRS paths, and are not executable (one or the other criteria must be met to run the program from a menu). This impacts KDE users, and potentially others. I noticed that on native NixOS with KDE, NixOS adds all these paths for each application to one's XDG_DATA_DIRS variable. | NOTE: The above fix will make your programs installed by nix visible in your application menu, but you still will not be able to run them, because they are symlinked outside your XDG_DATA_DIRS paths, and are not executable (one or the other criteria must be met to run the program from a menu). This impacts KDE users, and potentially others. I noticed that on native NixOS with KDE, NixOS adds all these paths for each application to one's XDG_DATA_DIRS variable. | ||
==== | ==== Error: the option has conflicting definitions ==== | ||
If while doing a <syntaxHighlight lang="console">nixos-rebuild switch</syntaxHighlight> you see an error like: | If while doing a <syntaxHighlight lang="console">nixos-rebuild switch</syntaxHighlight> you see an error like: | ||