aboutsummaryrefslogtreecommitdiff
path: root/flake.nix
blob: 661763bc28621da529f9c69bb882dcf8ee885d86 (plain) (blame)
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
{
  description = "a makeshift CI solution";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
  };

  outputs = {
    self,
    nixpkgs,
  }: let
    system = "x86_64-linux";
    pkgs = import nixpkgs {inherit system;};
    msci = (pkgs.writeScriptBin
      "msci" (builtins.readFile ./msci)).overrideAttrs (old: {
      buildCommand = "${old.buildCommand}\n patchShebangs $out";
    });
  in {
    packages."${system}".msci = pkgs.symlinkJoin {
      name = "msci";
      paths = [msci pkgs.jq pkgs.git];
      buildInputs = [pkgs.makeWrapper];
      postBuild = "wrapProgram $out/bin/msci --prefix PATH : $out/bin";
    };
    nixosModules.default = {
      lib,
      config,
      ...
    }: let
      cfg = config.makeshiftci;
    in {
      options = with lib; {
        makeshiftci = mkOption {
          type = types.submodule {
            options = {
              enable = mkEnableOption "enable makeshiftci";
              dataDir = mkOption {
                type = types.str;
                default = "/var/lib/makeshiftci";
                description = "data directory of makeshiftci";
              };
              createUser = mkEnableOption "create a non-root user";
            };
          };
        };
      };
      config = lib.mkIf cfg.enable {
        environment = {
          sessionVariables.MSCI_HOME = cfg.dataDir;
          systemPackages = [
            pkgs.jq
            pkgs.git
            self.packages."${system}".msci
          ];
        };
        systemd.tmpfiles.settings."makeshiftci" = {
          "${cfg.dataDir}" = {
            d = {
              user =
                if cfg.createUser
                then "makeshiftci"
                else "root";
              group =
                if cfg.createUser
                then "makeshiftci"
                else "root";
              mode = "0750";
            };
          };
        };
        services.cron.enable = true;
        users = lib.mkIf cfg.createUser {
          users."makeshiftci" = {
            group = "makeshiftci";
            home = cfg.dataDir;
            useDefaultShell = true;
          };
        };
      };
    };
  };
}