Skip to content

Instantly share code, notes, and snippets.

@3noch
Last active November 4, 2016 12:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 3noch/c9e523b90d91c8984ba833dfc88d087c to your computer and use it in GitHub Desktop.
Save 3noch/c9e523b90d91c8984ba833dfc88d087c to your computer and use it in GitHub Desktop.
Nix expression to build scoped Twitter Bootstrap CSS
# This expression builds a copy of Twitter Bootstrap CSS but with every rule embedded inside a CSS selector of
# your choice. This makes it easy to embed a Bootstrap-themed component in a site that doesn't use Bootstrap.
#
# Usage
# * Install nix from https://nixos.org/nix/ (it's a fancy package manager that won't mess up your system)
# * Save this file to `scoped-bootstrap.nix`
# * With nix stuff on your PATH, run `nix-build scoped-bootstrap.nix`
# * The result will be in `./result/` (a symlink). Copy to desired location.
# * If you don't want to keep `nix`: `rm -rf /nix`
{ pkgs ? import <nixpkgs> {}
, bootstrapSelector ? ".bootstrap" # Default bootstrap selector to prefix bootstrap styles (change to your needs)
, ...
}:
let
src = pkgs.fetchFromGitHub {
owner = "twbs";
repo = "bootstrap";
rev = "v3.3.7";
sha256 = "0li7vdr4avz34b9xvwk7skbvnvzbx002cw5nfm7iwvi1wk8v5bri";
};
in
pkgs.runCommand
"bootstrap-scoped-3.3.7"
{
inherit src;
buildInputs = [ pkgs.lessc pkgs.minify ];
}
''
mkdir -p $out
cat > $out/scoped-bootstrap.less <<'LESS'
${bootstrapSelector} {
@import "less/bootstrap.less";
}
LESS
lessc --include-path="$src" $out/scoped-bootstrap.less > $out/scoped-bootstrap.css
cat $out/scoped-bootstrap.css | minify --type=css > $out/scoped-bootstrap.min.css
''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment