Created
March 21, 2020 08:33
-
-
Save davidak/171f81f945f36d7fd88dce4e67af8a5d to your computer and use it in GitHub Desktop.
Use older package version with Nix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This works with the package manager [Nix](https://nixos.org/nix/), available on NixOS and working on most linux distros and macOS (theoretically also BSD and Windows). | |
1. search for package definition on GitHub, for example ansible | |
https://github.com/NixOS/nixpkgs/search?p=1&q=ansible&unscoped_q=ansible | |
it is here https://github.com/NixOS/nixpkgs/blob/master/pkgs/tools/admin/ansible/default.nix | |
2. search the history for the last commit with your preferred version, for example 2.5 | |
https://github.com/NixOS/nixpkgs/blob/dcf5fd5afcced6e8e89d8dd3b7ff6eda86cd2958/pkgs/tools/admin/ansible/default.nix | |
3. create an interactive shell with that package version available, with nix-shell | |
specify the commit id in the URL, here dcf5fd5 | |
``` | |
[davidak@X230:~]$ nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs-channels/archive/dcf5fd5.tar.gz -p ansible_2_5 | |
... | |
[nix-shell:~]$ ansible --version | |
ansible 2.5.15 | |
config file = None | |
configured module search path = ['/home/davidak/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] | |
ansible python module location = /nix/store/4crxnkz6zvkl2j8nxcfpnxr1yjaba86m-python3.7-ansible-2.5.15/lib/python3.7/site-packages/ansible | |
executable location = /nix/store/4crxnkz6zvkl2j8nxcfpnxr1yjaba86m-python3.7-ansible-2.5.15/bin/ansible | |
python version = 3.7.3 (default, Mar 25 2019, 20:59:09) [GCC 7.4.0] | |
``` | |
when you exit the shell, the package is no longer in your PATH. so your system remains clean. the package and it's specific dependencies will get removed from the disk with next `nix-collect-garbage -d` | |
when the version you need was never packaged, you might be able to use overrides, when the dependencies are still the same | |
like actually done here https://github.com/NixOS/nixpkgs/blob/dcf5fd5afcced6e8e89d8dd3b7ff6eda86cd2958/pkgs/tools/admin/ansible/default.nix#L8-L16 | |
or you can package it locally, in your configuration. use the existing package definition as base and modify as needed | |
i for example have a personal package that no one else needs, so i have it in my own git instead of upstreaming it into nixpkgs | |
https://github.com/davidak/nixos-config/blob/master/packages/satzgenerator.nix | |
this is a python application. the package definition is actually quiet simple |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment