Skip to content

Instantly share code, notes, and snippets.

@hazelweakly
Created February 13, 2023 19:49
Show Gist options
  • Save hazelweakly/ce7b27783e3284e7c07c1e0c834b39f3 to your computer and use it in GitHub Desktop.
Save hazelweakly/ce7b27783e3284e7c07c1e0c834b39f3 to your computer and use it in GitHub Desktop.
Nix Shenanigans
# Of all the reasons why I like nix, the ability and ergonomics in which I can do this
# are high on the list of compelling examples, in my opinion.
{
description = "nix shenanigans";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, rust-overlay, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
haskellBin = pkgs.writers.writeHaskellBin "bruh"
{ libraries = with pkgs.haskellPackages; [ conduit http-conduit bytestring ]; } ''
import Network.HTTP.Conduit
import qualified Data.ByteString.Lazy as L
main = simpleHttp "https://motherfuckingwebsite.com/" >>= L.putStr
'';
rustBin = pkgs.writers.writeRustBin "wowza"
{ } ''
fn main() {
let xs: [i32; 5] = [1, 2, 3, 4, 5];
println!("I can't use crates here. sadness.");
println!("first element of the array: {}", xs[0]);
}
'';
jsBin = pkgs.writers.writeJSBin "lmao"
{ libraries = [ pkgs.nodePackages.uglify-js ]; } ''
const UglifyJS = require("uglify-js");
const code = "function add(first, second) { return first + second; }";
console.log(UglifyJS.minify(code).code);
'';
justfile = pkgs.writeText "justfile" ''
[private]
default:
just --list
js:
lmao
rust:
wowza
haskell:
bruh
'';
justBin = pkgs.writers.writeBashBin "just" ''
exec ${pkgs.just}/bin/just --justfile=${justfile} "$@"
'';
in
with pkgs;
{
devShells.default = mkShell {
buildInputs = [ haskellBin rustBin jsBin justBin ];
shellHook = ''
just
'';
};
}
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment