├── arm-baremetal.nix ├── bar.c ├── bar.h ├── bare-env.nix ├── bare-env.txt ├── brcmfmac4356 ├── brcmfmac4356-pcie.nix └── brcmfmac4356-pcie.txt ├── bridged-container └── configuration.nix ├── config-debug.nix ├── container-generator ├── configuration.nix ├── container-helper.nix └── default.nix ├── cross-compiled-kernel.nix ├── disk-image-tests.nix ├── efi-notes.md ├── example.nix ├── foo.c ├── fs-test └── configuration.nix ├── haskell-init ├── flake.nix └── hello_world.hs ├── install-helper ├── configuration.nix └── default.nix ├── ip-magic ├── core.nix ├── reverse-generator.cpp └── test.nix ├── kexec ├── LICENSE.md ├── README.md ├── autoreboot.nix ├── configuration.nix ├── dummy.nix ├── justdoit.nix ├── kexec.nix ├── nixops-example.nix ├── session.md ├── simple-test.nix ├── target-config.nix ├── test.nix └── vbox-tips.md ├── make.nix ├── module-example ├── default.nix ├── example.nix ├── expr.nix ├── expr2.nix └── usage.md ├── nix-tests.sublime-workspace ├── nix-tracker ├── default.nix ├── main.cpp ├── others.md └── setup.md ├── placeholder.nix ├── qemu └── default.nix ├── scopedImport ├── float1.nix ├── float2.nix └── float3.nix ├── self-reference ├── self-reference.nix └── self-reference.txt └── zed └── configuration.nix /arm-baremetal.nix: -------------------------------------------------------------------------------- 1 | { arch ? "arm-none-eabi" }: 2 | # known to compile: 3 | # arm-none-eabi 4 | # mipsel-unknown-linux-gnu 5 | let 6 | cross = { 7 | config = arch; 8 | libc = null; 9 | }; 10 | pkgs = import { crossSystem = cross; }; 11 | in pkgs.buildEnv { 12 | name = "arm-baremetal"; 13 | paths = [ pkgs.binutilsCross pkgs.gccCrossStageStatic ]; 14 | } -------------------------------------------------------------------------------- /bar.c: -------------------------------------------------------------------------------- 1 | int bar() { return 42; } -------------------------------------------------------------------------------- /bar.h: -------------------------------------------------------------------------------- 1 | int bar(); -------------------------------------------------------------------------------- /bare-env.nix: -------------------------------------------------------------------------------- 1 | with import {}; 2 | 3 | builtins.derivation { 4 | system = builtins.currentSystem; 5 | name = "bare-env"; 6 | builder = stdenv.shell; 7 | args = [ (writeText "builder.sh" '' 8 | ${procps}/bin/ps -eH ux 9 | ${coreutils}/bin/env 10 | ${coreutils}/bin/id 11 | ${coreutils}/bin/cat /proc/mounts 12 | '') ]; 13 | } 14 | -------------------------------------------------------------------------------- /bare-env.txt: -------------------------------------------------------------------------------- 1 | these derivations will be built: 2 | /nix/store/54hhl8yj96j0s8262pxgp4xy4127qcql-builder.sh.drv 3 | /nix/store/fspmycgdmkqcd3p4lxr9n7cmcd771lpf-bare-env.drv 4 | building path(s) ‘/nix/store/b8kvgs6qc8zvz0jvbi2jrxfmcwbgdmni-builder.sh’ 5 | building path(s) ‘/nix/store/zpffs7k4qmbdg1a8y1prwwnn7srfv9r6-bare-env’ 6 | USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND 7 | nixbld 1 0.0 0.0 15336 1868 ? Ss 16:49 0:00 bash /nix/store/b8kvgs6qc8zvz0jvbi2jrxfmcwbgdmni-builder.sh 8 | nixbld 2 0.0 0.0 17484 1508 ? R 16:49 0:00 /nix/store/11vm819wkw83fn0c3q1hpgfidcgndy01-procps-3.3.11/bin/ps -eH ux 9 | TMPDIR=/tmp/nix-build-bare-env.drv-0 10 | builder=/nix/store/cjsvvfvx39bs4qj097j253c8mb75cpw6-bash-4.3-p46/bin/bash 11 | name=bare-env 12 | TEMP=/tmp/nix-build-bare-env.drv-0 13 | NIX_STORE=/nix/store 14 | system=x86_64-linux 15 | PATH=/path-not-set 16 | TEMPDIR=/tmp/nix-build-bare-env.drv-0 17 | NIX_BUILD_TOP=/tmp/nix-build-bare-env.drv-0 18 | PWD=/tmp/nix-build-bare-env.drv-0 19 | out=/nix/store/zpffs7k4qmbdg1a8y1prwwnn7srfv9r6-bare-env 20 | SHLVL=1 21 | HOME=/homeless-shelter 22 | TMP=/tmp/nix-build-bare-env.drv-0 23 | NIX_BUILD_CORES=7 24 | _=/nix/store/nwq2mdczlhs3hcrdkbw131kkyaxyknn1-coreutils-8.25/bin/env 25 | uid=30001(nixbld) gid=30000(nixbld) groups=30000(nixbld) 26 | amd/nix / zfs rw,relatime,xattr,noacl 0 0 27 | amd/nix /bin/sh zfs rw,relatime,xattr,noacl 0 0 28 | devtmpfs /dev/full devtmpfs rw,nosuid,size=816668k,nr_inodes=2040244,mode=755 0 0 29 | devtmpfs /dev/kvm devtmpfs rw,nosuid,size=816668k,nr_inodes=2040244,mode=755 0 0 30 | devtmpfs /dev/null devtmpfs rw,nosuid,size=816668k,nr_inodes=2040244,mode=755 0 0 31 | devtmpfs /dev/random devtmpfs rw,nosuid,size=816668k,nr_inodes=2040244,mode=755 0 0 32 | devtmpfs /dev/tty devtmpfs rw,nosuid,size=816668k,nr_inodes=2040244,mode=755 0 0 33 | devtmpfs /dev/urandom devtmpfs rw,nosuid,size=816668k,nr_inodes=2040244,mode=755 0 0 34 | devtmpfs /dev/zero devtmpfs rw,nosuid,size=816668k,nr_inodes=2040244,mode=755 0 0 35 | amd/nix /nix/store/11vm819wkw83fn0c3q1hpgfidcgndy01-procps-3.3.11 zfs rw,relatime,xattr,noacl 0 0 36 | amd/nix /nix/store/1jwkjzrivp541v5ibgzb4wc2avla5zx9-glibc-2.24 zfs rw,relatime,xattr,noacl 0 0 37 | amd/nix /nix/store/22lsciby58xfsajvn3pxmlpx5pcivi00-attr-2.4.47 zfs rw,relatime,xattr,noacl 0 0 38 | amd/nix /nix/store/amy9x080xy87qhk0812h46r6p14d1n7h-acl-2.2.52 zfs rw,relatime,xattr,noacl 0 0 39 | amd/nix /nix/store/cjsvvfvx39bs4qj097j253c8mb75cpw6-bash-4.3-p46 zfs rw,relatime,xattr,noacl 0 0 40 | amd/nix /nix/store/hfwd34bvdj9hx5lkhb51xim4nx5brbba-ncurses-6.0 zfs rw,relatime,xattr,noacl 0 0 41 | amd/nix /nix/store/nwq2mdczlhs3hcrdkbw131kkyaxyknn1-coreutils-8.25 zfs rw,relatime,xattr,noacl 0 0 42 | amd/root /tmp/nix-build-bare-env.drv-0 zfs rw,relatime,xattr,noacl 0 0 43 | none /proc proc rw,relatime 0 0 44 | none /dev/shm tmpfs rw,relatime 0 0 45 | none /dev/pts devpts rw,relatime,mode=620,ptmxmode=000 0 0 46 | builder for ‘/nix/store/fspmycgdmkqcd3p4lxr9n7cmcd771lpf-bare-env.drv’ failed to produce output path ‘/nix/store/zpffs7k4qmbdg1a8y1prwwnn7srfv9r6-bare-env’ 47 | error: build of ‘/nix/store/fspmycgdmkqcd3p4lxr9n7cmcd771lpf-bare-env.drv’ failed 48 | -------------------------------------------------------------------------------- /brcmfmac4356/brcmfmac4356-pcie.nix: -------------------------------------------------------------------------------- 1 | { pkgs, ... }: 2 | 3 | let 4 | dummy_firmware = pkgs.writeTextFile { 5 | name = "brcmfmac4356-pcie.txt"; 6 | text = builtins.readFile ./brcmfmac4356-pcie.txt; 7 | destination = "/lib/firmware/brcm/brcmfmac4356-pcie.txt"; 8 | }; 9 | in { 10 | hardware.firmware = [ dummy_firmware ]; 11 | } 12 | -------------------------------------------------------------------------------- /brcmfmac4356/brcmfmac4356-pcie.txt: -------------------------------------------------------------------------------- 1 | # Sample variables file for BCM94356Z NGFF 22x30mm iPA, iLNA board with PCIe for production package 2 | NVRAMRev=$Rev: 492104 $ 3 | #4356 chip = 4354 A2 chip 4 | sromrev=11 5 | boardrev=0x1102 6 | boardtype=0x073e 7 | boardflags=0x02400201 8 | #0x2000 enable 2G spur WAR 9 | boardflags2=0x00802000 10 | boardflags3=0x0000000a 11 | #boardflags3 0x00000100 /* to read swctrlmap from nvram*/ 12 | #define BFL3_5G_SPUR_WAR 0x00080000 /* enable spur WAR in 5G band */ 13 | #define BFL3_AvVim 0x40000000 /* load AvVim from nvram */ 14 | macaddr=00:90:4c:1a:10:01 15 | ccode=0x5854 16 | regrev=205 17 | antswitch=0 18 | pdgain5g=4 19 | pdgain2g=4 20 | tworangetssi2g=0 21 | tworangetssi5g=0 22 | paprdis=0 23 | femctrl=10 24 | vendid=0x14e4 25 | devid=0x43ec 26 | manfid=0x2d0 27 | #prodid=0x052e 28 | nocrc=1 29 | otpimagesize=502 30 | xtalfreq=37400 31 | rxgains2gelnagaina0=0 32 | rxgains2gtrisoa0=7 33 | rxgains2gtrelnabypa0=0 34 | rxgains5gelnagaina0=0 35 | rxgains5gtrisoa0=11 36 | rxgains5gtrelnabypa0=0 37 | rxgains5gmelnagaina0=0 38 | rxgains5gmtrisoa0=13 39 | rxgains5gmtrelnabypa0=0 40 | rxgains5ghelnagaina0=0 41 | rxgains5ghtrisoa0=12 42 | rxgains5ghtrelnabypa0=0 43 | rxgains2gelnagaina1=0 44 | rxgains2gtrisoa1=7 45 | rxgains2gtrelnabypa1=0 46 | rxgains5gelnagaina1=0 47 | rxgains5gtrisoa1=10 48 | rxgains5gtrelnabypa1=0 49 | rxgains5gmelnagaina1=0 50 | rxgains5gmtrisoa1=11 51 | rxgains5gmtrelnabypa1=0 52 | rxgains5ghelnagaina1=0 53 | rxgains5ghtrisoa1=11 54 | rxgains5ghtrelnabypa1=0 55 | rxchain=3 56 | txchain=3 57 | aa2g=3 58 | aa5g=3 59 | agbg0=2 60 | agbg1=2 61 | aga0=2 62 | aga1=2 63 | tssipos2g=1 64 | extpagain2g=2 65 | tssipos5g=1 66 | extpagain5g=2 67 | tempthresh=255 68 | tempoffset=255 69 | rawtempsense=0x1ff 70 | pa2ga0=-147,6192,-705 71 | pa2ga1=-161,6041,-701 72 | pa5ga0=-194,6069,-739,-188,6137,-743,-185,5931,-725,-171,5898,-715 73 | pa5ga1=-190,6248,-757,-190,6275,-759,-190,6225,-757,-184,6131,-746 74 | subband5gver=0x4 75 | pdoffsetcckma0=0x4 76 | pdoffsetcckma1=0x4 77 | pdoffset40ma0=0x0000 78 | pdoffset80ma0=0x0000 79 | pdoffset40ma1=0x0000 80 | pdoffset80ma1=0x0000 81 | maxp2ga0=76 82 | maxp5ga0=74,74,74,74 83 | maxp2ga1=76 84 | maxp5ga1=74,74,74,74 85 | cckbw202gpo=0x0000 86 | cckbw20ul2gpo=0x0000 87 | mcsbw202gpo=0x99644422 88 | mcsbw402gpo=0x99644422 89 | dot11agofdmhrbw202gpo=0x6666 90 | ofdmlrbw202gpo=0x0022 91 | mcsbw205glpo=0x88766663 92 | mcsbw405glpo=0x88666663 93 | mcsbw805glpo=0xbb666665 94 | mcsbw205gmpo=0xd8666663 95 | mcsbw405gmpo=0x88666663 96 | mcsbw805gmpo=0xcc666665 97 | mcsbw205ghpo=0xdc666663 98 | mcsbw405ghpo=0xaa666663 99 | mcsbw805ghpo=0xdd666665 100 | mcslr5glpo=0x0000 101 | mcslr5gmpo=0x0000 102 | mcslr5ghpo=0x0000 103 | sb20in40hrpo=0x0 104 | sb20in80and160hr5glpo=0x0 105 | sb40and80hr5glpo=0x0 106 | sb20in80and160hr5gmpo=0x0 107 | sb40and80hr5gmpo=0x0 108 | sb20in80and160hr5ghpo=0x0 109 | sb40and80hr5ghpo=0x0 110 | sb20in40lrpo=0x0 111 | sb20in80and160lr5glpo=0x0 112 | sb40and80lr5glpo=0x0 113 | sb20in80and160lr5gmpo=0x0 114 | sb40and80lr5gmpo=0x0 115 | sb20in80and160lr5ghpo=0x0 116 | sb40and80lr5ghpo=0x0 117 | dot11agduphrpo=0x0 118 | dot11agduplrpo=0x0 119 | phycal_tempdelta=255 120 | temps_period=15 121 | temps_hysteresis=15 122 | rssicorrnorm_c0=4,4 123 | rssicorrnorm_c1=4,4 124 | rssicorrnorm5g_c0=1,2,3,1,2,3,6,6,8,6,6,8 125 | rssicorrnorm5g_c1=1,2,3,2,2,2,7,7,8,7,7,8 126 | -------------------------------------------------------------------------------- /bridged-container/configuration.nix: -------------------------------------------------------------------------------- 1 | # nixos-rebuild build-vm -I nixos-config=./configuration.nix -Q -j 8 2 | { pkgs, ... }: 3 | 4 | { 5 | environment.systemPackages = with pkgs; [ screen tcpdump ]; 6 | containers.test1 = { 7 | autoStart = true; 8 | hostBridge = "br0"; 9 | privateNetwork = true; 10 | localAddress = "10.0.2.16/24"; 11 | config = { ... }: { 12 | networking.hostName = "test1"; 13 | }; 14 | }; 15 | networking.bridges.br0.interfaces = [ "eth0" ]; 16 | networking.hostName = "host"; 17 | users.users.root.initialPassword = "root"; 18 | } 19 | -------------------------------------------------------------------------------- /config-debug.nix: -------------------------------------------------------------------------------- 1 | { 2 | packageOverrides = pkgs: { 3 | stdenv = pkgs.stdenv // { 4 | mkDerivation = args: pkgs.stdenv.mkDerivation (args // { 5 | NIX_CFLAGS_COMPILE = (toString args.NIX_CFLAGS_COMPILE or "") + "-g"; 6 | }); 7 | }; 8 | }; 9 | } -------------------------------------------------------------------------------- /container-generator/configuration.nix: -------------------------------------------------------------------------------- 1 | { ... }: 2 | 3 | { 4 | imports = [ ./container-helper.nix ]; 5 | networking.hostName = "guest"; 6 | } 7 | -------------------------------------------------------------------------------- /container-generator/container-helper.nix: -------------------------------------------------------------------------------- 1 | { pkgs, config, ... }: 2 | 3 | let 4 | bootScript = pkgs.writeScript "boot" '' 5 | #!/bin/sh 6 | unshare -m .${createMountsScript} 7 | ''; 8 | createMountsScript = pkgs.writeScript "createMounts" '' 9 | #!/bin/sh 10 | mkdir -p proc dev 11 | mount --bind /proc proc/ 12 | mount -t tmpfs tmpfs dev/ 13 | mkdir -p etc 14 | touch etc/resolv.conf 15 | mount --bind /etc/resolv.conf etc/resolv.conf 16 | 17 | cd dev 18 | mknod null c 1 3 19 | mknod zero c 1 5 20 | mknod full c 1 7 21 | mknod random c 1 8 22 | mknod urandom c 1 9 23 | mknod tty c 5 0 24 | mkdir net 25 | mknod net/tun c 10 200 26 | cd .. 27 | 28 | export LC_ALL="C" 29 | chroot . ${unshareNonMountScript} 30 | ''; 31 | unshareNonMountScript = pkgs.writeScript "unshareNonMount" '' 32 | #!${pkgs.stdenv.shell} --noprofile 33 | export PATH=${config.system.path}/bin 34 | unshare -i -p -u ${launchInitScript} 35 | ''; 36 | launchInitScript = pkgs.writeScript "launchInit" '' 37 | #!${pkgs.stdenv.shell} --noprofile 38 | set -m 39 | ${initScript} & 40 | echo $! > /pid 41 | fg 1 42 | ''; 43 | initScript = pkgs.writeScript "initScript" '' 44 | #!${pkgs.stdenv.shell} 45 | mount -t proc proc /proc 46 | if [ -f /nix/var/nix/profiles/system/init ]; then 47 | exec /nix/var/nix/profiles/system/init 48 | else 49 | exec /init 50 | fi 51 | ''; 52 | enterScript = pkgs.writeScript "enter" '' 53 | #!/bin/sh 54 | exec nsenter -t $(cat ./pid) -m -u -i -p -r -w ${pkgs.bashInteractive}/bin/bash 55 | ''; 56 | tarball = pkgs.callPackage { 57 | storeContents = [ 58 | { object = "${config.system.build.toplevel}/init"; symlink = "/init"; } 59 | { object = "${pkgs.bashInteractive}/bin/bash"; symlink = "/bash"; } 60 | { object = enterScript; symlink = "/enter"; } 61 | ]; 62 | contents = [ 63 | { source = bootScript; target = "/boot"; } 64 | ]; 65 | }; 66 | in { 67 | system.build = { 68 | inherit bootScript createMountsScript unshareNonMountScript launchInitScript initScript enterScript tarball; 69 | }; 70 | system.extraSystemBuilderCmds = '' 71 | cp ${bootScript} $out/boot 72 | cp ${enterScript} $out/enter 73 | ''; 74 | boot.isContainer = true; 75 | networking.dhcpcd.enable = false; 76 | networking.firewall.enable = false; 77 | boot.postBootCommands = '' 78 | # After booting, register the contents of the Nix store on the 79 | # CD in the Nix database in the tmpfs. 80 | if [ -f /nix-path-registration ]; then 81 | ${config.nix.package.out}/bin/nix-store --load-db < /nix-path-registration && 82 | rm /nix-path-registration 83 | fi 84 | 85 | # nixos-rebuild also requires a "system" profile and an 86 | # /etc/NIXOS tag. 87 | touch /etc/NIXOS 88 | ${config.nix.package.out}/bin/nix-env -p /nix/var/nix/profiles/system --set /run/current-system 89 | rm /boot /enter /init 90 | cp -v /nix/var/nix/profiles/system/boot /boot 91 | cp -v /nix/var/nix/profiles/system/enter /enter 92 | ln -sv ./nix/var/nix/profiles/system/init init 93 | mkdir -pv /etc/nixos/ 94 | if [ ! -f /etc/nixos/configuration.nix ]; then 95 | cp ${./configuration.nix} /etc/nixos/configuration.nix 96 | fi 97 | if [ ! -f /etc/nixos/container-helper.nix ]; then 98 | cp ${./container-helper.nix} /etc/nixos/container-helper.nix 99 | fi 100 | 101 | # Reread host resolv.conf from backup 102 | resolvconf -m 10000 -a host < /etc/resolv.conf.bak 103 | ''; 104 | } 105 | -------------------------------------------------------------------------------- /container-generator/default.nix: -------------------------------------------------------------------------------- 1 | let 2 | eval = import { configuration = ./configuration.nix; }; 3 | pkgs = eval.config._module.args.pkgs; 4 | in rec { 5 | tarball = eval.config.system.build.tarball; 6 | cfg = { ... }: { 7 | services.mingetty.autologinUser = "root"; 8 | virtualisation.memorySize = 2048; 9 | services.xserver = { 10 | enable = true; 11 | displayManager.slim = { 12 | enable = true; 13 | autoLogin = true; 14 | defaultUser = "root"; 15 | }; 16 | desktopManager.xfce.enable = true; 17 | }; 18 | networking.hostName = "host"; 19 | environment.systemPackages = [ ( 20 | pkgs.writeScriptBin "doit" '' 21 | cd /root 22 | mkdir -p t 23 | mount -t tmpfs none /root/t -o size=2048m 24 | cd t 25 | tar -xf ${eval.config.system.build.tarball}/tarball/nixos-system-x86_64-linux.tar.xz 26 | '' 27 | ) ]; 28 | }; 29 | test-guest = (import { configuration = cfg; }).vm; 30 | } 31 | -------------------------------------------------------------------------------- /cross-compiled-kernel.nix: -------------------------------------------------------------------------------- 1 | # export NIX_LDFLAGS="${NIX_LDFLAGS} -lncurses" 2 | # make bcm2709_defconfig 3 | # make gconfig 4 | # time make CROSS_COMPILE=arm-none-eabi- -j 8 5 | 6 | with import {}; 7 | let 8 | pkgs2 = import { 9 | crossSystem = { 10 | config = "arm-none-eabi"; 11 | libc = null; 12 | }; 13 | }; 14 | in runCommand "kernel" { 15 | buildInputs = [ pkgs2.binutilsCross pkgs2.gccCrossStageStatic gcc ncurses pkgconfig gtk2 glib gnome2.libglade bc ]; 16 | ARCH = "arm"; 17 | } "" 18 | -------------------------------------------------------------------------------- /disk-image-tests.nix: -------------------------------------------------------------------------------- 1 | # build with one of: 2 | # * nix-build '' -I nixos-config=./disk-image-tests.nix -A config.system.build.ext4 3 | # * nix-build '' -I nixos-config=./disk-image-tests.nix -A config.system.build.tarball 4 | 5 | { config, pkgs, ... }: 6 | 7 | { 8 | boot.loader.grub.enable = false; 9 | fileSystems = { 10 | "/" = { 11 | label = "NIXOS_ROOT"; 12 | }; 13 | }; 14 | boot.postBootCommands = '' 15 | if [ -f /nix-path-registration ]; then 16 | ${config.nix.package.out}/bin/nix-store --load-db < /nix-path-registration && rm /nix-path-registration 17 | fi 18 | ${config.nix.package.out}/bin/nix-env -p /nix/var/nix/profiles/system --set /run/current-system 19 | 20 | # resize the ext4 image to occupy the full partition 21 | rootPart=$(readlink -f /dev/disk/by-label/NIXOS_ROOT) 22 | ${pkgs.e2fsprogs}/bin/resize2fs $rootPart 23 | ''; 24 | system.activationScripts.installInitScript = '' 25 | ln -fs $systemConfig/init /bin/init 26 | ''; 27 | system.build = { 28 | # a tarball you can unpack to / 29 | tarball = pkgs.callPackage (pkgs.path + "/nixos/lib/make-system-tarball.nix") { 30 | storeContents = [ { 31 | object = "${config.system.build.toplevel}/init"; 32 | symlink = "/bin/init"; 33 | } ]; 34 | contents = []; 35 | }; 36 | # an FS you can mount to / 37 | # note, you will need to make a symlink to the right init yourself or use init=/nix/store/foo/init 38 | ext4 = pkgs.callPackage (pkgs.path + "/nixos/lib/make-ext4-fs.nix") { 39 | volumeLabel = "NIXOS_ROOT"; 40 | storePaths = [ config.system.build.toplevel ]; 41 | }; 42 | }; 43 | } 44 | -------------------------------------------------------------------------------- /efi-notes.md: -------------------------------------------------------------------------------- 1 | how to install nixos from legacy booting 2 | 3 | first, boot via legacy, and install with the following options 4 | 5 | ```nix 6 | boot.loader.grub.efiSupport = true; 7 | boot.loader.grub.efiInstallAsRemovable = true; 8 | boot.loader.grub.device = "nodev"; 9 | ``` 10 | 11 | then boot that via EFI, and change the config 12 | 13 | ```nix 14 | boot.loader.grub.efiInstallAsRemovable = false; 15 | boot.loader.efi.canTouchEfiVariables = true; 16 | ``` 17 | 18 | then ``NIXOS_INSTALL_BOOTLOADER=1 nixos-rebuild switch`` and confirm nixos is listed in ``efibootmgr``, then you can safely delete /boot/EFI/BOOT/BOOTX64.EFI 19 | -------------------------------------------------------------------------------- /example.nix: -------------------------------------------------------------------------------- 1 | { pkgs, lib, config, ... }: 2 | 3 | { 4 | system.build.example = import { 5 | inherit pkgs lib config; 6 | partitioned = true; 7 | diskSize = 2 * 1024; 8 | }; 9 | fileSystems."/".device = "/dev/disk/by-label/nixos"; 10 | boot.loader.grub.device = "/dev/vda"; 11 | services.xserver = { 12 | displayManager.slim.enable = true; 13 | desktopManager.xfce.enable = true; 14 | enable = true; 15 | }; 16 | boot.plymouth.enable = true; 17 | users.users.root.initialPassword = "root"; 18 | } -------------------------------------------------------------------------------- /foo.c: -------------------------------------------------------------------------------- 1 | #include "bar.h" 2 | 3 | int main(int argc, char **argv) { 4 | return bar(); 5 | } -------------------------------------------------------------------------------- /fs-test/configuration.nix: -------------------------------------------------------------------------------- 1 | { ... }: 2 | 3 | let 4 | pool = "tank"; 5 | volumes = [ "/nix" "/home" ]; 6 | in { 7 | boot.loader.grub.device = "/dev/sda"; 8 | fileSystems = [ 9 | { device = "/dev/sda1"; mountPoint = "/data"; fsType = "xfs"; } 10 | { device = "${pool}/root"; mountPoint = "/"; fsType = "zfs"; } 11 | ] ++ (map (v: { device = "${pool}${v}"; mountPoint = v; fsType = "zfs"; }) volumes); 12 | networking.hostId = "fe1f6cbf"; 13 | } 14 | -------------------------------------------------------------------------------- /haskell-init/flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | outputs = { self, nixpkgs }: 3 | let 4 | pkgs = (import nixpkgs { system = "x86_64-linux"; }); 5 | in { 6 | packages.x86_64-linux = pkgs.lib.fix (s: { 7 | ghc = pkgs.pkgsCross.musl64.haskellPackages.ghcWithPackages (p: with p; [ directory split transformers mtl linux-mount ] ); 8 | hello_world = pkgs.stdenv.mkDerivation { 9 | name = "hello_world"; 10 | nativeBuildInputs = with pkgs; [ 11 | s.ghc 12 | #(import {}).llvm 13 | #(import {}).strace 14 | ]; 15 | buildInputs = with pkgs; [ pkgs.libffi pkgs.gmp ]; 16 | unpackPhase = '' 17 | cp ${./hello_world.hs} hello_world.hs 18 | ''; 19 | installPhase = '' 20 | mkdir -p $out/bin 21 | #{pkgs.pkgsCross.musl64.ghc.targetPrefix}ghc 22 | x86_64-unknown-linux-musl-ghc hello_world.hs -static -split-sections -o $out/bin/init 23 | $STRIP $out/bin/init 24 | ''; 25 | }; 26 | hello_world' = pkgs.runCommand "hello_world2" {} ''cp ${s.hello_world}/bin/init $out''; 27 | initrd = pkgs.makeInitrd { 28 | contents = [ 29 | { 30 | object = s.hello_world'; 31 | symlink = "/init"; 32 | } 33 | ]; 34 | }; 35 | tester = pkgs.writeScript "tester" '' 36 | #!${pkgs.stdenv.shell} 37 | export PATH=${pkgs.coreutils}/bin/:${pkgs.utillinux}/bin/ 38 | mount -v -t proc proc proc 39 | ls -l /proc/self/fd/ 40 | #${pkgs.strace}/bin/strace -f ${s.hello_world}/bin/init 41 | ''; 42 | kernel = pkgs.linuxPackages.kernel; 43 | script = pkgs.writeScriptBin "script" '' 44 | #!${pkgs.stdenv.shell} 45 | ${pkgs.qemu}/bin/qemu-system-x86_64 -kernel ${s.kernel}/bzImage -initrd ${s.initrd}/initrd -m 512 -append "console=ttyS0 quiet" 46 | #-nographic -serial mon:stdio 47 | ''; 48 | }); 49 | defaultPackage.x86_64-linux = self.packages.x86_64-linux.script; 50 | }; 51 | } 52 | -------------------------------------------------------------------------------- /haskell-init/hello_world.hs: -------------------------------------------------------------------------------- 1 | {-# LANGUAGE LambdaCase #-} 2 | 3 | module Main where 4 | import Control.Concurrent (threadDelay) 5 | import Control.Monad (forever) 6 | import System.Posix.Directory 7 | import System.Directory 8 | import Data.Char 9 | import Data.List.Split 10 | import Control.Monad.State 11 | import System.Linux.Mount 12 | 13 | data AppState = AppState { running :: Bool } deriving (Eq, Show, Read) 14 | 15 | ls :: String -> IO () 16 | ls arg1 = mapM_ print =<< getDirectoryContents arg1 17 | 18 | type Repl = StateT AppState IO 19 | 20 | keepRunning :: Bool -> Repl () 21 | keepRunning b = modify $ \m -> m { running = b } 22 | 23 | eval :: [String] -> Repl () 24 | eval ("ls" : arg1 : rest) = do 25 | liftIO $ ls arg1 26 | eval ("ls" : rest) = do 27 | liftIO $ ls "." 28 | eval ("quit":rest) = do 29 | keepRunning False 30 | eval _ = do 31 | liftIO $ putStrLn "unknown command" 32 | 33 | defaultMain :: Repl () -> IO () 34 | defaultMain repl = do 35 | mount "devtmpfs" "/dev" "devtmpfs" [] noData 36 | mount "proc" "/proc" "proc" [] noData 37 | mount "sysfs" "/sys" "sysfs" [] noData 38 | putStrLn "booted" 39 | flip evalStateT initialState repl 40 | where 41 | initialState = AppState True 42 | 43 | main = defaultMain $ fix $ \loop -> 44 | running <$> get >>= \case 45 | False -> liftIO $ putStrLn "Exiting" 46 | True -> do 47 | liftIO $ putStr "> " 48 | line <- splitOn " " <$> liftIO getLine 49 | eval line >> loop 50 | -------------------------------------------------------------------------------- /install-helper/configuration.nix: -------------------------------------------------------------------------------- 1 | { pkgs, lib, ... }: 2 | 3 | with lib; 4 | 5 | { 6 | imports = [ ]; 7 | environment.systemPackages = with pkgs; [ teamspeak_client ]; 8 | services = { 9 | xserver.autorun = mkOverride 49 true; 10 | toxvpn = { 11 | enable = true; 12 | localip = "192.168.123.45"; 13 | auto_peers = [ "dd51f5f444b63c9c6d58ecf0637ce4c161fe776c86dc717b2e209bc686e56a5d2227dfee1338" ]; 14 | }; 15 | }; 16 | environment.etc."wpa_supplicant.conf".text = '' 17 | network={ 18 | ssid="network name" 19 | psk="network password" 20 | } 21 | ''; 22 | networking.wireless.enable = true; 23 | nixpkgs = { 24 | config = { 25 | allowUnfree = true; 26 | }; 27 | }; 28 | } 29 | -------------------------------------------------------------------------------- /install-helper/default.nix: -------------------------------------------------------------------------------- 1 | let 2 | eval = import { configuration = ./configuration.nix; }; 3 | in eval.config 4 | -------------------------------------------------------------------------------- /ip-magic/core.nix: -------------------------------------------------------------------------------- 1 | { pkgs }: 2 | 3 | with pkgs.lib; 4 | 5 | rec { 6 | forward_header = '' 7 | $TTL 3D 8 | @ IN SOA ns.localnet. hostmaster (1 8H 2H 4W 1D) 9 | NS ns.localnet. 10 | ''; 11 | reverse_header = '' 12 | $TTL 3D 13 | @ IN SOA ns.localnet. hostmaster (1 8H 2H 4W 1D) 14 | ''; 15 | create_forward = hosts: pkgs.writeText "dns.forward" (forward_header + (concatMapStringsSep "\n" 16 | (h: 17 | concatStringsSep "\n" ( 18 | (optional (h ? v6) "${h.name} IN AAAA ${h.v6}") ++ 19 | (optional (h ? v4) "${h.name} IN A ${h.v4}") 20 | ) 21 | ) hosts)); 22 | reverse-generator = pkgs.runCommandCC "reverse-generator" { buildInputs = [ pkgs.jsoncpp ]; } '' 23 | mkdir -p $out/bin 24 | g++ ${./reverse-generator.cpp} -o $out/bin/reverse-generator -Wall -ljsoncpp 25 | ''; 26 | create_reverse = hosts: domain: pkgs.runCommand "dns.reverse" { buildInputs = [ reverse-generator ]; } '' 27 | cat ${pkgs.writeText "header.rev" reverse_header} > $out 28 | reverse-generator '${builtins.toJSON hosts}' ${domain} >> $out 29 | ''; 30 | } -------------------------------------------------------------------------------- /ip-magic/reverse-generator.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | int main(int argc, char **argv) { 10 | assert(argc == 3); 11 | Json::Reader reader; 12 | Json::Value root; 13 | string domain = argv[2]; 14 | if (!reader.parse(argv[1], root)) { 15 | cerr << "unable to parse json\n"; 16 | return 1; 17 | } 18 | assert(root.isArray()); 19 | for (unsigned int i=0; i= 0; x--) { 26 | printf("%x.%x.", result.s6_addr[x] & 0xf, result.s6_addr[x] >> 4); 27 | } 28 | cout << "ip6.arpa. IN PTR " << host["name"].asString() << "." << domain << "\n"; 29 | } else { 30 | cerr << "unable to parse '" << host["v6"].asString() << "' as a valid IPv6 addr\n"; 31 | return 2; 32 | } 33 | } 34 | if (host.isMember("v4")) { 35 | unsigned char buf[4]; 36 | if (inet_pton(AF_INET, host["v4"].asCString(), &buf) == 1) { 37 | for (int x = 3; x >= 0; x--) { 38 | printf("%d.", buf[x]); 39 | } 40 | cout << "in-addr.arpa. IN PTR " << host["name"].asString() << "." << domain << "\n"; 41 | } else { 42 | cerr << "unable to parse '" << host["v4"].asString() << "' as a valid IPv4 addr\n"; 43 | return 3; 44 | } 45 | } 46 | } 47 | return 0; 48 | } -------------------------------------------------------------------------------- /ip-magic/test.nix: -------------------------------------------------------------------------------- 1 | with import {}; 2 | 3 | rec { 4 | core = import ./core.nix { inherit pkgs; }; 5 | sample_hosts = [ 6 | { name="host1"; mac="11:22:33:44:55:66"; v4 = "192.168.3.10"; v6 = "2001:db8:85a3::8a2e:370:7334"; } 7 | { name="host2"; mac="11:22:33:44:55:77"; v4 = "192.168.3.11"; v6 = "2001:db8:85a3::8a2e:370:7335"; } 8 | { name="host3"; mac="11:22:33:44:55:88"; v4 = "192.168.3.12"; } 9 | { name="host4"; mac="11:22:33:44:55:99"; v6 = "2001:db8:85a3::8a2e:370:7336"; } 10 | ]; 11 | dns.forward = core.create_forward sample_hosts; 12 | dns.reverse = core.create_reverse sample_hosts "localnet."; 13 | } -------------------------------------------------------------------------------- /kexec/LICENSE.md: -------------------------------------------------------------------------------- 1 | Apache License 2 | ============== 3 | 4 | _Version 2.0, January 2004_ 5 | _<>_ 6 | 7 | ### Terms and Conditions for use, reproduction, and distribution 8 | 9 | #### 1. Definitions 10 | 11 | “License” shall mean the terms and conditions for use, reproduction, and 12 | distribution as defined by Sections 1 through 9 of this document. 13 | 14 | “Licensor” shall mean the copyright owner or entity authorized by the copyright 15 | owner that is granting the License. 16 | 17 | “Legal Entity” shall mean the union of the acting entity and all other entities 18 | that control, are controlled by, or are under common control with that entity. 19 | For the purposes of this definition, “control” means **(i)** the power, direct or 20 | indirect, to cause the direction or management of such entity, whether by 21 | contract or otherwise, or **(ii)** ownership of fifty percent (50%) or more of the 22 | outstanding shares, or **(iii)** beneficial ownership of such entity. 23 | 24 | “You” (or “Your”) shall mean an individual or Legal Entity exercising 25 | permissions granted by this License. 26 | 27 | “Source” form shall mean the preferred form for making modifications, including 28 | but not limited to software source code, documentation source, and configuration 29 | files. 30 | 31 | “Object” form shall mean any form resulting from mechanical transformation or 32 | translation of a Source form, including but not limited to compiled object code, 33 | generated documentation, and conversions to other media types. 34 | 35 | “Work” shall mean the work of authorship, whether in Source or Object form, made 36 | available under the License, as indicated by a copyright notice that is included 37 | in or attached to the work (an example is provided in the Appendix below). 38 | 39 | “Derivative Works” shall mean any work, whether in Source or Object form, that 40 | is based on (or derived from) the Work and for which the editorial revisions, 41 | annotations, elaborations, or other modifications represent, as a whole, an 42 | original work of authorship. For the purposes of this License, Derivative Works 43 | shall not include works that remain separable from, or merely link (or bind by 44 | name) to the interfaces of, the Work and Derivative Works thereof. 45 | 46 | “Contribution” shall mean any work of authorship, including the original version 47 | of the Work and any modifications or additions to that Work or Derivative Works 48 | thereof, that is intentionally submitted to Licensor for inclusion in the Work 49 | by the copyright owner or by an individual or Legal Entity authorized to submit 50 | on behalf of the copyright owner. For the purposes of this definition, 51 | “submitted” means any form of electronic, verbal, or written communication sent 52 | to the Licensor or its representatives, including but not limited to 53 | communication on electronic mailing lists, source code control systems, and 54 | issue tracking systems that are managed by, or on behalf of, the Licensor for 55 | the purpose of discussing and improving the Work, but excluding communication 56 | that is conspicuously marked or otherwise designated in writing by the copyright 57 | owner as “Not a Contribution.” 58 | 59 | “Contributor” shall mean Licensor and any individual or Legal Entity on behalf 60 | of whom a Contribution has been received by Licensor and subsequently 61 | incorporated within the Work. 62 | 63 | #### 2. Grant of Copyright License 64 | 65 | Subject to the terms and conditions of this License, each Contributor hereby 66 | grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, 67 | irrevocable copyright license to reproduce, prepare Derivative Works of, 68 | publicly display, publicly perform, sublicense, and distribute the Work and such 69 | Derivative Works in Source or Object form. 70 | 71 | #### 3. Grant of Patent License 72 | 73 | Subject to the terms and conditions of this License, each Contributor hereby 74 | grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, 75 | irrevocable (except as stated in this section) patent license to make, have 76 | made, use, offer to sell, sell, import, and otherwise transfer the Work, where 77 | such license applies only to those patent claims licensable by such Contributor 78 | that are necessarily infringed by their Contribution(s) alone or by combination 79 | of their Contribution(s) with the Work to which such Contribution(s) was 80 | submitted. If You institute patent litigation against any entity (including a 81 | cross-claim or counterclaim in a lawsuit) alleging that the Work or a 82 | Contribution incorporated within the Work constitutes direct or contributory 83 | patent infringement, then any patent licenses granted to You under this License 84 | for that Work shall terminate as of the date such litigation is filed. 85 | 86 | #### 4. Redistribution 87 | 88 | You may reproduce and distribute copies of the Work or Derivative Works thereof 89 | in any medium, with or without modifications, and in Source or Object form, 90 | provided that You meet the following conditions: 91 | 92 | * **(a)** You must give any other recipients of the Work or Derivative Works a copy of 93 | this License; and 94 | * **(b)** You must cause any modified files to carry prominent notices stating that You 95 | changed the files; and 96 | * **(c)** You must retain, in the Source form of any Derivative Works that You distribute, 97 | all copyright, patent, trademark, and attribution notices from the Source form 98 | of the Work, excluding those notices that do not pertain to any part of the 99 | Derivative Works; and 100 | * **(d)** If the Work includes a “NOTICE” text file as part of its distribution, then any 101 | Derivative Works that You distribute must include a readable copy of the 102 | attribution notices contained within such NOTICE file, excluding those notices 103 | that do not pertain to any part of the Derivative Works, in at least one of the 104 | following places: within a NOTICE text file distributed as part of the 105 | Derivative Works; within the Source form or documentation, if provided along 106 | with the Derivative Works; or, within a display generated by the Derivative 107 | Works, if and wherever such third-party notices normally appear. The contents of 108 | the NOTICE file are for informational purposes only and do not modify the 109 | License. You may add Your own attribution notices within Derivative Works that 110 | You distribute, alongside or as an addendum to the NOTICE text from the Work, 111 | provided that such additional attribution notices cannot be construed as 112 | modifying the License. 113 | 114 | You may add Your own copyright statement to Your modifications and may provide 115 | additional or different license terms and conditions for use, reproduction, or 116 | distribution of Your modifications, or for any such Derivative Works as a whole, 117 | provided Your use, reproduction, and distribution of the Work otherwise complies 118 | with the conditions stated in this License. 119 | 120 | #### 5. Submission of Contributions 121 | 122 | Unless You explicitly state otherwise, any Contribution intentionally submitted 123 | for inclusion in the Work by You to the Licensor shall be under the terms and 124 | conditions of this License, without any additional terms or conditions. 125 | Notwithstanding the above, nothing herein shall supersede or modify the terms of 126 | any separate license agreement you may have executed with Licensor regarding 127 | such Contributions. 128 | 129 | #### 6. Trademarks 130 | 131 | This License does not grant permission to use the trade names, trademarks, 132 | service marks, or product names of the Licensor, except as required for 133 | reasonable and customary use in describing the origin of the Work and 134 | reproducing the content of the NOTICE file. 135 | 136 | #### 7. Disclaimer of Warranty 137 | 138 | Unless required by applicable law or agreed to in writing, Licensor provides the 139 | Work (and each Contributor provides its Contributions) on an “AS IS” BASIS, 140 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 141 | including, without limitation, any warranties or conditions of TITLE, 142 | NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are 143 | solely responsible for determining the appropriateness of using or 144 | redistributing the Work and assume any risks associated with Your exercise of 145 | permissions under this License. 146 | 147 | #### 8. Limitation of Liability 148 | 149 | In no event and under no legal theory, whether in tort (including negligence), 150 | contract, or otherwise, unless required by applicable law (such as deliberate 151 | and grossly negligent acts) or agreed to in writing, shall any Contributor be 152 | liable to You for damages, including any direct, indirect, special, incidental, 153 | or consequential damages of any character arising as a result of this License or 154 | out of the use or inability to use the Work (including but not limited to 155 | damages for loss of goodwill, work stoppage, computer failure or malfunction, or 156 | any and all other commercial damages or losses), even if such Contributor has 157 | been advised of the possibility of such damages. 158 | 159 | #### 9. Accepting Warranty or Additional Liability 160 | 161 | While redistributing the Work or Derivative Works thereof, You may choose to 162 | offer, and charge a fee for, acceptance of support, warranty, indemnity, or 163 | other liability obligations and/or rights consistent with this License. However, 164 | in accepting such obligations, You may act only on Your own behalf and on Your 165 | sole responsibility, not on behalf of any other Contributor, and only if You 166 | agree to indemnify, defend, and hold each Contributor harmless for any liability 167 | incurred by, or claims asserted against, such Contributor by reason of your 168 | accepting any such warranty or additional liability. 169 | 170 | _END OF TERMS AND CONDITIONS_ 171 | 172 | ### APPENDIX: How to apply the Apache License to your work 173 | 174 | To apply the Apache License to your work, attach the following boilerplate 175 | notice, with the fields enclosed by brackets `[]` replaced with your own 176 | identifying information. (Don't include the brackets!) The text should be 177 | enclosed in the appropriate comment syntax for the file format. We also 178 | recommend that a file or class name and description of purpose be included on 179 | the same “printed page” as the copyright notice for easier identification within 180 | third-party archives. 181 | 182 | Copyright [yyyy] [name of copyright owner] 183 | 184 | Licensed under the Apache License, Version 2.0 (the "License"); 185 | you may not use this file except in compliance with the License. 186 | You may obtain a copy of the License at 187 | 188 | http://www.apache.org/licenses/LICENSE-2.0 189 | 190 | Unless required by applicable law or agreed to in writing, software 191 | distributed under the License is distributed on an "AS IS" BASIS, 192 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 193 | See the License for the specific language governing permissions and 194 | limitations under the License. 195 | 196 | -------------------------------------------------------------------------------- /kexec/README.md: -------------------------------------------------------------------------------- 1 | using this nix expression and a copy of nixpkgs from nixos-unstable, you can boot a nixos ramdisk on any server with a linux kernel that has kexec enabled 2 | 3 | to use, insert your own ssh public key into the authorizedKeys for root, and then execute as seen in session.md 4 | 5 | you are also free to pre-install custom tools into the ramdisk by just adding them to configuration.nix just like you would on a normal nixos system 6 | 7 | one simple customization would be ``boot.supportedFilesystems = [ "zfs" ];`` 8 | 9 | and once you have nixos in a ramdisk, you are free to delete all partitions, and nixos-install like normal 10 | -------------------------------------------------------------------------------- /kexec/autoreboot.nix: -------------------------------------------------------------------------------- 1 | { config, lib, ... }: 2 | 3 | { 4 | options = { 5 | kexec.autoReboot = lib.mkOption { 6 | default = true; 7 | description = "auto-reboot at the end of the hour"; 8 | type = lib.types.bool; 9 | }; 10 | }; 11 | config = lib.mkIf config.kexec.autoReboot { 12 | systemd.timers.autoreboot = { 13 | partOf = [ "autoreboot.service" ]; 14 | wantedBy = [ "timers.target" ]; 15 | timerConfig.OnCalendar = "hourly"; 16 | }; 17 | systemd.services.autoreboot = { 18 | script = "shutdown -r +5"; 19 | }; 20 | }; 21 | } 22 | -------------------------------------------------------------------------------- /kexec/configuration.nix: -------------------------------------------------------------------------------- 1 | # new cmd: nix-build '' -A config.system.build.kexec_tarball -I nixos-config=./configuration.nix -Q -j 4 2 | 3 | { lib, pkgs, config, ... }: 4 | 5 | with lib; 6 | 7 | { 8 | imports = [ ./autoreboot.nix ./kexec.nix ./justdoit.nix ]; 9 | 10 | boot.supportedFilesystems = [ "zfs" ]; 11 | boot.loader.grub.enable = false; 12 | boot.kernelParams = [ 13 | "console=ttyS0,115200" # allows certain forms of remote access, if the hardware is setup right 14 | "panic=30" "boot.panic_on_fail" # reboot the machine upon fatal boot issues 15 | ]; 16 | systemd.services.sshd.wantedBy = mkForce [ "multi-user.target" ]; 17 | networking.hostName = "kexec"; 18 | # example way to embed an ssh pubkey into the tar 19 | # users.users.root.openssh.authorizedKeys.keys = [ "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC34wZQFEOGkA5b0Z6maE3aKy/ix1MiK1D0Qmg4E9skAA57yKtWYzjA23r5OCF4Nhlj1CuYd6P1sEI/fMnxf+KkqqgW3ZoZ0+pQu4Bd8Ymi3OkkQX9kiq2coD3AFI6JytC6uBi6FaZQT5fG59DbXhxO5YpZlym8ps1obyCBX0hyKntD18RgHNaNM+jkQOhQ5OoxKsBEobxQOEdjIowl2QeEHb99n45sFr53NFqk3UCz0Y7ZMf1hSFQPuuEC/wExzBBJ1Wl7E1LlNA4p9O3qJUSadGZS4e5nSLqMnbQWv2icQS/7J8IwY0M8r1MsL8mdnlXHUofPlG1r4mtovQ2myzOx clever@nixos" ]; 20 | } 21 | -------------------------------------------------------------------------------- /kexec/dummy.nix: -------------------------------------------------------------------------------- 1 | let 2 | pkgs = import { config = {}; }; 3 | netboot = let 4 | build = (import (pkgs.path + "/nixos/lib/eval-config.nix") { 5 | system = "x86_64-linux"; 6 | modules = [ 7 | (pkgs.path + "/nixos/modules/installer/netboot/netboot-minimal.nix") 8 | ./justdoit.nix 9 | ./test.nix 10 | ]; 11 | }).config.system.build; 12 | in pkgs.symlinkJoin { 13 | name = "netboot"; 14 | paths = with build; [ netbootRamdisk kernel netbootIpxeScript ]; 15 | }; 16 | in netboot 17 | -------------------------------------------------------------------------------- /kexec/justdoit.nix: -------------------------------------------------------------------------------- 1 | { config, pkgs, lib, ... }: 2 | 3 | with lib; 4 | let 5 | cfg = config.kexec.justdoit; 6 | x = if cfg.nvme then "p" else ""; 7 | in { 8 | options = { 9 | kexec.justdoit = { 10 | rootDevice = mkOption { 11 | type = types.str; 12 | default = "/dev/sda"; 13 | description = "the root block device that justdoit will nuke from orbit and force nixos onto"; 14 | }; 15 | bootSize = mkOption { 16 | type = types.int; 17 | default = 256; 18 | description = "size of /boot in mb"; 19 | }; 20 | bootType = mkOption { 21 | type = types.enum [ "ext4" "vfat" "zfs" ]; 22 | default = "ext4"; 23 | }; 24 | swapSize = mkOption { 25 | type = types.int; 26 | default = 1024; 27 | description = "size of swap in mb"; 28 | }; 29 | poolName = mkOption { 30 | type = types.str; 31 | default = "tank"; 32 | description = "zfs pool name"; 33 | }; 34 | luksEncrypt = mkOption { 35 | type = types.bool; 36 | default = false; 37 | description = "encrypt all of zfs and swap"; 38 | }; 39 | uefi = mkOption { 40 | type = types.bool; 41 | default = false; 42 | description = "create a uefi install"; 43 | }; 44 | nvme = mkOption { 45 | type = types.bool; 46 | default = false; 47 | description = "rootDevice is nvme"; 48 | }; 49 | }; 50 | }; 51 | config = let 52 | mkBootTable = { 53 | ext4 = "mkfs.ext4 $NIXOS_BOOT -L NIXOS_BOOT"; 54 | vfat = "mkfs.vfat $NIXOS_BOOT -n NIXOS_BOOT"; 55 | zfs = ""; 56 | }; 57 | in lib.mkIf true { 58 | system.build.justdoit = pkgs.writeScriptBin "justdoit" '' 59 | #!${pkgs.stdenv.shell} 60 | 61 | set -e 62 | 63 | vgchange -a n 64 | 65 | wipefs -a ${cfg.rootDevice} 66 | dd if=/dev/zero of=${cfg.rootDevice} bs=512 count=10000 67 | sfdisk ${cfg.rootDevice} < /mnt/etc/nixos/generated.nix < $out/cmdline 10 | nuke-refs $out/kernel 11 | ''; 12 | kexec_script = pkgs.writeTextFile { 13 | executable = true; 14 | name = "kexec-nixos"; 15 | text = '' 16 | #!${pkgs.stdenv.shell} 17 | export PATH=${pkgs.kexectools}/bin:${pkgs.cpio}/bin:$PATH 18 | set -x 19 | set -e 20 | cd $(mktemp -d) 21 | pwd 22 | mkdir initrd 23 | pushd initrd 24 | if [ -e /ssh_pubkey ]; then 25 | cat /ssh_pubkey >> authorized_keys 26 | fi 27 | find -type f | cpio -o -H newc | gzip -9 > ../extra.gz 28 | popd 29 | cat ${image}/initrd extra.gz > final.gz 30 | 31 | kexec -l ${image}/kernel --initrd=final.gz --append="init=${builtins.unsafeDiscardStringContext config.system.build.toplevel}/init ${toString config.boot.kernelParams}" 32 | sync 33 | echo "executing kernel, filesystems will be improperly umounted" 34 | kexec -e 35 | ''; 36 | }; 37 | }; 38 | boot.initrd.postMountCommands = '' 39 | mkdir -p /mnt-root/root/.ssh/ 40 | cp /authorized_keys /mnt-root/root/.ssh/ 41 | ''; 42 | system.build.kexec_tarball = pkgs.callPackage (pkgs.path + "/nixos/lib/make-system-tarball.nix") { 43 | storeContents = [ 44 | { object = config.system.build.kexec_script; symlink = "/kexec_nixos"; } 45 | ]; 46 | contents = []; 47 | }; 48 | } 49 | -------------------------------------------------------------------------------- /kexec/nixops-example.nix: -------------------------------------------------------------------------------- 1 | { 2 | machine1 = { 3 | # if the root device is diferent, update it here 4 | boot.loader.grub.devices = [ "/dev/sda" ]; 5 | deployment = { 6 | targetEnv = "none"; 7 | targetHost = "192.168.2.160"; 8 | }; 9 | services.openssh.enable = true; 10 | fileSystems = { 11 | # if you change the pool name, update it here 12 | "/" = { fsType = "zfs"; device = "tank/root"; }; 13 | "/home" = { fsType = "zfs"; device = "tank/home"; }; 14 | "/nix" = { fsType = "zfs"; device = "tank/nix"; }; 15 | "/boot" = { fsType = "ext4"; label = "NIXOS_BOOT"; }; 16 | }; 17 | swapDevices = [ 18 | { label = "NIXOS_SWAP"; } 19 | ]; 20 | networking.hostId = "1d27723e"; # must be copied from the one justdoit randomly generated 21 | }; 22 | } 23 | -------------------------------------------------------------------------------- /kexec/session.md: -------------------------------------------------------------------------------- 1 | ``` 2 | $ nix-build '' -A config.system.build.kexec_tarball -I nixos-config=./configuration.nix -Q -j 4 3 | $ scp result/tarball/nixos-system-x86_64-linux.tar.xz 192.168.2.151:. 4 | $ ssh 192.168.2.151 5 | Welcome to Ubuntu 16.10 (GNU/Linux 4.8.0-22-generic x86_64) 6 | 7 | * Documentation: https://help.ubuntu.com 8 | * Management: https://landscape.canonical.com 9 | * Support: https://ubuntu.com/advantage 10 | 11 | 49 packages can be updated. 12 | 29 updates are security updates. 13 | 14 | clever@ubuntu:~$ sudo -i 15 | [sudo] password for clever: 16 | root@ubuntu:~# cd / 17 | root@ubuntu:/# tar -xf /home/clever/nixos-system-x86_64-linux.tar.xz 18 | root@ubuntu:/# ./kexec_nixos 19 | executing kernel, filesystems will be improperly umounted 20 | Connection to 192.168.2.151 closed. 21 | [clever@amd-nixos:~/nix-tests/kexec]$ ping 192.168.2.151 22 | PING 192.168.2.151 (192.168.2.151) 56(84) bytes of data. 23 | 64 bytes from 192.168.2.151: icmp_seq=1 ttl=64 time=0.197 ms 24 | 64 bytes from 192.168.2.151: icmp_seq=2 ttl=64 time=0.121 ms 25 | 64 bytes from 192.168.2.151: icmp_seq=3 ttl=64 time=0.181 ms 26 | ^C 27 | [clever@amd-nixos:~/nix-tests/kexec]$ ssh root@192.168.2.151 28 | The authenticity of host '192.168.2.151 (192.168.2.151)' can't be established. 29 | ED25519 key fingerprint is SHA256:o1Tl49CuK6Ipd5gT6GaNfotsgVMJcdxr2FZbGrmhqmE. 30 | Are you sure you want to continue connecting (yes/no)? yes 31 | Warning: Permanently added '192.168.2.151' (ED25519) to the list of known hosts. 32 | Last login: Fri Dec 9 05:47:11 2016 33 | 34 | [root@kexec:~]# 35 | ``` 36 | -------------------------------------------------------------------------------- /kexec/simple-test.nix: -------------------------------------------------------------------------------- 1 | let 2 | pkgs = import { config = {}; }; 3 | packages = with pkgs.lib; self: { 4 | nvme = false; 5 | uefi = false; 6 | virtio = true; 7 | configuration = {}; 8 | configuration1 = { 9 | imports = [ ./configuration.nix self.configuration ]; 10 | }; 11 | config = (import { configuration = self.configuration1; }).config; 12 | justdoit = self.config.system.build.justdoit; 13 | image = self.config.system.build.image; 14 | interface = if self.nvme then "none" else (if self.virtio then "virtio" else "scsi"); 15 | commonFlags = [ 16 | "-fw_cfg" "opt/com.angeldsis/simple-string,string=foobarbaz" 17 | "-serial" "mon:stdio" 18 | "-net" "user,hostfwd=tcp:127.0.0.2:2222-:22" "-net" "nic" 19 | "-m" "2048" 20 | "-drive" "index=0,id=drive1,file=dummy_root.qcow2,cache=writeback,werror=report,if=${self.interface}" 21 | ] ++ optional self.nvme "-device nvme,drive=drive1,serial=1234" 22 | ++ optional self.uefi "-drive if=pflash,format=raw,readonly,file=${pkgs.OVMF.fd}/FV/OVMF.fd -drive if=pflash,format=raw,file=my_uefi_vars.bin"; 23 | qemu_test1 = pkgs.writeScriptBin "qemu_test1" '' 24 | #!${pkgs.stdenv.shell} 25 | export PATH=${pkgs.qemu_kvm}/bin/:$PATH 26 | 27 | if ! test -e dummy_root.qcow2; then 28 | qemu-img create -f qcow2 dummy_root.qcow2 20G 29 | fi 30 | if ! test -e my_uefi_vars.bin; then 31 | cp ${pkgs.OVMF.fd}/FV/OVMF_VARS.fd my_uefi_vars.bin 32 | chmod +w my_uefi_vars.bin 33 | fi 34 | 35 | qemu-kvm -kernel ${self.image}/kernel -initrd ${self.image}/initrd \ 36 | -append "init=${builtins.unsafeDiscardStringContext self.config.system.build.toplevel}/init ${toString self.config.boot.kernelParams}" \ 37 | ${toString self.commonFlags} 38 | ''; 39 | qemu_test2 = pkgs.writeScriptBin "qemu_test2" '' 40 | #!${pkgs.stdenv.shell} 41 | export PATH=${pkgs.qemu_kvm}/bin/:$PATH 42 | 43 | qemu-kvm ${toString self.commonFlags} 44 | # -chardev stdio,id=qemu-debug-out -device isa-debugcon,chardev=qemu-debug-out 45 | ''; 46 | # -debugcon file:debug.log -global isa-debugcon.iobase=0x402 \ 47 | qemu_test = pkgs.buildEnv { 48 | name = "qemu_test"; 49 | paths = with self; [ qemu_test1 qemu_test2 ]; 50 | }; 51 | }; 52 | self = pkgs.lib.makeScope pkgs.newScope packages; 53 | makeTest = { uefi ? false, nvme ? false, virtio ? false, luks ? false, bootType ? (if uefi then "vfat" else "ext4")}: let 54 | pkgs2 = with pkgs.lib; self.overrideScope' (self: super: { 55 | inherit uefi nvme virtio; 56 | configuration = { 57 | kexec.justdoit = { 58 | rootDevice = mkForce (if nvme then "/dev/nvme0n1" else (if virtio then "/dev/vda" else "/dev/sda")); 59 | nvme = mkForce nvme; 60 | luksEncrypt = mkForce luks; 61 | uefi = mkForce uefi; 62 | inherit bootType; 63 | }; 64 | }; 65 | }); 66 | in pkgs2.qemu_test // { justdoit = pkgs2.justdoit; }; 67 | in { 68 | legacy_sata = makeTest {}; 69 | uefi_sata = makeTest { uefi = true; }; 70 | legacy_virtio = makeTest { virtio = true; }; 71 | nvme = makeTest { uefi = true; nvme = true; }; 72 | luks_legacy = makeTest { luks = true; virtio = true; }; 73 | virtio_no_boot = makeTest { virtio = true; bootType = "zfs"; }; 74 | luks_nvme = makeTest { luks = true; uefi = true; nvme = true; }; 75 | } 76 | -------------------------------------------------------------------------------- /kexec/target-config.nix: -------------------------------------------------------------------------------- 1 | { ... }: 2 | 3 | { 4 | imports = [ ./hardware-configuration.nix ./generated.nix ]; 5 | boot.loader.grub.enable = true; 6 | boot.loader.grub.version = 2; 7 | services.openssh.enable = true; 8 | boot.zfs.devNodes = "/dev"; # fixes some virtualmachine issues 9 | boot.zfs.forceImportRoot = false; 10 | boot.zfs.forceImportAll = false; 11 | boot.kernelParams = [ 12 | "boot.shell_on_fail" 13 | "panic=30" "boot.panic_on_fail" # reboot the machine upon fatal boot issues 14 | ]; 15 | } 16 | -------------------------------------------------------------------------------- /kexec/test.nix: -------------------------------------------------------------------------------- 1 | { ... }: 2 | 3 | { 4 | kexec.justdoit = { 5 | luksEncrypt = false; 6 | }; 7 | } 8 | -------------------------------------------------------------------------------- /kexec/vbox-tips.md: -------------------------------------------------------------------------------- 1 | ``virtualisation.virtualbox.guest.enable = true;`` in the configuration.nix for the tar and 2 | ``` 3 | root@ubuntu:/sys/bus/pci/drivers/vboxvideo# ls -l 4 | total 0 5 | lrwxrwxrwx 1 root root 0 Dec 11 14:56 0000:00:02.0 -> ../../../../devices/pci0000:00/0000:00:02.0 6 | root@ubuntu:/sys/bus/pci/drivers/vboxvideo# echo 0000\:00\:02.0 > unbind 7 | ``` 8 | prior to kexec will allow the vboxvideo driver to recover and continue working in the new kernel after kexec 9 | -------------------------------------------------------------------------------- /make.nix: -------------------------------------------------------------------------------- 1 | with import {}; 2 | 3 | rec { 4 | bar_h = builtins.filterSource (name: type: lib.hasSuffix "/bar.h" name) ./.; 5 | foo_headers = buildEnv { 6 | name = "foo_headers"; 7 | paths = [ bar_h ]; 8 | }; 9 | foo = runCommandCC "foo.o" {} "gcc -c ${./foo.c} -I${foo_headers} -o $out"; 10 | bar = runCommandCC "bar.o" {} "gcc -c ${./bar.c} -o $out"; 11 | main = runCommandCC "main" {} "gcc ${foo} ${bar} -o $out"; 12 | } -------------------------------------------------------------------------------- /module-example/default.nix: -------------------------------------------------------------------------------- 1 | with import {}; 2 | 3 | pkgs.lib.evalModules { 4 | prefix = []; 5 | check = true; 6 | modules = [ ./example.nix ./expr.nix ]; 7 | args = {}; 8 | } 9 | -------------------------------------------------------------------------------- /module-example/example.nix: -------------------------------------------------------------------------------- 1 | { lib, ... }: 2 | 3 | { 4 | options = { 5 | a = lib.mkOption { 6 | type = lib.types.listOf lib.types.int; 7 | }; 8 | }; 9 | config = {}; 10 | } 11 | -------------------------------------------------------------------------------- /module-example/expr.nix: -------------------------------------------------------------------------------- 1 | { ... }: 2 | 3 | { 4 | imports = [ ./expr2.nix ]; 5 | a = [ 1 ]; 6 | } 7 | -------------------------------------------------------------------------------- /module-example/expr2.nix: -------------------------------------------------------------------------------- 1 | { ... }: 2 | 3 | { 4 | a = [ 2 ]; 5 | } 6 | -------------------------------------------------------------------------------- /module-example/usage.md: -------------------------------------------------------------------------------- 1 | ``` 2 | [clever@amd-nixos:~/nix-tests/module-example]$ nix repl default.nix 3 | Welcome to Nix version 2.2. Type :? for help. 4 | 5 | Loading 'default.nix'... 6 | Added 2 variables. 7 | 8 | nix-repl> config.a 9 | [ 2 1 ] 10 | ``` 11 | `example.nix` defines a to be an option, that is a list of ints, and then `exrp.nix` and `expr2.nix` set a to different things, [1] and [2], `default.nix` then merges all 3 files together, and looks at `config.a` 12 | -------------------------------------------------------------------------------- /nix-tests.sublime-workspace: -------------------------------------------------------------------------------- 1 | { 2 | "auto_complete": 3 | { 4 | "selected_items": 5 | [ 6 | [ 7 | "log_", 8 | "log_pubkey_raw" 9 | ], 10 | [ 11 | "add", 12 | "address" 13 | ], 14 | [ 15 | "tv", 16 | "tvbuff_t" 17 | ], 18 | [ 19 | "packet", 20 | "packet_info" 21 | ], 22 | [ 23 | "addre", 24 | "address6" 25 | ], 26 | [ 27 | "address", 28 | "address6" 29 | ], 30 | [ 31 | "proto_t", 32 | "proto_tree_add_ipv4" 33 | ], 34 | [ 35 | "ett", 36 | "ett_node" 37 | ], 38 | [ 39 | "proto_it", 40 | "proto_item_add_subtree" 41 | ], 42 | [ 43 | "tox", 44 | "tox_tree" 45 | ], 46 | [ 47 | "FT_UINT", 48 | "FT_UINT16" 49 | ], 50 | [ 51 | "addr", 52 | "addr_family" 53 | ], 54 | [ 55 | "ENC", 56 | "ENC_BIG_ENDIAN" 57 | ], 58 | [ 59 | "proto_tr", 60 | "proto_tree_add_item" 61 | ], 62 | [ 63 | "node", 64 | "node_count" 65 | ], 66 | [ 67 | "ciph", 68 | "ciphertext" 69 | ], 70 | [ 71 | "pack", 72 | "packet_type" 73 | ], 74 | [ 75 | "lib", 76 | "libtoxcore" 77 | ], 78 | [ 79 | "pkg", 80 | "pkgConfig" 81 | ], 82 | [ 83 | "gli", 84 | "glibmmdev" 85 | ], 86 | [ 87 | "gl", 88 | "glibmmdev" 89 | ], 90 | [ 91 | "netw", 92 | "networkProtobuf" 93 | ], 94 | [ 95 | "n", 96 | "new_ts" 97 | ], 98 | [ 99 | "last", 100 | "last_ts" 101 | ], 102 | [ 103 | "QS", 104 | "QStringLiteral" 105 | ], 106 | [ 107 | "off", 108 | "offset2" 109 | ], 110 | [ 111 | "con", 112 | "continue" 113 | ], 114 | [ 115 | "Db", 116 | "DbException" 117 | ], 118 | [ 119 | "co", 120 | "column_blob" 121 | ], 122 | [ 123 | "pubk", 124 | "pubkey" 125 | ], 126 | [ 127 | "st", 128 | "stmt_" 129 | ], 130 | [ 131 | "get_d", 132 | "get_data_" 133 | ], 134 | [ 135 | "Prep", 136 | "PrepareException" 137 | ], 138 | [ 139 | "SQL", 140 | "SQLITE_OK" 141 | ], 142 | [ 143 | "Pre", 144 | "PreparedQuery" 145 | ], 146 | [ 147 | "sq", 148 | "sql_utf8" 149 | ], 150 | [ 151 | "priv", 152 | "privkey_size" 153 | ], 154 | [ 155 | "pubke", 156 | "pubkey_size" 157 | ], 158 | [ 159 | "sql", 160 | "sqlite3_column_bytes" 161 | ], 162 | [ 163 | "sqlit", 164 | "sqlite3_column_blob" 165 | ], 166 | [ 167 | "sqlite3_bind", 168 | "sqlite3_bind_blob" 169 | ], 170 | [ 171 | "pu", 172 | "pubkey_" 173 | ], 174 | [ 175 | "cry", 176 | "crypto_box_SECRETKEYBYTES" 177 | ], 178 | [ 179 | "Ch", 180 | "ChannelNode" 181 | ], 182 | [ 183 | "self", 184 | "self_changed" 185 | ], 186 | [ 187 | "ch", 188 | "Channel" 189 | ], 190 | [ 191 | "Chann", 192 | "ChannelNode" 193 | ], 194 | [ 195 | "chann", 196 | "channelFolder" 197 | ], 198 | [ 199 | "chan", 200 | "changed" 201 | ], 202 | [ 203 | "cha", 204 | "channelFolder" 205 | ], 206 | [ 207 | "SQLITE", 208 | "SQLITE_DONE" 209 | ], 210 | [ 211 | "nam", 212 | "name_size" 213 | ], 214 | [ 215 | "sqlite3_colu", 216 | "sqlite3_column_bytes" 217 | ], 218 | [ 219 | "na", 220 | "name_size" 221 | ], 222 | [ 223 | "get", 224 | "get_all_channels" 225 | ], 226 | [ 227 | "SQLI", 228 | "SQLITE_ROW" 229 | ], 230 | [ 231 | "chnn", 232 | "channelFolder" 233 | ], 234 | [ 235 | "No", 236 | "NodeType" 237 | ], 238 | [ 239 | "nod", 240 | "node_changed" 241 | ], 242 | [ 243 | "Fri", 244 | "FriendNode" 245 | ], 246 | [ 247 | "read", 248 | "read_data" 249 | ], 250 | [ 251 | "sa", 252 | "savedata_length" 253 | ], 254 | [ 255 | "saveda", 256 | "savedata_data_" 257 | ], 258 | [ 259 | "set_", 260 | "set_savedata_data" 261 | ], 262 | [ 263 | "set_sa", 264 | "set_savedata_data" 265 | ], 266 | [ 267 | "re", 268 | "read_data" 269 | ], 270 | [ 271 | "key", 272 | "key_bytes" 273 | ], 274 | [ 275 | "str", 276 | "streaming" 277 | ], 278 | [ 279 | "seri", 280 | "seriesName" 281 | ], 282 | [ 283 | "url", 284 | "url_bytes" 285 | ], 286 | [ 287 | "to", 288 | "toUtf8" 289 | ], 290 | [ 291 | "matc", 292 | "matchedLength" 293 | ], 294 | [ 295 | "ind", 296 | "indexIn" 297 | ], 298 | [ 299 | "inc", 300 | "include" 301 | ], 302 | [ 303 | "pars", 304 | "parse_series" 305 | ], 306 | [ 307 | "ser", 308 | "seriesName_" 309 | ], 310 | [ 311 | "Ki", 312 | "KissParseRequest" 313 | ], 314 | [ 315 | "e", 316 | "explicit" 317 | ], 318 | [ 319 | "rea", 320 | "readyRead" 321 | ], 322 | [ 323 | "QNe", 324 | "QNetworkReply" 325 | ], 326 | [ 327 | "QN", 328 | "QNetworkReply" 329 | ], 330 | [ 331 | "root", 332 | "root_" 333 | ], 334 | [ 335 | "est", 336 | "estimated_sender_clock" 337 | ], 338 | [ 339 | "esti", 340 | "estimated_oneway_latency" 341 | ], 342 | [ 343 | "da", 344 | "datapacket" 345 | ], 346 | [ 347 | "user", 348 | "username" 349 | ], 350 | [ 351 | "g", 352 | "get_username" 353 | ], 354 | [ 355 | "fri", 356 | "friend_number" 357 | ], 358 | [ 359 | "siz", 360 | "size_t" 361 | ], 362 | [ 363 | "ui", 364 | "uint8_t" 365 | ], 366 | [ 367 | "uin", 368 | "uint32_t" 369 | ], 370 | [ 371 | "call", 372 | "callback_friend_name" 373 | ], 374 | [ 375 | "TOX_ERR", 376 | "TOX_ERR_SET_INFO" 377 | ], 378 | [ 379 | "uint", 380 | "uint8_t" 381 | ], 382 | [ 383 | "li", 384 | "link_type" 385 | ], 386 | [ 387 | "conn", 388 | "connection" 389 | ], 390 | [ 391 | "up", 392 | "uptime_offset" 393 | ], 394 | [ 395 | "ran", 396 | "random_delay" 397 | ], 398 | [ 399 | "sen", 400 | "send_packet" 401 | ], 402 | [ 403 | "from", 404 | "fromStdString" 405 | ], 406 | [ 407 | "pa", 408 | "payload" 409 | ], 410 | [ 411 | "cal", 412 | "call_stop" 413 | ], 414 | [ 415 | "hea", 416 | "header_size" 417 | ], 418 | [ 419 | "packe", 420 | "packet1" 421 | ], 422 | [ 423 | "QB", 424 | "QByteArray" 425 | ], 426 | [ 427 | "St", 428 | "StateNull" 429 | ], 430 | [ 431 | "out", 432 | "outbound_pipeline" 433 | ], 434 | [ 435 | "inb", 436 | "inbound" 437 | ], 438 | [ 439 | "QG", 440 | "QGst" 441 | ], 442 | [ 443 | "G_TYPE", 444 | "G_TYPE_STRING" 445 | ], 446 | [ 447 | "TOX_", 448 | "TOX_TYPE_SOURCE" 449 | ], 450 | [ 451 | "tox_", 452 | "tox_source_stream_send_event" 453 | ], 454 | [ 455 | "tox_s", 456 | "tox_source_stream" 457 | ], 458 | [ 459 | "GstSt", 460 | "GstStateChangeReturn" 461 | ], 462 | [ 463 | "tox_source_stream_c", 464 | "tox_source_stream_change_state" 465 | ], 466 | [ 467 | "PR", 468 | "PROP_N" 469 | ], 470 | [ 471 | "PRO", 472 | "PROP_STREAM" 473 | ], 474 | [ 475 | "El", 476 | "Element" 477 | ], 478 | [ 479 | "Tox", 480 | "ToxSourceStreamClass" 481 | ] 482 | ] 483 | }, 484 | "buffers": 485 | [ 486 | ], 487 | "build_system": "", 488 | "build_system_choices": 489 | [ 490 | [ 491 | [ 492 | [ 493 | "Packages/C++/C++ Single File.sublime-build", 494 | "" 495 | ], 496 | [ 497 | "Packages/C++/C++ Single File.sublime-build", 498 | "Run" 499 | ], 500 | [ 501 | "Packages/User/ninja.sublime-build", 502 | "" 503 | ] 504 | ], 505 | [ 506 | "Packages/User/ninja.sublime-build", 507 | "" 508 | ] 509 | ] 510 | ], 511 | "build_varint": "", 512 | "command_palette": 513 | { 514 | "height": 348.0, 515 | "last_filter": "Package Control: ", 516 | "selected_items": 517 | [ 518 | [ 519 | "Package Control: ", 520 | "Package Control: Enable Package" 521 | ], 522 | [ 523 | "Package Control: d", 524 | "Package Control: Disable Package" 525 | ], 526 | [ 527 | "c++", 528 | "C++YouCompleteMe: Highlight problems" 529 | ], 530 | [ 531 | "cmd", 532 | "C++YouCompleteMe: Goto declaration" 533 | ], 534 | [ 535 | "ycmd", 536 | "Ycmd: Restart ycmd server" 537 | ], 538 | [ 539 | "ycm", 540 | "C++YouCompleteMe: Highlight problems" 541 | ] 542 | ], 543 | "width": 449.0 544 | }, 545 | "console": 546 | { 547 | "height": 231.0, 548 | "history": 549 | [ 550 | "/home/clever/.config/sublime-text-3", 551 | "clear()", 552 | "clear", 553 | "import urllib.request,os,hashlib; h = '2915d1851351e5ee549c20394736b442' + '8bc59f460fa1548d1514676163dafc88'; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); by = urllib.request.urlopen( 'http://packagecontrol.io/' + pf.replace(' ', '%20')).read(); dh = hashlib.sha256(by).hexdigest(); print('Error validating download (got %s instead of %s), please try manual install' % (dh, h)) if dh != h else open(os.path.join( ipp, pf), 'wb' ).write(by)" 554 | ] 555 | }, 556 | "distraction_free": 557 | { 558 | "menu_visible": true, 559 | "show_minimap": false, 560 | "show_open_files": false, 561 | "show_tabs": false, 562 | "side_bar_visible": false, 563 | "status_bar_visible": false 564 | }, 565 | "expanded_folders": 566 | [ 567 | "/home/clever/nix-tests" 568 | ], 569 | "file_history": 570 | [ 571 | "/home/clever/toxcore/toxcore/net_crypto.c", 572 | "/home/clever/apps/arcane-chat/logkeys.c", 573 | "/home/clever/apps/arcane-chat/fixes/gstreamer/qt-gstreamer/default.nix", 574 | "/home/clever/apps/arcane-chat/chat-shaker/chat-shaker.hs", 575 | "/home/clever/apps/arcane-chat/chat-shaker/default.nix", 576 | "/home/clever/apps/arcane-chat/chat/CMakeLists.txt", 577 | "/home/clever/apps/arcane-chat/chat/default.nix", 578 | "/home/clever/apps/arcane-chat/default.nix", 579 | "/home/clever/apps/arcane-chat/redo.nix", 580 | "/home/clever/apps/arcane-chat/fixes/gstreamer/qt-gstreamer/CMakeLists.txt", 581 | "/home/clever/apps/arcane-chat/fixes/5.6/qtsvg.nix", 582 | "/home/clever/apps/arcane-chat/release.nix", 583 | "/home/clever/apps/arcane-chat/fixes/5.6/default.nix", 584 | "/home/clever/apps/arcane-chat/fixes/gstreamer/qt-gstreamer/Makefile", 585 | "/home/clever/apps/arcane-chat/fixes/5.6/qtbase/default.nix", 586 | "/home/clever/x/qtsvg-opensource-src-5.6.1/src/svg/qsvghandler.cpp", 587 | "/home/clever/apps/arcane-chat/qtbase.txt", 588 | "/home/clever/x/gstreamermm-1.4.3/gstreamer/gstreamermm/pad.h", 589 | "/home/clever/x/gstreamermm-1.4.3/gstreamer/gstreamermm/bin.cc", 590 | "/home/clever/x/gstreamermm-1.4.3/gstreamer/gstreamermm/bin.h", 591 | "/home/clever/apps/arcane-chat/fixes/gstreamer/base/default.nix", 592 | "/home/clever/apps/arcane-chat/fixes/gstreamer/gstreamermm/default.nix", 593 | "/home/clever/apps/arcane-chat/chat/src/core.hpp", 594 | "/home/clever/spotify.nix", 595 | "/home/clever/apps/arcane-chat/chat/src/friend.hpp", 596 | "/home/clever/apps/arcane-chat/chat/src/core.cpp", 597 | "/home/clever/apps/arcane-chat/chat/src/db.hpp", 598 | "/home/clever/apps/arcane-chat/chat/src/utils.cpp", 599 | "/home/clever/apps/arcane-chat/chat/src/core_db.cpp", 600 | "/home/clever/apps/arcane-chat/chat/src/infowidget.hpp", 601 | "/home/clever/apps/arcane-chat/chat/src/kiss.hpp", 602 | "/home/clever/apps/arcane-chat/chat/src/options.hpp", 603 | "/home/clever/apps/arcane-chat/chat/src/channelmodel.hpp", 604 | "/home/clever/apps/arcane-chat/chat/src/chatwidget.hpp", 605 | "/home/clever/apps/arcane-chat/chat/src/core_db.hpp", 606 | "/home/clever/apps/arcane-chat/chat/src/stats.hpp", 607 | "/home/clever/apps/arcane-chat/chat/src/stats.cpp", 608 | "/home/clever/apps/arcane-chat/chat/src/kiss.cpp", 609 | "/home/clever/apps/arcane-chat/chat/src/friend.cpp", 610 | "/home/clever/apps/arcane-chat/chat/src/chatwidget.cpp", 611 | "/home/clever/apps/arcane-chat/chat/src/channelmodel.cpp", 612 | "/home/clever/apps/arcane-chat/chat/src/channel.hpp", 613 | "/home/clever/apps/arcane-chat/chat/src/channel.cpp", 614 | "/home/clever/apps/arcane-chat/chat/src/mainwindow.cpp", 615 | "/home/clever/apps/arcane-chat/chat/src/mainwindow.hpp", 616 | "/home/clever/apps/arcane-chat/chat/network.proto", 617 | "/home/clever/apps/arcane-chat/chat-build/network.pb.h", 618 | "/home/clever/.config/sublime-text-3/Packages/User/Preferences.sublime-settings", 619 | "/home/clever/.config/sublime-text-3/Packages/Default/Preferences.sublime-settings", 620 | "/home/clever/apps/arcane-chat/chat/src/audiocall.hpp", 621 | "/home/clever/apps/arcane-chat/chat/src/kisscache.cpp", 622 | "/home/clever/apps/arcane-chat/chat/src/client.cpp", 623 | "/home/clever/apps/arcane-chat/chat/src/options.cpp", 624 | "/home/clever/apps/arcane-chat/chat/src/mainwindow.ui", 625 | "/home/clever/apps/arcane-chat/chat-build/ui_mainwindow.h", 626 | "/home/clever/apps/arcane-chat/chat/src/kisstest.cpp", 627 | "/home/clever/apps/arcane-chat/chat/src/infowidget.cpp", 628 | "/home/clever/apps/arcane-chat/chat/src/kisscache.hpp", 629 | "/home/clever/apps/arcane-chat/chat/src/wrapper.js", 630 | "/home/clever/apps/arcane-chat/chat/src/temp.html", 631 | "/home/clever/apps/arcane-chat/chat/src/audiocall.cpp", 632 | "/home/clever/not-os/installer-example.sh", 633 | "/home/clever/apps/arcane-chat/chat/src/callcontrol.cpp", 634 | "/home/clever/apps/arcane-chat/chat/src/utils.hpp", 635 | "/home/clever/apps/arcane-chat/glib/default.nix", 636 | "/home/clever/apps/arcane-chat/chat/src/callcontrol.hpp", 637 | "/home/clever/apps/arcane-chat/chat/src/server.cpp", 638 | "/home/clever/apps/arcane-chat/chat/src/toxsink.hpp", 639 | "/home/clever/apps/arcane-chat/chat/src/toxsource.hpp", 640 | "/home/clever/apps/arcane-chat/chat/state_util/state_test.cpp", 641 | "/home/clever/apps/arcane-chat/chat/src/Stats.hpp", 642 | "/home/clever/apps/arcane-chat/chat/src/toxsink.cpp", 643 | "/home/clever/apps/arcane-chat/chat-build/network.pb.cc", 644 | "/home/clever/x/qt-gstreamer-1.2.0/src/QGst/parse.cpp", 645 | "/home/clever/x/qt-gstreamer-1.2.0/src/QGlib/wrap.cpp", 646 | "/home/clever/x/qt-gstreamer-1.2.0/src/QGlib/wrap.h", 647 | "/home/clever/x/qt-gstreamer-1.2.0/src/QGlib/refpointer.h", 648 | "/home/clever/apps/arcane-chat/chat/src/gst.cpp", 649 | "/home/clever/apps/arcane-chat/chat/src/toxsource.cpp", 650 | "/home/clever/.config/sublime-text-3/Packages/C++YouCompleteMe/C++YouCompleteMe.sublime-settings", 651 | "/home/clever/apps/arcane-chat/chat/src/toxinputstream.cpp", 652 | "/home/clever/.config/sublime-text-3/Packages/User/ninja.sublime-build", 653 | "/home/clever/.config/sublime-text-3/Packages/User/YcmdCompletion.sublime-settings", 654 | "/home/clever/.ycmd.json" 655 | ], 656 | "find": 657 | { 658 | "height": 23.0 659 | }, 660 | "find_in_files": 661 | { 662 | "height": 0.0, 663 | "where_history": 664 | [ 665 | ] 666 | }, 667 | "find_state": 668 | { 669 | "case_sensitive": false, 670 | "find_history": 671 | [ 672 | " \"", 673 | "proto_tox", 674 | "ett_tox", 675 | "ciphertext", 676 | "hf_tox_pdu_type", 677 | "maybe", 678 | "calldata", 679 | "glib", 680 | "sigcxx", 681 | "headers", 682 | "rtags", 683 | "include-wh", 684 | "include", 685 | "super", 686 | "gst_all_1", 687 | "xorg", 688 | "pkgs", 689 | "<.> ", 690 | "Widgets", 691 | "protobuf", 692 | "prop", 693 | "glib", 694 | "txt", 695 | "glib", 696 | "gstreamer", 697 | "glib", 698 | "libav", 699 | "xorg", 700 | "lndir", 701 | "substi", 702 | "lndir", 703 | "qtbase", 704 | "dbus", 705 | "zlib", 706 | "standardpaths", 707 | "standard", 708 | "zlib", 709 | "compress.o", 710 | "mkspec", 711 | "harfbuzz", 712 | "xcb", 713 | "glib", 714 | "xcb", 715 | "icu", 716 | "harfbuzz", 717 | "qtbase", 718 | "pix", 719 | "cross", 720 | "interface", 721 | "protobuf", 722 | "uptime", 723 | "indent", 724 | "ruler", 725 | "save_sta", 726 | "save_state", 727 | "savedata", 728 | "save_st", 729 | "status", 730 | "tox_friend_send", 731 | "name", 732 | "toxcore", 733 | "data", 734 | "parse", 735 | "set_data", 736 | "include", 737 | "qt", 738 | "lossy", 739 | "send_lossy_packet", 740 | "wrap" 741 | ], 742 | "highlight": true, 743 | "in_selection": false, 744 | "preserve_case": false, 745 | "regex": false, 746 | "replace_history": 747 | [ 748 | "self", 749 | "iface" 750 | ], 751 | "reverse": false, 752 | "show_context": true, 753 | "use_buffer2": true, 754 | "whole_word": false, 755 | "wrap": true 756 | }, 757 | "folders": 758 | [ 759 | { 760 | "path": "/home/clever/nix-tests" 761 | } 762 | ], 763 | "groups": 764 | [ 765 | { 766 | "sheets": 767 | [ 768 | ] 769 | } 770 | ], 771 | "incremental_find": 772 | { 773 | "height": 23.0 774 | }, 775 | "input": 776 | { 777 | "height": 31.0 778 | }, 779 | "layout": 780 | { 781 | "cells": 782 | [ 783 | [ 784 | 0, 785 | 0, 786 | 1, 787 | 1 788 | ] 789 | ], 790 | "cols": 791 | [ 792 | 0.0, 793 | 1.0 794 | ], 795 | "rows": 796 | [ 797 | 0.0, 798 | 1.0 799 | ] 800 | }, 801 | "menu_visible": true, 802 | "output.CppYCM.2": 803 | { 804 | "height": 0.0 805 | }, 806 | "output.exec": 807 | { 808 | "height": 275.0 809 | }, 810 | "output.find_results": 811 | { 812 | "height": 0.0 813 | }, 814 | "output.sublime_haskell_error_panel": 815 | { 816 | "height": 100.0 817 | }, 818 | "pinned_build_system": "", 819 | "project": "", 820 | "replace": 821 | { 822 | "height": 42.0 823 | }, 824 | "save_all_on_build": true, 825 | "select_file": 826 | { 827 | "height": 0.0, 828 | "last_filter": "", 829 | "selected_items": 830 | [ 831 | ], 832 | "width": 0.0 833 | }, 834 | "select_project": 835 | { 836 | "height": 0.0, 837 | "last_filter": "", 838 | "selected_items": 839 | [ 840 | ], 841 | "width": 0.0 842 | }, 843 | "select_symbol": 844 | { 845 | "height": 0.0, 846 | "last_filter": "", 847 | "selected_items": 848 | [ 849 | ], 850 | "width": 0.0 851 | }, 852 | "selected_group": 0, 853 | "settings": 854 | { 855 | }, 856 | "show_minimap": true, 857 | "show_open_files": false, 858 | "show_tabs": true, 859 | "side_bar_visible": true, 860 | "side_bar_width": 240.0, 861 | "status_bar_visible": true, 862 | "template_settings": 863 | { 864 | } 865 | } 866 | -------------------------------------------------------------------------------- /nix-tracker/default.nix: -------------------------------------------------------------------------------- 1 | derivation { 2 | name = "example"; 3 | foo = builtins.storePath ./example.txt; 4 | } 5 | -------------------------------------------------------------------------------- /nix-tracker/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | using namespace std; 7 | 8 | static int progress_cb(const char *str, int len, void *data) { 9 | (void)data; 10 | printf("remote: %.*s", len, str); 11 | fflush(stdout); /* We don't have the \n to force the flush */ 12 | return 0; 13 | } 14 | static int update_cb(const char *refname, const git_oid *a, const git_oid *b, void *data) { 15 | char a_str[GIT_OID_HEXSZ+1], b_str[GIT_OID_HEXSZ+1]; 16 | (void)data; 17 | 18 | git_oid_fmt(b_str, b); 19 | b_str[GIT_OID_HEXSZ] = '\0'; 20 | 21 | if (git_oid_iszero(a)) { 22 | printf("[new] %.20s %s\n", b_str, refname); 23 | } else { 24 | git_oid_fmt(a_str, a); 25 | a_str[GIT_OID_HEXSZ] = '\0'; 26 | printf("[updated] %.10s..%.10s %s\n", a_str, b_str, refname); 27 | } 28 | 29 | return 0; 30 | } 31 | static int transfer_progress_cb(const git_transfer_progress *stats, void *payload) { 32 | if (stats->received_objects == stats->total_objects) { 33 | printf("Resolving deltas %d/%d\r",stats->indexed_deltas, stats->total_deltas); 34 | } else if (stats->total_objects > 0) { 35 | printf("Received %d/%d objects (%d) in %d bytes\r", stats->received_objects, stats->total_objects, stats->indexed_objects, stats->received_bytes); 36 | } 37 | return 0; 38 | } 39 | 40 | int remote_fetch(git_repository *repo, const char *alias) { 41 | int status = 0; 42 | git_remote *remote = 0; 43 | git_fetch_options fetch_opts = GIT_FETCH_OPTIONS_INIT; 44 | fetch_opts.callbacks.update_tips = &update_cb; 45 | fetch_opts.callbacks.sideband_progress = &progress_cb; 46 | fetch_opts.callbacks.transfer_progress = transfer_progress_cb; 47 | 48 | if (git_remote_lookup(&remote,repo,alias) < 0) { 49 | cout << "error resolving repo"; 50 | status = -1; 51 | goto done; 52 | } 53 | if (git_remote_fetch(remote,0,&fetch_opts,"fetch") < 0) { 54 | cout << "error doing fetch" << endl; 55 | status = -2; 56 | goto done; 57 | } 58 | done: 59 | git_remote_free(remote); 60 | return status; 61 | } 62 | int print_reference(git_repository *repo, const char *reference, const char *name) { 63 | git_oid oid; 64 | git_commit *commit = 0; 65 | if (git_reference_name_to_id(&oid,repo,reference) < 0) { 66 | cout << "fail 6" << endl; 67 | return -6; 68 | } 69 | char oid_hex[GIT_OID_HEXSZ+1] = {0}; 70 | git_oid_fmt(oid_hex,&oid); 71 | oid_hex[GIT_OID_HEXSZ] = '\0'; 72 | 73 | if (git_commit_lookup(&commit,repo,&oid) < 0) { 74 | cout << "fail 7" << endl; 75 | return -7; 76 | } 77 | git_time_t commit_time = git_commit_time(commit); 78 | char buf[512]; 79 | int size = strftime(buf,500,"%F %T",localtime(&commit_time)); 80 | buf[size] = 0; 81 | printf("%20s %s\t%s\n",name,oid_hex,buf); 82 | git_commit_free(commit); 83 | } 84 | 85 | int main(int argc, char **argv) { 86 | git_repository *repo = 0; 87 | 88 | git_libgit2_init(); 89 | // see setup.md for config info 90 | if (git_repository_open(&repo, "/home/clever/nixpkgs/") < 0) { 91 | cout << "unable to open repo"; 92 | return -1; 93 | } 94 | 95 | remote_fetch(repo, "origin"); 96 | remote_fetch(repo, "channels"); 97 | 98 | print_reference(repo, "refs/remotes/origin/master", "master"); 99 | print_reference(repo, "refs/remotes/channels/nixos-unstable-small", "nixos-unstable-small"); 100 | print_reference(repo, "refs/remotes/channels/nixpkgs-unstable", "pkgs-unstable"); 101 | print_reference(repo, "refs/remotes/channels/nixos-unstable", "nixos-unstable"); 102 | 103 | FILE *ver = fopen("/run/current-system/nixos-version","r"); 104 | char buf[512]; 105 | int size = fread(buf,1,500,ver); 106 | buf[size] = 0; 107 | fclose(ver); 108 | cout << buf; 109 | git_repository_free(repo); repo = 0; 110 | git_libgit2_shutdown(); 111 | } 112 | -------------------------------------------------------------------------------- /nix-tracker/others.md: -------------------------------------------------------------------------------- 1 | ``` 2 | 2017-05-01 13:50:58 < bachp> Is there an easy way to check if a NixOS update is available? I'm traing to write a small notification script that is running on my Machine and shows me a popup whenever a new version is available and nixos-rebuild switch would update the system. Kind of like the updata available indicator in other distributions. 3 | 2017-05-01 13:53:42 < clever> bachp: either check the revisions on https://github.com/NixOS/nixpkgs-channels or http://howoldis.herokuapp.com/ 4 | 2017-05-01 13:53:54 < goibhniu> hi bachp, I've been working on something similar, perhaps you can re-use some code: https://github.com/cillianderoiste/NixTrayWidget 5 | 2017-05-01 13:53:56 < clever> which reminds me, i started something that did that over git, where did i leave it, lol 6 | 2017-05-01 13:54:21 < gchristensen> In Which Everyone Has Solved This Problem Different Ways 7 | 2017-05-01 13:54:25 * goibhniu uses JSON from howoldis 8 | 2017-05-01 13:54:49 < clever> -rw-r--r-- 1 clever users 3.5K Feb 29 2016 main.cpp 9 | 2017-05-01 13:54:57 < clever> found it, year old, not even in git 10 | 2017-05-01 13:55:03 < gchristensen> an on feb 29 even 11 | 2017-05-01 13:55:27 < clever> [clever@amd-nixos:~/apps/nix-tracker]$ ./nix-tracker 12 | 2017-05-01 13:55:27 < clever> bash: ./nix-tracker: No such file or directory 13 | 2017-05-01 13:55:31 < clever> and the ld.so got GC'd 14 | 2017-05-01 13:55:51 < gchristensen> bachp: you might find nixos-version's --hash option useful :) 15 | ``` 16 | -------------------------------------------------------------------------------- /nix-tracker/setup.md: -------------------------------------------------------------------------------- 1 | the git repo opened in main must have the following remotes configured 2 | [clever@amd-nixos:~/apps/nixpkgs]$ git remote -v 3 | channels git@github.com:NixOS/nixpkgs-channels.git (fetch) 4 | channels git@github.com:NixOS/nixpkgs-channels.git (push) 5 | origin git@github.com:NixOS/nixpkgs.git (fetch) 6 | origin git@github.com:NixOS/nixpkgs.git (push) 7 | 8 | -------------------------------------------------------------------------------- /placeholder.nix: -------------------------------------------------------------------------------- 1 | with import {}; runCommand "name" {} "echo ${builtins.placeholder "out"} > $out" 2 | -------------------------------------------------------------------------------- /qemu/default.nix: -------------------------------------------------------------------------------- 1 | let 2 | pkgs = import {}; 3 | configuration = { ... }: 4 | { 5 | virtualisation.graphics = false; 6 | services.mingetty.autologinUser = "root"; 7 | }; 8 | eval = import { inherit configuration; }; 9 | in eval.vm 10 | -------------------------------------------------------------------------------- /scopedImport/float1.nix: -------------------------------------------------------------------------------- 1 | (0.1 * 0.2) * (0.4 * 0.8) 2 | -------------------------------------------------------------------------------- /scopedImport/float2.nix: -------------------------------------------------------------------------------- 1 | builtins.scopedImport { __mul = a: b: "boo!"; } ./float1.nix 2 | -------------------------------------------------------------------------------- /scopedImport/float3.nix: -------------------------------------------------------------------------------- 1 | builtins.scopedImport { __mul = a: b: builtins.seq a (a*b); } ./float1.nix 2 | -------------------------------------------------------------------------------- /self-reference/self-reference.nix: -------------------------------------------------------------------------------- 1 | with import {}; 2 | 3 | substituteAll { 4 | src = ./self-reference.txt; 5 | foo = hello; 6 | } 7 | -------------------------------------------------------------------------------- /self-reference/self-reference.txt: -------------------------------------------------------------------------------- 1 | a 2 | b 3 | c 4 | self-reference @out@ 5 | and if you wan hello-world, @foo@ 6 | -------------------------------------------------------------------------------- /zed/configuration.nix: -------------------------------------------------------------------------------- 1 | { pkgs, lib, config, ... }: 2 | 3 | let 4 | zfsUser = if config.boot.zfs.enableUnstable then pkgs.zfsUnstable else pkgs.zfs; 5 | newcfg = pkgs.runCommand "newcfg" {} '' 6 | cp -vir ${zfsUser}/etc/zfs/zed.d/ $out 7 | chmod +w $out/zed.rc 8 | cat >> $out/zed.rc <