~kaction/config

ref: 937f1dc71c050881291ae5251621b4395143987b config/flake.nix -rw-r--r-- 4.4 KiB
937f1dc7 — Dmitry Bogatov Merge branch 'feature/provision-gitconfig' into next 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# On supported architectures
# ~~~~~~~~~~~~~~~~~~~~~~~~~~
# Some code is written in amd64 assembler, so we hard-code arch. I do
# not have access to any non-amd64 device, even virtual one, so fine for
# me. Maybe I will regret it, who knows?
{
  description = "Personal flake of ~kaction";
  inputs.nixpkgs.url = "git+https://github.com/nixos/nixpkgs?tag=20.09";
  inputs.mk-passwd.url = "git+https://git.sr.ht/~kaction/mk-passwd?tag=0.1.1";
  inputs.nix-sys.url = "git+https://git.sr.ht/~kaction/nix-sys?rev=0a6caa99b8a47c99bdbccd96155e5ba85072009c";
  outputs = { self, nixpkgs, mk-passwd, nix-sys }:
    let
      system = "x86_64-linux"; # See note [On supported architectures]
      pkgs = import nixpkgs { inherit system; };

      # Set of packages provided by nixpkgs with all atrribute names
      # prefixed with "pristine-". Makes writing derivations that need
      # access to both new and pristine version of dependency (for raw
      # rewriting, for example) much more uniform.

      pristine = let
        inherit (pkgs.lib) nameValuePair mapAttrs';
        f = name: value: nameValuePair "pristine-${name}" value;
      in mapAttrs' f pkgs;
    in {
      # This incantaion creates something like overlay: new definitions
      # override values from nixpkgs and used to build dependencies.
      #
      # Unlike overlay (e.g import nixpkgs { overlays = [...]; }) it
      # allows caching of nixpkgs, significantly increasing speed of
      # builds. [https://todo.sr.ht/~kaction/config/1]
      #
      # Also, it allows simple access to pristine versions of packages
      # from nixpkgs.
      packages."${system}" = pkgs.lib.makeScope pkgs.newScope (self':
        let
          inherit (self') callPackage;
          call = f: callPackage f { };
          do-rebuild = packages: path: rec {
            name = builtins.baseNameOf path;
            value = callPackage path { "${name}" = packages."${name}"; };
          };

          # In order of increasing preference and decreasing upstream
          # support. Sigh.
          rebuildGlibc = do-rebuild pkgs;
          rebuildMusl = do-rebuild pkgs.pkgsMusl;
          rebuildStatic = do-rebuild pkgs.pkgsStatic;

          rebuilded = builtins.listToAttrs (map rebuildGlibc [
            ./universe/mpop
            ./universe/msmtp
            ./universe/newsboat
            ./universe/python3
            ./universe/surfraw
            ./universe/w3m
            ./universe/doas
            ./universe/mutt
            ./universe/hub
            ./universe/vim
          ]);

        in pkgs // pristine // rebuilded // { # nixfmt: sort
          inherit (pkgs.pkgsStatic) execline;
          inherit system;
          Documentation =
            callPackage ./universe/Documentation { inherit nixpkgs; };
          attach-shell = call ./universe/attach-shell;
          blurdate = callPackage ./universe/blurdate { };
          dbxcli = callPackage ./universe/dbxcli { };
          neovim = callPackage ./universe/neovim { };
          dvtm =
            import ./universe/dvtm { inherit (pkgs.pkgsStatic) dvtm-unstable; };
          fasm-arch = call ./universe/fasm-arch;
          firewall = call ./universe/firewall;

          git-recall = call ./universe/git-recall;
          git-merge-pr = call ./universe/git-merge-pr;

          mk-runscript = call ./universe/mk-runscript;

          nix = pkgs.nixFlakes;
          psql = pkgs.postgresql_10;
          rewrite-paths =
            { drv, rules ? [ ], buildInputs ? [ ], postBuild ? "" }:
            callPackage ./universe/rewrite-paths {
              inherit drv rules buildInputs postBuild;
            };
          srht-ui = call ./universe/srht-ui;
          selectors = call ./universe/selectors;
          scripts = call ./universe/scripts;

          passphrase2pgp = call ./universe/passphrase2pgp;
          posixrc = callPackage ./universe/posixrc { };
          mk-passwd = mk-passwd.defaultPackage.${system};
          manifest = callPackage ./manifest { };
          system-wide = nix-sys.defaultPackage.${system}.overrideAttrs (_: {
            inherit (self') manifest;
          });
          tempfile = pkgs.pkgsStatic.callPackage ./universe/tempfile { };
          vidir = callPackage ./universe/vidir { };
          uenv = call ./universe/uenv;
          universe = import ./universe { pkgs = self.packages."${system}"; };
        });

      defaultPackage."${system}" = self.packages."${system}".universe;
    };
}