diff options
| -rw-r--r-- | ci.nix | 46 | ||||
| -rw-r--r-- | default.nix | 4 | ||||
| -rw-r--r-- | flake.lock | 23 | ||||
| -rw-r--r-- | flake.nix | 39 | ||||
| -rw-r--r-- | lib/default.nix | 3 | ||||
| -rw-r--r-- | overlay.nix | 14 | ||||
| -rw-r--r-- | pkgs/hgrep/default.nix | 2 | ||||
| -rw-r--r-- | pkgs/reparojson/default.nix | 2 | ||||
| -rw-r--r-- | treefmt.nix | 5 |
9 files changed, 105 insertions, 33 deletions
@@ -9,29 +9,42 @@ # then your CI will be able to build and cache only those packages for # which this is possible. -{ pkgs ? import <nixpkgs> { } }: +{ + pkgs ? import <nixpkgs> { }, +}: with builtins; let isReserved = n: n == "lib" || n == "overlays" || n == "modules"; isDerivation = p: isAttrs p && p ? type && p.type == "derivation"; - isBuildable = p: let - licenseFromMeta = p.meta.license or []; - licenseList = if builtins.isList licenseFromMeta then licenseFromMeta else [licenseFromMeta]; - in !(p.meta.broken or false) && builtins.all (license: license.free or true) licenseList; + isBuildable = + p: + let + licenseFromMeta = p.meta.license or [ ]; + licenseList = if builtins.isList licenseFromMeta then licenseFromMeta else [ licenseFromMeta ]; + in + !(p.meta.broken or false) && builtins.all (license: license.free or true) licenseList; isCacheable = p: !(p.preferLocalBuild or false); shouldRecurseForDerivations = p: isAttrs p && p.recurseForDerivations or false; - nameValuePair = n: v: { name = n; value = v; }; + nameValuePair = n: v: { + name = n; + value = v; + }; concatMap = builtins.concatMap or (f: xs: concatLists (map f xs)); - flattenPkgs = s: + flattenPkgs = + s: let - f = p: - if shouldRecurseForDerivations p then flattenPkgs p - else if isDerivation p then [ p ] - else [ ]; + f = + p: + if shouldRecurseForDerivations p then + flattenPkgs p + else if isDerivation p then + [ p ] + else + [ ]; in concatMap f (attrValues s); @@ -39,12 +52,11 @@ let nurAttrs = import ./default.nix { inherit pkgs; }; - nurPkgs = - flattenPkgs - (listToAttrs - (map (n: nameValuePair n nurAttrs.${n}) - (filter (n: !isReserved n) - (attrNames nurAttrs)))); + nurPkgs = flattenPkgs ( + listToAttrs ( + map (n: nameValuePair n nurAttrs.${n}) (filter (n: !isReserved n) (attrNames nurAttrs)) + ) + ); in rec { diff --git a/default.nix b/default.nix index 9c05a71..427e936 100644 --- a/default.nix +++ b/default.nix @@ -6,7 +6,9 @@ # commands such as: # nix-build -A mypackage -{ pkgs ? import <nixpkgs> { } }: +{ + pkgs ? import <nixpkgs> { }, +}: { # The `lib`, `modules`, and `overlays` names are special @@ -18,7 +18,28 @@ }, "root": { "inputs": { - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs", + "treefmt-nix": "treefmt-nix" + } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1744961264, + "narHash": "sha256-aRmUh0AMwcbdjJHnytg1e5h5ECcaWtIFQa6d9gI85AI=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "8d404a69efe76146368885110f29a2ca3700bee6", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" } } }, @@ -1,14 +1,41 @@ { description = "My personal NUR repository"; - inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; - outputs = { self, nixpkgs }: + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + + treefmt-nix = { + url = "github:numtide/treefmt-nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = + { + self, + nixpkgs, + treefmt-nix, + }: let forAllSystems = nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed; in { - legacyPackages = forAllSystems (system: import ./default.nix { - pkgs = import nixpkgs { inherit system; }; - }); - packages = forAllSystems (system: nixpkgs.lib.filterAttrs (_: v: nixpkgs.lib.isDerivation v) self.legacyPackages.${system}); + formatter = forAllSystems ( + system: + let + pkgs = import nixpkgs { inherit system; }; + treefmt = treefmt-nix.lib.evalModule pkgs ./treefmt.nix; + in + treefmt.config.build.wrapper + ); + legacyPackages = forAllSystems ( + system: + import ./default.nix { + pkgs = import nixpkgs { inherit system; }; + } + ); + packages = forAllSystems ( + system: nixpkgs.lib.filterAttrs (_: v: nixpkgs.lib.isDerivation v) self.legacyPackages.${system} + ); }; } diff --git a/lib/default.nix b/lib/default.nix index a7fab1d..1d25545 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -1,6 +1,7 @@ { pkgs }: -with pkgs.lib; { +with pkgs.lib; +{ # Add your library functions here # # hexint = x: hexvals.${toLower x}; diff --git a/overlay.nix b/overlay.nix index bff7396..4272d50 100644 --- a/overlay.nix +++ b/overlay.nix @@ -5,11 +5,15 @@ self: super: let isReserved = n: n == "lib" || n == "overlays" || n == "modules"; - nameValuePair = n: v: { name = n; value = v; }; + nameValuePair = n: v: { + name = n; + value = v; + }; nurAttrs = import ./default.nix { pkgs = super; }; in -builtins.listToAttrs - (map (n: nameValuePair n nurAttrs.${n}) - (builtins.filter (n: !isReserved n) - (builtins.attrNames nurAttrs))) +builtins.listToAttrs ( + map (n: nameValuePair n nurAttrs.${n}) ( + builtins.filter (n: !isReserved n) (builtins.attrNames nurAttrs) + ) +) diff --git a/pkgs/hgrep/default.nix b/pkgs/hgrep/default.nix index 9db9780..2027e1d 100644 --- a/pkgs/hgrep/default.nix +++ b/pkgs/hgrep/default.nix @@ -50,7 +50,7 @@ rustPlatform.buildRustPackage rec { description = "hgrep is a grep tool with human-friendly search output. This is similar to `-C` option of `grep` command, but its output is enhanced with syntax highlighting focusing on human readable outputs."; homepage = "https://github.com/rhysd/hgrep"; changelog = "https://github.com/rhysd/hgrep/raw/v${version}/CHANGELOG.md"; - license = [lib.licenses.mit]; + license = [ lib.licenses.mit ]; mainProgram = "hgrep"; }; } diff --git a/pkgs/reparojson/default.nix b/pkgs/reparojson/default.nix index ae8ab6e..fd79c79 100644 --- a/pkgs/reparojson/default.nix +++ b/pkgs/reparojson/default.nix @@ -19,7 +19,7 @@ rustPlatform.buildRustPackage rec { meta = { description = "A simple command-line tool to repair JSON. It only fixes the syntactic errors and never formats the given input."; homepage = "https://github.com/nsfisis/reparojson"; - license = [lib.licenses.mit]; + license = [ lib.licenses.mit ]; mainProgram = "reparojson"; }; } diff --git a/treefmt.nix b/treefmt.nix new file mode 100644 index 0000000..972a362 --- /dev/null +++ b/treefmt.nix @@ -0,0 +1,5 @@ +{ pkgs, ... }: +{ + projectRootFile = "flake.nix"; + programs.nixfmt.enable = true; +} |
