Code Monkey home page Code Monkey logo

userscan's Introduction

fc-userscan

Scans directories containing manually compiled programs and registers them with the Nix garbage collector.

Problem description

One can install fancy libs using nix-env and compile programs against them. But, after a system update, the Nix garbage collector comes and pulls dynamic link and other runtime dependencies out from under our manually compiled files.

This problem exists for some extent on all distros, but in NixOS it's amplified by the fact that even smallest changes somewhere down the dependency chain will change checksums from which Nix store paths are constructed.

Solution

This tool allows to scan arbitrary directories and to register all Nix dependencies found as GC roots so that they won't be taken away by the garbage collector. Since plain string search is used, it works for both dynamic linkage and other references, like config file paths.

Example

Consider a Python virtualenv:

$ nix-env --install python3
$ pyvenv myvenv

Now let's see if there are Nix store references present (hint: there are):

$ fc-userscan -l myvenv
myvenv/bin/python3.5
/nix/store/a5zbx856hyfgz2isz0j60i8w44i6av09-python3-3.5.2

myvenv/pyvenv.cfg
/nix/store/a5zbx856hyfgz2isz0j60i8w44i6av09-python3-3.5.2

fc-userscan scans and registers Nix store references found either as symlinks (like python3.5) or in files (pyvenv.cfg). The -l flag causes found references to be dumped to stdout. At the same time, found references are registered with the Nix garbage collector:

$ ls -lR /nix/var/nix/gcroots/profiles/per-user/ckauhaus/home/ckauhaus/myvenv
/nix/var/nix/gcroots/profiles/per-user/ckauhaus/home/ckauhaus/myvenv
lrwxrwxrwx 1 ckauhaus users 57 Aug 11 13:29 a5zbx856hyfgz2isz0j60i8w44i6av09 -> /nix/store/a5zbx856hyfgz2isz0j60i8w44i6av09-python3-3.5.2
drwxr-xr-x 2 ckauhaus users 46 Aug 11 13:29 bin

/nix/var/nix/gcroots/profiles/per-user/ckauhaus/home/ckauhaus/myvenv/bin
lrwxrwxrwx 1 ckauhaus users 57 Aug 11 13:29 a5zbx856hyfgz2isz0j60i8w44i6av09 -> /nix/store/a5zbx856hyfgz2isz0j60i8w44i6av09-python3-3.5.2

All GC root registrations for a given dir $DIR go into /nix/var/nix/gcroots/profiles/per-user/$USER/$DIR so this can easily be inspected by the administrator. Should a reference vanish at the original location, the registration will be cleaned up by the next run.

Hacking

fc-userscan compiles with Rust 1.39.0 or higher.

To conveniently build setuid executables, install cargo-make and run cargo make suid.

I'll happily accept pull requests at the GitHub repository. Please write tests if feasible.

Contact

The primary author of fc-userscan is Christian Kauhaus or @ckauhaus on various online services.

License

The software is licensed under a 3-clause BSD license.

userscan's People

Contributors

ctheune avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.