P2 Tooling Installation via nix for AnyLinux™ (any Linux Distribution)

__red____red__ Posts: 449
edited 2019-01-15 - 01:20:01 in Propeller 2
Greetings.

tl;dr - if you want to go straight to installation - scroll down!


What:
nix is a package manager whose primary advantage is that it DOES NOT POLLUTE your existing OS. All application files / executables etc live in one directory tree which means that removing it and any applications that it manages is as simple as deleting that one directory.

So What:
As nix manages ALL of the dependencies, it will run on ANY Linux OS regardless of age and configuration. With the exception of one command, its use is entirely done as an unprivileged user. You can even make applications visible to single shell sessions only such that they disappear when your shell exits!

Now What
See Installation Below:


ChangeLog:
2019-01-13: Bumped p2gcc to 2019-01-13r0
2019-01-12: nix will now download binary packages instead of compiling everything locally.
2019-01-12: Versions bumped to: propeller-gcc: "2018-04-14r1", p2gcc: "2019-01-12r1", spin2cpp: "2018-11-03r0", spinsim: "2018-12-06r0";

Packaging Notes
1. We do not honor the P2GCC_LIBDIR environmental variable but instead set the value to the location of the lib/ directory.
2. propeller-gcc includes its own version of spinsim and spin2cpp. As propeller-gcc includes 'pinned' versions (and maybe for good reasons I don't know about yet) I let propeller-gcc install its version. We probably shouldn't do that, but I need to make sure before I start modifying what is in the 'standard' package.

Installation
[nixdemo@ubuntut0:~] $ bash <(curl https://nixos.org/nix/install)
Note: a multi-user installation is possible. See https://nixos.org/nix/manual/#sect-multi-user-installation
performing a single-user installation of Nix...
directory /nix does not exist; creating it by running 'mkdir -m 0755 /nix && chown nixdemo /nix' using sudo
[sudo] password for nixdemo:
copying Nix to /nix/store.................................
initialising Nix database...
Nix: creating /home/nixdemo/.nix-profile
installing 'nix-2.2.1'
building '/nix/store/jkcbkr60gzcmz6bk9y4j4bhlx8qcqcyz-user-environment.drv'...
created 6 symlinks in user environment
unpacking channels...
created 2 symlinks in user environment
modifying /home/nixdemo/.profile...

Installation finished!  To ensure that the necessary environment
variables are set, either log in again, or type

  . /home/nixdemo/.nix-profile/etc/profile.d/nix.sh

in your shell.
[nixdemo@ubuntut0:~] $ . /home/nixdemo/.nix-profile/etc/profile.d/nix.sh
[nixdemo@ubuntut0:~] $ nix-env -iA cachix -f https://cachix.org/api/v1/install
unpacking 'https://cachix.org/api/v1/install'...
installing 'cachix-0.1.3'
these paths will be fetched (9.88 MiB download, 47.89 MiB unpacked):
  /nix/store/86kmx16flgixkzf22gaga8lxdds2wiw2-ncurses-6.1-20181027
  /nix/store/frvzsnzrw8baq58vb2zhqjkrkm3x0pxc-gmp-6.1.2
  /nix/store/idq4dzxj0ylmh16vm3hyv25s2dz1w6kc-zlib-1.2.11
  /nix/store/im2lxq8pz0l6qb4wx25hiqnv0d1lbcsb-xz-5.2.4
  /nix/store/mrfcv8ipiksfdrx3xq7dvcrzgg2jdfsw-glibc-2.27
  /nix/store/x3jacyl2lp46wcd6n9qyn07rhafnsp1q-gcc-7.3.0-lib
  /nix/store/xdbc2dja9dn6yrbm9ln8245cxynm5qhb-cachix-0.1.3
copying path '/nix/store/mrfcv8ipiksfdrx3xq7dvcrzgg2jdfsw-glibc-2.27' from 'https://cache.nixos.org'...
copying path '/nix/store/x3jacyl2lp46wcd6n9qyn07rhafnsp1q-gcc-7.3.0-lib' from 'https://cache.nixos.org'...
copying path '/nix/store/86kmx16flgixkzf22gaga8lxdds2wiw2-ncurses-6.1-20181027' from 'https://cache.nixos.org'...
copying path '/nix/store/frvzsnzrw8baq58vb2zhqjkrkm3x0pxc-gmp-6.1.2' from 'https://cache.nixos.org'...
copying path '/nix/store/im2lxq8pz0l6qb4wx25hiqnv0d1lbcsb-xz-5.2.4' from 'https://cache.nixos.org'...
copying path '/nix/store/idq4dzxj0ylmh16vm3hyv25s2dz1w6kc-zlib-1.2.11' from 'https://cache.nixos.org'...
copying path '/nix/store/xdbc2dja9dn6yrbm9ln8245cxynm5qhb-cachix-0.1.3' from 'https://cache.nixos.org'...
building '/nix/store/vkpic61rfqphsxllp4m1wad12qa024s4-user-environment.drv'...
created 22 symlinks in user environment
[nixdemo@ubuntut0: ~] $ cachix use redvers
Configured https://redvers.cachix.org binary cache in /home/nixdemo/.config/nix/nix.conf
[nixdemo@ubuntut0:~] $ mkdir -p .config/nixpkgs/overlays
[nixdemo@ubuntut0:~] $ cd .config/nixpkgs/overlays/
[nixdemo@ubuntut0:~/.config/nixpkgs/overlays] $ git clone  https://github.com/redvers/parallax-tooling
Cloning into 'parallax-tooling'...
remote: Enumerating objects: 51, done.
remote: Counting objects: 100% (51/51)
remote: Counting objects: 100% (51/51), done.
[nixdemo@ubuntut0:~/.config/nixpkgs/overlays] $ nix-env -i p2gcc
installing 'p2gcc-2019-01-12r1'
these paths will be fetched (0.08 MiB download, 0.37 MiB unpacked):
  /nix/store/slxljvzw1a8hgqnkap7yz5z34dq2d0q6-p2gcc-2019-01-12r1
copying path '/nix/store/slxljvzw1a8hgqnkap7yz5z34dq2d0q6-p2gcc-2019-01-12r1' from 'https://redvers.cachix.org'...
building '/nix/store/hg585gay00f0rs7mwl94g0xrsczmpsj6-user-environment.drv'...
created 327 symlinks in user environment
nixdemo@ubuntut0: ~/.config/nixpkgs/overlays] $ p2gcc
usage: p2gcc [options] file [file...]
  options are
  -c      - Do not run the linker
  -v      - Enable verbose mode
  -d      - Enable debug mode
  -r      - Run after linking
  -t      - Run terminal emulator
  -T      - Run terminal emulator in PST mode
  -k      - Keep intermediate files
  -s      - Run simulutor
  -o file - Set output file name
  -p port - Port used for loading
[nixdemo@ubuntut0:~/.config/nixpkgs/overlays] $ nix-env -i propeller-gcc
installing 'propeller-gcc-2018-04-14r1'
these paths will be fetched (74.08 MiB download, 369.81 MiB unpacked):
  /nix/store/22lrlr8d1d0dymy29jfpgmksfx1p5kc6-glibc-2.27-bin
  /nix/store/5l7mynximjv4jl6wm22bwzclabggxswi-propeller-gcc-2018-04-14r1
  /nix/store/6dywfq0s7crkl012wbkp6sjq9wgzklwy-expat-2.2.6-dev
  /nix/store/b2xkfmhfa4l4fznwqr4xz6vy97qzq250-flex-2.6.4
  /nix/store/c90akqjk2lk9r18wvxnkvd07j2nnl3f1-linux-headers-4.18.3
  /nix/store/g3laz2ssygn0nllgndqn64qi3phsijsh-gnum4-1.4.18
  /nix/store/p7j7qg5cri229ihf8nllwjhzgbvgx5d0-gcc-7.3.0
  /nix/store/psqblh5bsgkbkhn4r648pgjw5rq4npkv-glibc-2.27-dev
copying path '/nix/store/c90akqjk2lk9r18wvxnkvd07j2nnl3f1-linux-headers-4.18.3' from 'https://cache.nixos.org'...
copying path '/nix/store/6dywfq0s7crkl012wbkp6sjq9wgzklwy-expat-2.2.6-dev' from 'https://cache.nixos.org'...
copying path '/nix/store/22lrlr8d1d0dymy29jfpgmksfx1p5kc6-glibc-2.27-bin' from 'https://cache.nixos.org'...
copying path '/nix/store/g3laz2ssygn0nllgndqn64qi3phsijsh-gnum4-1.4.18' from 'https://cache.nixos.org'...
copying path '/nix/store/psqblh5bsgkbkhn4r648pgjw5rq4npkv-glibc-2.27-dev' from 'https://cache.nixos.org'...
copying path '/nix/store/b2xkfmhfa4l4fznwqr4xz6vy97qzq250-flex-2.6.4' from 'https://cache.nixos.org'...
copying path '/nix/store/p7j7qg5cri229ihf8nllwjhzgbvgx5d0-gcc-7.3.0' from 'https://cache.nixos.org'...
copying path '/nix/store/5l7mynximjv4jl6wm22bwzclabggxswi-propeller-gcc-2018-04-14r1' from 'https://redvers.cachix.org'...
building '/nix/store/p2cj0p96zjm53y28x0sjagzn2sv1h87m-user-environment.drv'...
created 425 symlinks in user environment

Testing

Write the following (simple) C program (foo.c):
#include "stdio.h"

int main() {
   sleep(10);
   printf("Hello World\n");
}

Compile and test it in the simulator like this:
[nixdemo@ubuntut0:~$] p2gcc  -v -t -s foo.c -o foo
propeller-elf-gcc -mcog -Os -m32bit-doubles -S foo.c
s2pasm -p/nix/store/slxljvzw1a8hgqnkap7yz5z34dq2d0q6-p2gcc-2019-01-12r1/lib/prefix.spin2 foo
p2asm -c -o foo.spin2
p2link /nix/store/slxljvzw1a8hgqnkap7yz5z34dq2d0q6-p2gcc-2019-01-12r1/lib/prefix.o -v foo.o -o foo /nix/store/slxljvzw1a8hgqnkap7yz5z34dq2d0q6-p2gcc-2019-01-12r1/lib/stdio.a /nix/store/slxljvzw1a8hgqnkap7yz5z34dq2d0q6-p2gcc-2019-01-12r1/lib/stdlib.a /nix/store/slxljvzw1a8hgqnkap7yz5z34dq2d0q6-p2gcc-2019-01-12r1/lib/string.a
Found offset of 12 for symbol ___files of type 04 at location 5f4
spinsim -b -t foo
Hello World

... and to run on the REAL hardware:
[red@apophenia:~/projects/testing-propellergcc]$ loadp2 -p /dev/ttyUSB0 -t foo
[ Entering terminal mode.  Press ESC to exit. ]                                                                                                                                                                                                                                                                                                
Hello World

Comments

  • Sorry - the 'spoiler' tag doesn't seem to function in my browser so I split the command and output by using quote instead.
  • I'm surprised it doesn't compile the tools locally. How to update when Dave or Eric bug fixes?

    Money is a placeholder for cooperation
  • evanh wrote: »
    I'm surprised it doesn't compile the tools locally.

    If you want it to always compile locally, just don't execute the cachix command as that's the command that enables the binary caching.
    How to update when Dave or Eric bug fixes?

    I'm tracking them in the repo so as updates get pushed them them, those changes should update too. I'll document how this works when I see the next set of code updates hit.

    The very abridged version of a simple local version bump:

    Edit the file pkgs/packagename/default.nix. For example, for p2gcc:
       version = "2019-01-12r1";
        name = "p2gcc-${version}";
    
        buildInputs = [ propeller-gcc ];
    
        src = fetchFromGitHub {
          owner = "davehein";
          repo  = "p2gcc";
          rev   = "2d7fcd554bbb700bfd8fd49ade01b5b386c44f9f";
          sha256 = "10ind8d6v7islyfjng9wjy0vmk9lbqp70jca8lq6s4c96b3smbcn";
        };
    

    version = date of the last push and the r# is there in case of updates to dependencies.
    rev = last git commit.
    sha256 = checksum of the code download from github.

    When you make those edits, it will go ahead and compile all the things.
  • Here's an example - I just bumped p2gcc: https://github.com/redvers/parallax-tooling/commit/99d58997d34a4054151d0cc7babc6cdd7f7b58a7

    Here's how the upgrade looks (maybe I should write some simple shellscripts to make this easier?)
    nixdemo@ubuntut0:~$ cd .config/nixpkgs/overlays/parallax-tooling/
    nixdemo@ubuntut0:~/.config/nixpkgs/overlays/parallax-tooling$ git pull
    remote: Enumerating objects: 9, done.
    remote: Counting objects: 100% (9/9), done.
    remote: Compressing objects: 100% (2/2), done.
    remote: Total 5 (delta 2), reused 5 (delta 2), pack-reused 0
    Unpacking objects: 100% (5/5), done.
    From https://github.com/redvers/parallax-tooling
       dc64538..99d5899  master     -> origin/master
    Updating dc64538..99d5899
    Fast-forward
     pkgs/p2gcc/default.nix | 6 +++---
     1 file changed, 3 insertions(+), 3 deletions(-)
    nixdemo@ubuntut0:~/.config/nixpkgs/overlays/parallax-tooling$ cd
    

    Query the version updates:
    nixdemo@ubuntut0:~$ nix-env -qc
    cachix-0.1.3                = 0.1.3
    git-2.19.2                  = 2.19.2
    nix-2.2.1                   > 2.2pre6526_9f99d624
    p2gcc-2019-01-12r1          < 2019-01-13r0
    propeller-gcc-2018-04-14r1  = 2018-04-14r1
    

    Do the upgrade:
    nixdemo@ubuntut0:~$ nix-env -i p2gcc
    replacing old 'p2gcc-2019-01-12r1'
    installing 'p2gcc-2019-01-13r0'
    these paths will be fetched (0.08 MiB download, 0.37 MiB unpacked):
      /nix/store/gv64cmyf4xq86q87hnf0wrpad27aj0dp-p2gcc-2019-01-13r0
    copying path '/nix/store/gv64cmyf4xq86q87hnf0wrpad27aj0dp-p2gcc-2019-01-13r0' from 'https://redvers.cachix.org'...
    building '/nix/store/9shmrs9f7yxrq4avp5a5l1vj6papk6sl-user-environment.drv'...
    created 425 symlinks in user environment
    

    Done.
  • samuellsamuell Posts: 189
    edited 2019-01-17 - 01:55:08
    Hi,

    Is there any way to lean out the "/nix" directory? When I ran "nix-env -i p2gcc", it took a good time compiling (lots and lots of files) and that directory now takes up 2GB of space. It even compiled grep.

    Kind regards, Samuel Lourenço
Sign In or Register to comment.