P2 Tooling Installation via nix for AnyLinux™ (any Linux Distribution)
__red__
Posts: 470
Greetings.
tl;dr - if you want to go straight to installation - scroll down!
Update: see below for upgrade instructions...
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-02-09: POTENTIAL BREAKING CHANGE
2019-02-09: I have moved spin2sim (includes fastspin), openspin, and spinsim out of the propeller-gcc package as they were at fixed (and old) versions. To get those same tools, you need to install their separate packages. If you are upgrading from this point on, please upgrade propeller-gcc before installing the opensim, spin2cpp, and spinsim packages.
2019-01-24: Bumped p2gcc to 2019-01-23r1 (fcfed297ab9f63c050ee2c436bb9b74abdb4f0d0)
2019-01-19: Bumped p2gcc to 2019-01-18r0 and propeller-gcc to 2018-04-14r2
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
Testing
Write the following (simple) C program (foo.c):
Compile and test it in the simulator like this:
... and to run on the REAL hardware:
Upgrades
To upgrade, you need to update the overlay as follows:
As before, these files should be copied from cache and not locally compiled.
To remove the previous versions:
tl;dr - if you want to go straight to installation - scroll down!
Update: see below for upgrade instructions...
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-02-09: POTENTIAL BREAKING CHANGE
2019-02-09: I have moved spin2sim (includes fastspin), openspin, and spinsim out of the propeller-gcc package as they were at fixed (and old) versions. To get those same tools, you need to install their separate packages. If you are upgrading from this point on, please upgrade propeller-gcc before installing the opensim, spin2cpp, and spinsim packages.
2019-01-24: Bumped p2gcc to 2019-01-23r1 (fcfed297ab9f63c050ee2c436bb9b74abdb4f0d0)
2019-01-19: Bumped p2gcc to 2019-01-18r0 and propeller-gcc to 2018-04-14r2
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
Upgrades
To upgrade, you need to update the overlay as follows:
cd ~/.config/nixpkgs/overlays/parallax-tooling git pull nix-env -i propeller-gcc nix-env -i p2gcc
As before, these files should be copied from cache and not locally compiled.
To remove the previous versions:
nix-collect-garbage
Comments
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.
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 = 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 how the upgrade looks (maybe I should write some simple shellscripts to make this easier?)
Query the version updates:
Do the upgrade:
Done.
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
yes:
This I'm really curious about because you should have been able to pull everything from cache.
What hardware / OS are you running?
Thanks,
Red
Agreed - it shouldn't be anywhere near that size.
Sure, but like I said his machine shouldn't be compiling anything as all of the package definitions he's using should be in cache.
Answering to your question, I'm using a VM with Kubuntu 18.04 LTS, 64bit. The VM manager is VirtualBox. However, since my virtual RAM was limited to 2GB, the "nix-env -i p2gcc" step failed. I had to extend the RAM to 4GB temporarily and try again.
Kind regards, Samuel Lourenço
I'm going to set up the same VM here and test this - I can't think of any reason why it would force a compilation.
I'll let you know if I can replicate.
Thanks,
Red
EDIT: It's installing now...
(it's actually propeller-gcc which is a dependency of p2gcc that's causing the issue - I'll know why shortly).
I shall return!
Kind regards, Samuel Lourenço
Okey-dokey,
Nuke your /nix directory from orbit and:
I'm not entirely sure why this build differs but I'm going to find out. This should get you moving in the meantime.
Thanks,
Red
I just bumped it due to changes in p2gcc to include these changes:
The terminal still asks for and accepts ESC, although now it seems to accept Ctrl+] as well.
Kind regards, Samuel Lourenço
I am currently re-factoring the propeller-gcc package to remove openspin, spinsim, and spin2cpp from it. The reason being that the propeller-gcc package has old versions tagged and, as a user you may want to run more recent versions.
When the work is completed I'll add full docs above.
Update the overlay:
Update propeller-gcc:
Update p2gcc:
Update spin2cpp: