Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
content badge
swh:1:cnt:b930b720725e318de5ff2842a03db147250b29bb

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
(requires biblatex-software package)
Generating citation ...
#! @perl@ -w @perlFlags@

use strict;
use File::Basename;
use IO::Handle;

my $binDir = $ENV{"NIX_BIN_DIR"} || "@bindir@";


STDOUT->autoflush(1);

my @remoteStoresAll = split ':', ($ENV{"NIX_OTHER_STORES"} or "");

my @remoteStores;
foreach my $dir (@remoteStoresAll) {
    push @remoteStores, glob($dir);
}


$ENV{"NIX_REMOTE"} = "";


sub findStorePath {
    my $storePath = shift;
    foreach my $store (@remoteStores) {
        my $sourcePath = "$store/store/" . basename $storePath;
        next unless -e $sourcePath || -l $sourcePath;
        $ENV{"NIX_DB_DIR"} = "$store/var/nix/db";
        return ($store, $sourcePath) if
            system("@bindir@/nix-store --check-validity $storePath") == 0;
    }
    return undef;
}


if ($ARGV[0] eq "--query") {

    while (<STDIN>) {
        my $cmd = $_; chomp $cmd;

        if ($cmd eq "have") {
            my $storePath = <STDIN>; chomp $storePath;
            print STDOUT (defined findStorePath($storePath) ? "1\n" : "0\n");
        }

        elsif ($cmd eq "info") {
            my $storePath = <STDIN>; chomp $storePath;
            my ($store, $sourcePath) = findStorePath($storePath);
            if (!defined $store) {
                print "0\n";
                next; # not an error
            }
            print "1\n";

            $ENV{"NIX_DB_DIR"} = "$store/var/nix/db";
            
            my $deriver = `@bindir@/nix-store --query --deriver $storePath`;
            die "cannot query deriver of `$storePath'" if $? != 0;
            chomp $deriver;
            $deriver = "" if $deriver eq "unknown-deriver";

            my @references = split "\n",
                `@bindir@/nix-store --query --references $storePath`;
            die "cannot query references of `$storePath'" if $? != 0;

            my $narSize = `@bindir@/nix-store --query --size $storePath`;
            die "cannot query size of `$storePath'" if $? != 0;
            chomp $narSize;

            print "$deriver\n";
            print scalar @references, "\n";
            print "$_\n" foreach @references;
            print "$narSize\n";
            print "$narSize\n";
        }

        else { die "unknown command `$cmd'"; }
    }
}


elsif ($ARGV[0] eq "--substitute") {
    die unless scalar @ARGV == 2;
    my $storePath = $ARGV[1];
    my ($store, $sourcePath) = findStorePath $storePath;
    die unless $store;
    print "\n*** Copying `$storePath' from `$sourcePath'\n\n";
    system("$binDir/nix-store --dump $sourcePath | $binDir/nix-store --restore $storePath") == 0
        or die "cannot copy `$sourcePath' to `$storePath'";
}


else { die; }

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API