summaryrefslogtreecommitdiff
path: root/nix-ontopof-docker2.example.nix
blob: a996c32e4087fe894f0b15a2745d06df54791911 (plain)
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157

{
  description = "Nix packages on top of docker pattern";

  inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";

  outputs = { self, nixpkgs }:
    let

      # System types to support.
      supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ];

      # Helper function to generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'.
      forAllSystems = nixpkgs.lib.genAttrs supportedSystems;

      # Nixpkgs instantiated for supported system types.
      nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; });

    in
    {

      # Requires dirty nixbld with access to docker daemon
      packages = forAllSystems (system:
        let
          pkgs = nixpkgsFor.${system};

          # from: https://github.com/nix-community/home-manager/blob/70824bb5c790b820b189f62f643f795b1d2ade2e/modules/programs/neovim.nix#L412
          neovimConfig = pkgs.neovimUtils.makeNeovimConfig {
            viAlias = true;
            vimAlias = true;
            withPython3 = false;
            withRuby = false;
            withNodeJs = false;
            extraPython3Packages = _: [];
            extraLuaPackages = _: [];

            plugins = with pkgs.vimPlugins; [
              # highlighting
              nvim-treesitter.withAllGrammars
              playground
              gruvbox-material
              kanagawa-nvim
              lsp_lines-nvim
              gitsigns-nvim
              vim-helm
              lualine-nvim

              # external
              oil-nvim
              vim-fugitive
              venn-nvim
              gv-vim
              zoxide-vim
              obsidian-nvim
              go-nvim

              # Coding
              fzf-lua
              nvim-lspconfig
              null-ls-nvim
              lsp_signature-nvim
              nvim-dap
              nvim-dap-ui
              nvim-nio
              nvim-dap-python
              luasnip
              vim-test
              nvim-lint
              vim-surround
              conform-nvim
              trouble-nvim
              vim-easy-align
              nvim-comment

              # cmp
              nvim-cmp
              cmp-cmdline
              cmp-nvim-lsp
              cmp-buffer
              cmp-path
              cmp_luasnip

              # conjure
              vim-racket
              nvim-parinfer
              hotpot-nvim
            ];
            customRC = "";
          };

          neovim-package = pkgs.wrapNeovimUnstable pkgs.neovim-unwrapped (neovimConfig
            // {
              wrapRc = false;
            });

          st-terminfo = with pkgs; stdenv.mkDerivation rec {
            pname = "st-terminfo";
            version = "0.9.2";

            src = fetchurl {
              url = "https://dl.suckless.org/st/st-${version}.tar.gz";
              hash = "sha256-ayFdT0crIdYjLzDyIRF6d34kvP7miVXd77dCZGf5SUs=";
            };

            nativeBuildInputs = [ ncurses ];

            outputs = [ "out" ];

            buildPhase = ''
            echo no build
            '';
            installPhase = ''
            export HOME=$(mktemp -d)
            mkdir -p "$out/share/terminfo"
            cat st.info | tic -x -o "$out/share/terminfo" -
            '';
          };

          nvim-container = pkgs.dockerTools.buildImage {
            name =  "nvim-container";
            tag = "latest";
            copyToRoot = pkgs.buildEnv {
              extraPrefix = "/usr";
              name = "neovim-nix-ide-usr";
              paths =  with pkgs; [
                neovim-package
                docker-client
                zoxide
                xclip
                k9s
                st-terminfo
              ];
            };
          };
# # TODO: this is just for me
# RUN curl -sSL https://raw.githubusercontent.com/Shourai/st/refs/heads/master/st.info | tic -x -
        in
        {
          nvim-container-install = pkgs.writeShellScriptBin "nvim-container-install" ''
            #!/bin/sh
            docker image load -i ${nvim-container}
            Dockerfile="/tmp/$(id -u)/nix-ontop-docker"
            mkdir -p "$(dirname "$Dockerfile")"
            cat <<DOCKERFILE >"$Dockerfile"
            FROM pionativedev.azurecr.io/pionative/pnsh-ide-support:latest
            COPY --from=nvim-container:latest /usr /usr
            DOCKERFILE
            docker build -f "$Dockerfile" -t pionativedev.azurecr.io/pionative/pnsh-nvim:latest -- .
          '';
        });

      # The default package for 'nix build'. This makes sense if the
      # flake provides only one package or there is a clear "main"
      # package.
      defaultPackage = forAllSystems (system: self.packages.${system}.neovim-container);
    };
}