···11-# Bower {#sec-bower}
22-33-[Bower](https://bower.io) is a package manager for web site front-end components. Bower packages (comprising of build artifacts and sometimes sources) are stored in `git` repositories, typically on Github. The package registry is run by the Bower team with package metadata coming from the `bower.json` file within each package.
44-55-The end result of running Bower is a `bower_components` directory which can be included in the web app's build process.
66-77-Bower can be run interactively, by installing `nodePackages.bower`. More interestingly, the Bower components can be declared in a Nix derivation, with the help of `bower2nix`.
88-99-## bower2nix usage {#ssec-bower2nix-usage}
1010-1111-Suppose you have a `bower.json` with the following contents:
1212-1313-### Example bower.json {#ex-bowerJson}
1414-1515-```json
1616- "name": "my-web-app",
1717- "dependencies": {
1818- "angular": "~1.5.0",
1919- "bootstrap": "~3.3.6"
2020- }
2121-```
2222-2323-Running `bower2nix` will produce something like the following output:
2424-2525-```nix
2626-{ fetchbower, buildEnv }:
2727-buildEnv {
2828- name = "bower-env";
2929- ignoreCollisions = true;
3030- paths = [
3131- (fetchbower "angular" "1.5.3" "~1.5.0" "1749xb0firxdra4rzadm4q9x90v6pzkbd7xmcyjk6qfza09ykk9y")
3232- (fetchbower "bootstrap" "3.3.6" "~3.3.6" "1vvqlpbfcy0k5pncfjaiskj3y6scwifxygfqnw393sjfxiviwmbv")
3333- (fetchbower "jquery" "2.2.2" "1.9.1 - 2" "10sp5h98sqwk90y4k6hbdviwqzvzwqf47r3r51pakch5ii2y7js1")
3434- ];
3535-}
3636-```
3737-3838-Using the `bower2nix` command line arguments, the output can be redirected to a file. A name like `bower-packages.nix` would be fine.
3939-4040-The resulting derivation is a union of all the downloaded Bower packages (and their dependencies). To use it, they still need to be linked together by Bower, which is where `buildBowerComponents` is useful.
4141-4242-## buildBowerComponents function {#ssec-build-bower-components}
4343-4444-The function is implemented in [pkgs/development/bower-modules/generic/default.nix](https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/bower-modules/generic/default.nix).
4545-4646-### Example buildBowerComponents {#ex-buildBowerComponents}
4747-4848-```nix
4949-{
5050- bowerComponents = buildBowerComponents {
5151- name = "my-web-app";
5252- generated = ./bower-packages.nix; # note 1
5353- src = myWebApp; # note 2
5454- };
5555-}
5656-```
5757-5858-In ["buildBowerComponents" example](#ex-buildBowerComponents) the following arguments are of special significance to the function:
5959-6060-1. `generated` specifies the file which was created by {command}`bower2nix`.
6161-2. `src` is your project's sources. It needs to contain a {file}`bower.json` file.
6262-6363-`buildBowerComponents` will run Bower to link together the output of `bower2nix`, resulting in a `bower_components` directory which can be used.
6464-6565-Here is an example of a web frontend build process using `gulp`. You might use `grunt`, or anything else.
6666-6767-### Example build script (gulpfile.js) {#ex-bowerGulpFile}
6868-6969-```javascript
7070-var gulp = require('gulp');
7171-7272-gulp.task('default', [], function () {
7373- gulp.start('build');
7474-});
7575-7676-gulp.task('build', [], function () {
7777- console.log("Just a dummy gulp build");
7878- gulp
7979- .src(["./bower_components/**/*"])
8080- .pipe(gulp.dest("./gulpdist/"));
8181-});
8282-```
8383-8484-### Example Full example — default.nix {#ex-buildBowerComponentsDefaultNix}
8585-8686-```nix
8787-{
8888- myWebApp ? {
8989- outPath = ./.;
9090- name = "myWebApp";
9191- },
9292- pkgs ? import <nixpkgs> { },
9393-}:
9494-9595-pkgs.stdenv.mkDerivation {
9696- name = "my-web-app-frontend";
9797- src = myWebApp;
9898-9999- buildInputs = [ pkgs.nodePackages.gulp ];
100100-101101- bowerComponents = pkgs.buildBowerComponents {
102102- # note 1
103103- name = "my-web-app";
104104- generated = ./bower-packages.nix;
105105- src = myWebApp;
106106- };
107107-108108- nativeBuildInputs = [
109109- writableTmpDirAsHomeHook # note 3
110110- ];
111111-112112- buildPhase = ''
113113- runHook preBuild
114114-115115- cp --reflink=auto --no-preserve=mode -R $bowerComponents/bower_components . # note 2
116116- ${pkgs.nodePackages.gulp}/bin/gulp build # note 4
117117-118118- runHook postBuild
119119- '';
120120-121121- installPhase = ''
122122- runHook preInstall
123123-124124- mv gulpdist $out
125125-126126- runHook postInstall
127127- '';
128128-}
129129-```
130130-131131-A few notes about [Full example — `default.nix`](#ex-buildBowerComponentsDefaultNix):
132132-133133-1. The result of `buildBowerComponents` is an input to the frontend build.
134134-2. Whether to symlink or copy the {file}`bower_components` directory depends on the build tool in use.
135135- In this case, a copy is used to avoid {command}`gulp` silliness with permissions.
136136-3. {command}`gulp` requires `HOME` to refer to a writeable directory.
137137-4. The actual build command in this example is {command}`gulp`. Other tools could be used instead.
138138-139139-## Troubleshooting {#ssec-bower2nix-troubleshooting}
140140-141141-### ENOCACHE errors from buildBowerComponents {#enocache-errors-from-buildbowercomponents}
142142-143143-This means that Bower was looking for a package version which doesn't exist in the generated `bower-packages.nix`.
144144-145145-If `bower.json` has been updated, then run `bower2nix` again.
146146-147147-It could also be a bug in `bower2nix` or `fetchbower`. If possible, try reformulating the version specification in `bower.json`.
···20202121- `mono4` and `mono5` have been removed. Use `mono6` or `mono` instead.
22222323+- Everything related to `bower` was removed, as it is deprecated and not used by anything in nixpkgs.
2424+2325- The `offrss` package was removed due to lack of upstream maintenance since 2012. It's recommended for users to migrate to another RSS reader
24262527- `installShellFiles`: Allow installManPage to take a piped input, add the `--name` flag for renaming the file when installed. Can also append `--` to opt-out of all subsequent parsing.
-41
pkgs/build-support/fetchbower/default.nix
···11-{
22- stdenvNoCC,
33- lib,
44- bower2nix,
55- cacert,
66-}:
77-let
88- bowerVersion =
99- version:
1010- let
1111- components = lib.splitString "#" version;
1212- hash = lib.last components;
1313- ver = if builtins.length components == 1 then (cleanName version) else hash;
1414- in
1515- ver;
1616-1717- cleanName = name: lib.replaceStrings [ "/" ":" ] [ "-" "-" ] name;
1818-1919- fetchbower =
2020- name: version: target: outputHash:
2121- stdenvNoCC.mkDerivation {
2222- name = "${cleanName name}-${bowerVersion version}";
2323- buildCommand = ''
2424- fetch-bower --quiet --out=$PWD/out "${name}" "${target}" "${version}"
2525- # In some cases, the result of fetchBower is different depending
2626- # on the output directory (e.g. if the bower package contains
2727- # symlinks). So use a local output directory before copying to
2828- # $out.
2929- cp -R out $out
3030- '';
3131- outputHashMode = "recursive";
3232- outputHashAlgo = "sha256";
3333- inherit outputHash;
3434- nativeBuildInputs = [
3535- bower2nix
3636- cacert
3737- ];
3838- };
3939-4040-in
4141-fetchbower
···538538 boost184 = throw "Boost 1.84 has been removed as it is obsolete and no longer used by anything in Nixpkgs"; # Added 2024-11-24
539539 boost185 = throw "Boost 1.85 has been removed as it is obsolete and no longer used by anything in Nixpkgs"; # Added 2024-11-24
540540 boost_process = throw "boost_process has been removed as it is included in regular boost"; # Added 2024-05-01
541541+ bower2nix = throw "bower2nix has been removed as bower was removed. It is recommended to migrate to yarn."; # Added 2025-09-17
541542 bpb = throw "bpb has been removed as it is unmaintained and not compatible with recent Rust versions"; # Added 2024-04-30
542543 bpftool = throw "'bpftool' has been renamed to/replaced by 'bpftools'"; # Converted to throw 2024-10-17
543544 brasero-original = lib.warnOnInstantiate "Use 'brasero-unwrapped' instead of 'brasero-original'" brasero-unwrapped; # Added 2024-09-29
···549550 budgie = throw "The `budgie` scope has been removed and all packages moved to the top-level"; # Added 2024-07-14
550551 budgiePlugins = throw "The `budgiePlugins` scope has been removed and all packages moved to the top-level"; # Added 2024-07-14
551552 buildBarebox = throw "buildBarebox has been removed due to lack of interest in maintaining it in nixpkgs"; # Added 2025-04-19
553553+ buildBowerComponents = throw "buildBowerComponents has been removed as bower was removed. It is recommended to migrate to yarn."; # Added 2025-09-17
552554 buildGo122Module = throw "Go 1.22 is end-of-life, and 'buildGo122Module' has been removed. Please use a newer builder version."; # Added 2025-03-28
553555 buildGo123Module = throw "Go 1.23 is end-of-life, and 'buildGo123Module' has been removed. Please use a newer builder version."; # Added 2025-08-13
554556 buildGoPackage = throw "`buildGoPackage` has been deprecated and removed, see the Go section in the nixpkgs manual for details"; # Added 2024-11-18
···886888 fdr = throw "fdr has been removed, as it cannot be built from source and depends on Python 2.x"; # Added 2025-03-19
887889 inherit (luaPackages) fennel; # Added 2022-09-24
888890 ferdi = throw "'ferdi' has been removed, upstream does not exist anymore and the package is insecure"; # Added 2024-08-22
891891+ fetchbower = throw "fetchbower has been removed as bower was removed. It is recommended to migrate to yarn."; # Added 2025-09-17
889892 fetchFromGithub = throw "You meant fetchFromGitHub, with a capital H"; # preserve, reason: common typo
890893 ffmpeg_5 = throw "ffmpeg_5 has been removed, please use another version"; # Added 2024-07-12
891894 ffmpeg_5-headless = throw "ffmpeg_5-headless has been removed, please use another version"; # Added 2024-07-12